Package com.dotmarketing.beans

Examples of com.dotmarketing.beans.Host


            prePath = "/webdav/autopub/";
        } else {
            prePath = "/webdav/nonpub/";
        }

        Host folderHost;
        try {
            folderHost = hostAPI.find( parentFolder.getHostId(), user, false );
        } catch ( DotDataException e ) {
            Logger.error( DotWebdavHelper.class, e.getMessage(), e );
            throw new IOException( e.getMessage() );
        } catch ( DotSecurityException e ) {
            Logger.error( DotWebdavHelper.class, e.getMessage(), e );
            throw new IOException( e.getMessage() );
        }

        List<Resource> result = new ArrayList<Resource>();
        try {

            //Search for child folders
            List<Folder> folderListSubChildren = folderAPI.findSubFolders( parentFolder, user, false );
            //Search for child files
            List<Versionable> filesListSubChildren = new ArrayList<Versionable>();
            try {
                filesListSubChildren.addAll( folderAPI.getWorkingFiles( parentFolder, user, false ) );
                filesListSubChildren.addAll( APILocator.getFileAssetAPI().findFileAssetsByFolder( parentFolder, user, false ) );
            } catch ( Exception e2 ) {
                Logger.error( this, "Could not load files : ", e2 );
            }

            for ( Versionable file : filesListSubChildren ) {
                if ( !file.isArchived() ) {
                    IFileAsset fileAsset = (IFileAsset) file;
                    FileResourceImpl resource = new FileResourceImpl( fileAsset, prePath + folderHost.getHostname() + "/" + fileAsset.getPath() );
                    result.add( resource );
                }
            }
            for ( Folder folder : folderListSubChildren ) {
                if ( !folder.isArchived() ) {
                    String path = idapi.find( folder ).getPath();

                    FolderResourceImpl resource = new FolderResourceImpl( folder, prePath + folderHost.getHostname() + "/" + (path.startsWith( "/" ) ? path.substring( 1 ) : path) );
                    result.add( resource );
                }
            }

            String p = APILocator.getIdentifierAPI().find( parentFolder ).getPath();
            if ( p.contains( "/" ) )
                p.replace( "/", java.io.File.separator );
            java.io.File tempDir = new java.io.File( tempHolderDir.getPath() + java.io.File.separator + folderHost.getHostname() + p );
            p = idapi.find( parentFolder ).getPath();
            if ( !p.endsWith( "/" ) )
                p = p + "/";
            if ( !p.startsWith( "/" ) )
                p = "/" + p;
            if ( tempDir.exists() && tempDir.isDirectory() ) {
                java.io.File[] files = tempDir.listFiles();
                for ( java.io.File file : files ) {
                    String tp = prePath + folderHost.getHostname() + p + file.getName();
                    if ( !isTempResource( tp ) ) {
                        continue;
                    }
                    if ( file.isDirectory() ) {
                        TempFolderResourceImpl tr = new TempFolderResourceImpl( tp, file, isAutoPub );
View Full Code Here


      // ### Copy the permission ###
      // Source
      String sourceHostName = getHostname(sourcePath);
      String sourceFolderName = getPath(sourcePath);
      // String sourceFolderName = DotCMSStorage.getFolderName(sourcePath);
      Host sourceHost;

      sourceHost = hostAPI.findByName(sourceHostName, user, false);



      Folder sourceFolder = folderAPI.findFolderByPath(sourceFolderName + "/", sourceHost,user,false);
      // Destination
      String destinationHostName = getHostname(destinationPath);
      String destinationFolderName = getPath(destinationPath);
      // String destinationFolderName =
      // DotCMSStorage.getFolderName(destinationPath);
      Host destinationHost;

      destinationHost = hostAPI.findByName(destinationHostName, user, false);


      Folder destinationFolder = folderAPI.findFolderByPath(destinationFolderName + "/", destinationHost,user,false);
View Full Code Here

      fileName = deleteSpecialCharacter(fileName);
      if(fileName.startsWith(".")){
        return;
      }

      Host host;

      host = hostAPI.findByName(hostName, user, false);

      Folder folder = folderAPI.findFolderByPath(folderName, host,user,false);
      boolean hasPermission = false;

      hasPermission = (!folderName.equals("/") && perAPI.doesUserHavePermission(folder, PERMISSION_CAN_ADD_CHILDREN, user, false))
                      || (folderName.equals("/") && perAPI.doesUserHavePermission(host, PERMISSION_CAN_ADD_CHILDREN, user, false));

      if (hasPermission) {
        // Check the folder filters
        if (!checkFolderFilter(folder, fileName)) {
          throw new IOException("The file doesn't comply the folder's filter");
        }

        if (host != null && InodeUtils.isSet(host.getInode())&& InodeUtils.isSet(folder.getInode())) {

          Identifier identifier = APILocator.getIdentifierAPI().find(host,path);

          File file = new File();
          file.setTitle(fileName);
View Full Code Here

    String path = getPath(resourceUri);
    String folderName = getFolderName(path);
    String fileName = getFileName(path);
    fileName = deleteSpecialCharacter(fileName);

    Host host;
    try {
      host = hostAPI.findByName(hostName, user, false);
    } catch (DotDataException e) {
      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    } catch (DotSecurityException e) {
      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    }

    Folder folder = new Folder();
    try {
      folder = folderAPI.findFolderByPath(folderName, host,user,false);
    } catch (Exception e2) {
      Logger.error(this, e2.getMessage(), e2);
    }
    if (host != null && InodeUtils.isSet(host.getInode()) && InodeUtils.isSet(folder.getInode())) {
      IFileAsset destinationFile = null;
      java.io.File workingFile = null;
      Folder parent = null;
      Contentlet fileAssetCont = null;
      Identifier identifier  = APILocator.getIdentifierAPI().find(host, path);
      if(identifier!=null && InodeUtils.isSet(identifier.getId()) && identifier.getAssetType().equals("contentlet")){
        fileAssetCont = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
        workingFile = fileAssetCont.getBinary(FileAssetAPI.BINARY_FIELD);
        destinationFile = APILocator.getFileAssetAPI().fromContentlet(fileAssetCont);
        parent = APILocator.getFolderAPI().findFolderByPath(identifier.getParentPath(), host, user, false);

        if(fileAssetCont.isArchived()) {
            APILocator.getContentletAPI().unarchive(fileAssetCont, user, false);
        }
      }else if(identifier!=null && InodeUtils.isSet(identifier.getId())){
        destinationFile = fileAPI.getFileByURI(path, host, false, user, false);
        // inode{1}/inode{2}/inode.file_extension
        workingFile = fileAPI.getAssetIOFile((File)destinationFile);

        if(destinationFile.isArchived()) {
            WebAssetFactory.unArchiveAsset((File)destinationFile);
        }
      }

      //http://jira.dotmarketing.net/browse/DOTCMS-1873
      //To clear velocity cache
      if(workingFile!=null){
        DotResourceCache vc = CacheLocator.getVeloctyResourceCache();
        vc.remove(ResourceManager.RESOURCE_TEMPLATE + workingFile.getPath());
      }

      InputStream is = content;
      byte[] currentData = IOUtils.toByteArray(is);

      if(destinationFile==null){
        Contentlet fileAsset = new Contentlet();
        Structure faStructure = StructureCache.getStructureByInode(folder.getDefaultFileType());
        Field fieldVar = faStructure.getFieldVar(FileAssetAPI.BINARY_FIELD);
        fileAsset.setStructureInode(folder.getDefaultFileType());
        fileAsset.setFolder(folder.getInode());
        if (currentData != null) {
          java.io.File tempUserFolder = new java.io.File(APILocator.getFileAPI().getRealAssetPathTmpBinary() + java.io.File.separator + user.getUserId() +
              java.io.File.separator + fieldVar.getFieldContentlet());
          if (!tempUserFolder.exists())
            tempUserFolder.mkdirs();

          java.io.File fileData = new java.io.File(tempUserFolder.getAbsolutePath() + java.io.File.separator + fileName);
          if(fileData.exists())
            fileData.delete();
          // Saving the new working data
          FileChannel writeCurrentChannel = new FileOutputStream(fileData).getChannel();
          writeCurrentChannel.truncate(0);
          ByteBuffer buffer = ByteBuffer.allocate(currentData.length);
          buffer.put(currentData);
          buffer.position(0);
          writeCurrentChannel.write(buffer);
          writeCurrentChannel.force(false);
          writeCurrentChannel.close();
          fileAsset.setStringProperty(FileAssetAPI.TITLE_FIELD, fileName);
          fileAsset.setStringProperty(FileAssetAPI.FILE_NAME_FIELD, fileName);
          fileAsset.setBinary(FileAssetAPI.BINARY_FIELD, fileData);
          fileAsset.setHost(host.getIdentifier());
          fileAsset=APILocator.getContentletAPI().checkin(fileAsset, user, false);

          //Validate if the user have the right permission before
          if(isAutoPub && !perAPI.doesUserHavePermission(fileAsset, PermissionAPI.PERMISSION_PUBLISH, user) ){
            APILocator.getContentletAPI().archive(fileAsset, APILocator.getUserAPI().getSystemUser(), false);
View Full Code Here

    PermissionAPI perAPI = APILocator.getPermissionAPI();
    Logger.debug(this.getClass(), "createFolder");
    String hostName = getHostname(folderUri);
    String path = getPath(folderUri);

    Host host;
    try {
      host = hostAPI.findByName(hostName, user, false);
    } catch (DotDataException e) {
      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    } catch (DotSecurityException e) {
      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    }

    // CheckPermission
    List<Permission> parentPermissions = new ArrayList<Permission>();
    boolean hasPermission = false;
    boolean validName = true;
    String parentPath = getFolderName(path);
    if (UtilMethods.isSet(parentPath) && !parentPath.equals("/")) {
      Folder parentFolder;
      try {
        parentFolder = folderAPI.findFolderByPath(parentPath,host,user,false);
        hasPermission = perAPI.doesUserHavePermission(parentFolder,  PERMISSION_CAN_ADD_CHILDREN, user, false);
      } catch (Exception e) {
        Logger.error(DotWebdavHelper.class,e.getMessage(),e);
        throw new IOException(e.getMessage());
      }
    } else {
      if (host != null && InodeUtils.isSet(host.getInode())) {
        java.util.List<String> reservedFolderNames = new java.util.ArrayList<String>();
        String[] reservedFolderNamesArray = Config.getStringArrayProperty("RESERVEDFOLDERNAMES");
        for (String name : reservedFolderNamesArray) {
          reservedFolderNames.add(name.toUpperCase());
        }
        validName = (!(reservedFolderNames.contains(path.substring(1).toUpperCase())));
      }
      try {
        hasPermission = perAPI.doesUserHavePermission(host, PERMISSION_CAN_ADD_CHILDREN, user, false);
      } catch (DotDataException e) {
        Logger.error(DotWebdavHelper.class,e.getMessage(),e);
        throw new IOException(e.getMessage());
      }
    }

    // Create the new folders with it parent permissions
    if ((hasPermission) && (validName)) {
      if (InodeUtils.isSet(host.getInode())) {
        path = deleteSpecialCharacter(path);
        try {
          folder = folderAPI.createFolders(path, host,user,false);
        } catch (Exception e) {
          throw new DotDataException(e.getMessage(), e);
View Full Code Here

    PermissionAPI perAPI = APILocator.getPermissionAPI();

    String hostName = getHostname(fromPath);
    String toParentPath = getFolderName(getPath(toPath));

    Host host;
    Folder toParentFolder;
    try {
      host = hostAPI.findByName(hostName, user, false);
        toParentFolder = folderAPI.findFolderByPath(toParentPath,host,user,false);
    } catch (DotDataException e) {
View Full Code Here

    uri = stripMapping(uri);
    Logger.debug(this.getClass(), "In the removeObject Method");
    String hostName = getHostname(uri);
    String path = getPath(uri);
    String folderName = getFolderName(path);
    Host host;
    WebAsset webAsset=null;
    try {
      host = hostAPI.findByName(hostName, user, false);
    } catch (DotDataException e) {
      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
View Full Code Here

          returnValue.add(s);
        }
      } else {
        // ### GET THE FOLDERS AT THE FIRST LEVEL ###
        String hostName = getHostname(folderUriAux);
        Host host;
        try {
          host = hostAPI.findByName(hostName, user, false);
        } catch (DotDataException e) {
          Logger.error(DotWebdavHelper.class, e.getMessage(), e);
          throw new IOException(e.getMessage());
        } catch (DotSecurityException e) {
          Logger.error(DotWebdavHelper.class, e.getMessage(), e);
          throw new IOException(e.getMessage());
        }
        String path = getPath(folderUriAux);
        if (path.equals("") || path.equals("/")) {
          List<Folder> folders = folderAPI.findSubFolders(host,user,false);
          for (Folder folderAux : folders) {
            if (perAPI.doesUserHavePermission(folderAux, PERMISSION_READ, user, false)) {
              Summary s = new Summary();
              s.setName(folderAux.getName());
              s.setPath("/" + host.getHostname()
                  + idapi.find(folderAux).getPath());
              s.setPath(s.getPath().substring(0,
                  s.getPath().length() - 1));
              s.setFolder(true);
              s.setCreateDate(folderAux.getIDate());
              s.setCreateDate(folderAux.getModDate());
              s.setHost(host);
              returnValue.add(s);
            }
          }
        } else {
          // ### GET THE FOLDERS, HTMLPAHES AND FILES AT SECOND LEVEL
          // AND LOWERS ###
          path += "/";
          Folder folder = folderAPI.findFolderByPath(path, host, user, false);
          if (InodeUtils.isSet(folder.getInode())) {
            List<Folder> folders = new ArrayList<Folder>();
            // List<HTMLPage> pages = new ArrayList<HTMLPage>();
            List<Versionable> files = new ArrayList<Versionable>();
            // List<Link> links = new ArrayList<Link>();

            try {
              folders = (ArrayList<Folder>)APILocator.getFolderAPI().findSubFolders(folder, user, false);
              // pages = (ArrayList<HTMLPage>)
              // InodeFactory.getChildrenClassByCondition(folder,HTMLPage.class,
              // conditionAsset);
              files.addAll(folderAPI.getWorkingFiles(folder, user,false));
              if(folder.getInode().equals(FolderAPI.SYSTEM_FOLDER)){
                files.addAll(APILocator.getFileAssetAPI().findFileAssetsByHost(APILocator.getHostAPI().find(folder.getHostId(), user,false), user,false));
              }else{
                files.addAll(APILocator.getFileAssetAPI().findFileAssetsByFolder(folder, user,false));
              }
              // links = (ArrayList<Link>)
              // InodeFactory.getChildrenClassByCondition(folder,Link.class,
              // conditionAsset);
            } catch (Exception ex) {
              String message = ex.getMessage();
              Logger.debug(this, ex.toString());
            }

            for (Folder folderAux : folders) {
              if (perAPI.doesUserHavePermission(folderAux,
                  PERMISSION_READ, user, false)) {
                Summary s = new Summary();
                s.setFolder(true);
                s.setCreateDate(folderAux.getiDate());
                s.setModifyDate(folderAux.getModDate());
                s.setName(folderAux.getName());
                s.setPath("/" + host.getHostname()
                    + idapi.find(folderAux).getPath());
                s.setPath(s.getPath().substring(0,
                    s.getPath().length() - 1));
                s.setHost(host);
                returnValue.add(s);
View Full Code Here

    Logger.debug(this.getClass(), "getResourceContent");
    InputStream returnValue = null;
    String hostName = getHostname(resourceUri);
    String path = getPath(resourceUri);
    String folderName = getFolderName(path);
    Host host;
    Folder folder;
    try {
      host = hostAPI.findByName(hostName, user, false);
      folder = folderAPI.findFolderByPath(folderName, host,user,false);
    } catch (DotDataException e) {
      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    } catch (DotSecurityException e) {
      Logger.error(DotWebdavHelper.class, e.getMessage(), e);
      throw new IOException(e.getMessage());
    }
    if (host != null && InodeUtils.isSet(host.getInode()) && InodeUtils.isSet(folder.getInode())) {
      java.io.File workingFile  = null;
      Identifier identifier  = APILocator.getIdentifierAPI().find(host, path);
      if(identifier!=null && identifier.getAssetType().equals("contentlet")){
                Contentlet cont  = APILocator.getContentletAPI().findContentletByIdentifier(identifier.getId(), false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, false);
          workingFile = cont.getBinary(FileAssetAPI.BINARY_FIELD);
View Full Code Here

  @Override
  public Template copy(Template sourceTemplate, User user) throws DotDataException, DotSecurityException {

    Identifier id = APILocator.getIdentifierAPI().find(sourceTemplate.getIdentifier());

    Host  h = APILocator.getHostAPI().find(id.getHostId(), user, false);



    return copy(sourceTemplate, h, false, false, user, false);
View Full Code Here

TOP

Related Classes of com.dotmarketing.beans.Host

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.