Package com.dotmarketing.portlets.files.model

Examples of com.dotmarketing.portlets.files.model.File


        //Find file identifier
        Identifier identifier = com.dotmarketing.business.APILocator.getIdentifierAPI().find( file );

        // gets working container
        File workingWebAsset = (File) APILocator.getVersionableAPI().findWorkingVersion( identifier, APILocator.getUserAPI().getSystemUser(), false );
        // gets live container
        File liveWebAsset = (File) APILocator.getVersionableAPI().findLiveVersion( identifier, APILocator.getUserAPI().getSystemUser(), false );

        // checks if another identifer with the same name exists in the same
        Boolean fileNameExists;
        if ( parent != null ) {
            fileNameExists = fileNameExists( parent, file.getFileName() );
        } else {
            fileNameExists = fileNameExists( APILocator.getFolderAPI().findSystemFolder(), file.getFileName() );
        }
        if ( fileNameExists ) {
            return false;
        }

        // assets cache
        if ( (liveWebAsset != null) && (InodeUtils.isSet( liveWebAsset.getInode() )) ) {
            LiveCache.removeAssetFromCache( liveWebAsset );
        }
        WorkingCache.removeAssetFromCache( workingWebAsset );

        // gets old parent
        Folder oldParent = APILocator.getFolderAPI().findParentFolder( workingWebAsset, APILocator.getUserAPI().getSystemUser(), false );

        /*oldParent.deleteChild(workingWebAsset);
          if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
              oldParent.deleteChild(liveWebAsset);
          }
          //add new Parent
          parent.addChild(workingWebAsset);
          if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
              parent.addChild(liveWebAsset);
          }*/

        // gets identifier for this webasset and changes the uri and persists it
        User systemUser;
        try {
            systemUser = APILocator.getUserAPI().getSystemUser();
            if ( host == null ) {
                host = hostAPI.findParentHost( parent, systemUser, false );
            }
        } catch ( DotDataException e ) {
            Logger.error( FileFactory.class, e.getMessage(), e );
            throw new DotRuntimeException( e.getMessage(), e );

        } catch ( DotSecurityException e ) {
            Logger.error( FileFactory.class, e.getMessage(), e );
            throw new DotRuntimeException( e.getMessage(), e );
        }
        identifier.setHostId( host.getIdentifier() );
        identifier.setURI( parent != null ? workingWebAsset.getURI( parent ) : workingWebAsset.getURI() );
        //HibernateUtil.saveOrUpdate(identifier);
        APILocator.getIdentifierAPI().save( identifier );

        if ( UtilMethods.isSet( liveWebAsset ) )
            CacheLocator.getIdentifierCache().removeFromCacheByVersionable( liveWebAsset );
//    IdentifierCache.addAssetToIdentifierCache(liveWebAsset);

        // Add to Preview and Live Cache
        if ( (liveWebAsset != null) && (InodeUtils.isSet( liveWebAsset.getInode() )) ) {
            LiveCache.removeAssetFromCache( liveWebAsset );
            LiveCache.addToLiveAssetToCache( liveWebAsset );
        }
        WorkingCache.removeAssetFromCache( workingWebAsset );
        WorkingCache.addToWorkingAssetToCache( workingWebAsset );
View Full Code Here


  }
 
  @Override
  protected File get(String inode) {
    inode = primaryGroup + inode;
      File file = null;
      try{
        file = (File)cache.get(inode,primaryGroup);
      }catch (DotCacheException e) {
      Logger.debug(this, "Cache Entry not found", e);
    }
View Full Code Here

      // check if it's a contentlet
      if(pfa.isContentlet()){
        Contentlet aContentlet = APILocator.getContentletAPI().find(pfa.getInode(), APILocator.getUserAPI().getSystemUser(), false);
        result.add(aContentlet);
      }else{ //a File
        File aFile = APILocator.getFileAPI().find(pfa.getInode(), APILocator.getUserAPI().getSystemUser(), false);
        result.add(aFile);
      }
    }
    return result;
  }
View Full Code Here

        previewAsset.delete();
      result.setContentlet(true);
      result.setInode(c.getInode());
      result.setParent(c.getFolder());
    }else if(asset instanceof File){ // is a File
      File f = (File)asset;
      assetFile =  APILocator.getFileAPI().getAssetIOFile(f);
      previewAsset = new java.io.File(importedFilesAssetDir, assetFile.getName());
      if(previewAsset.exists())
        previewAsset.delete();
      result.setContentlet(false);
      result.setInode(f.getInode());
      result.setParent(f.getParent());
    }
    //set the real path for the body preview
    result.setRealFileSystemPath(previewAsset.getPath().substring(previewAsset.getPath().indexOf("/_preview")));
    FileInputStream fis = new FileInputStream(assetFile);
    FileOutputStream fos = new FileOutputStream(previewAsset);
View Full Code Here

    if (publishInode == null) return;
   
    ActionRequestImpl reqImpl = (ActionRequestImpl)req;
   
    for (int i=0;i<publishInode.length;i++) {
      File file = (File) InodeFactory.getInode(publishInode[i],File.class);
 
      if (InodeUtils.isSet(file.getInode())) {
        //calls the asset factory edit
       
        try{
          PublishFactory.publishAsset(file,reqImpl.getHttpServletRequest());
          SessionMessages.add(req, "message", "message.file_list.published");
View Full Code Here

    // calls edit method from super class that returns parent folder
    super._editWebAsset(req, res, config, form, user, WebKeys.FILE_EDIT);

    // This can't be done on the WebAsset so it needs to be done here.
    File file = (File) req.getAttribute(WebKeys.FILE_EDIT);

       Folder parentFolder = null;

    if(req.getParameter("parent") != null) {
      parentFolder = folderAPI.find(req.getParameter("parent"),user,false);
    } else {
      parentFolder = fileAPI.getFileFolder(file,WebAPILocator.getHostWebAPI().getCurrentHost(req), user, false);
    }

    // setting parent folder path and inode on the form bean
    if(parentFolder != null) {
      FileForm cf = (FileForm) form;
      cf.setSelectedparent(parentFolder.getName());
      cf.setParent(parentFolder.getInode());
      cf.setSelectedparentPath(APILocator.getIdentifierAPI().find(parentFolder).getPath());
      file.setParent(parentFolder.getInode());
    }



    req.setAttribute("PARENT_FOLDER",parentFolder);
View Full Code Here

          toReturn.put("name", imageContentlet.getTitle());
          toReturn.put("identifier", imageContentlet.getIdentifier());
          toReturn.put("extension", com.dotmarketing.util.UtilMethods.getFileExtension(imageContentlet.getTitle()));
        }
      } else {
        File imgFile = TemplateFactory.getImageFile(template);
        if(imgFile!=null){
          toReturn.put("inode", imgFile.getInode());
          toReturn.put("name", imgFile.getFileName());
          toReturn.put("identifier", imgFile.getIdentifier());
          toReturn.put("extension", com.dotmarketing.util.UtilMethods.getFileExtension(imgFile.getFileName()));
        }
      }
    }
    return toReturn;
  }
View Full Code Here

  throws Exception {
   
    Logger.debug(this, "I'm moving the webasset");
   
    // gets the current container being edited from the request object
    File webAsset = (File) req.getAttribute(WebKeys.FILE_EDIT);
   
    // gets folder parent
    String parentInode = req.getParameter("parent");
   
    if (parentInode != null && parentInode.length() != 0 && !parentInode.equalsIgnoreCase("")) {
View Full Code Here

   
    // calls edit method from super class that returns parent folder
    super._editWebAsset(req, res, config, form, user, WebKeys.FILE_EDIT);
   
    // This can't be done on the WebAsset so it needs to be done here.
    File file = (File) req.getAttribute(WebKeys.FILE_EDIT);
   
   
    Folder parentFolder = null;
   
    if(req.getParameter("parent") != null) {
      parentFolder = folderAPI.find(req.getParameter("parent"),user,false);
    } else if(UtilMethods.isSet(file.getIdentifier())){
      Identifier tempId = APILocator.getIdentifierAPI().find(file.getIdentifier());
      Host fileHost = APILocator.getHostAPI().find(tempId.getHostId(), user, false);
      parentFolder = fileAPI.getFileFolder(file,fileHost, user, false);
    }

    // setting parent folder path and inode on the form bean
    if(parentFolder != null) {
      FileForm cf = (FileForm) form;
      cf.setSelectedparent(parentFolder.getName());
      cf.setParent(parentFolder.getInode());
      cf.setSelectedparentPath(APILocator.getIdentifierAPI().find(parentFolder).getPath());
      file.setParent(parentFolder.getInode());
    }
    if(InodeUtils.isSet(file.getIdentifier())){
       APILocator.getFileAPI().invalidateCache(file);
    }
  }
View Full Code Here

      UploadPortletRequest uploadReq = PortalUtil.getUploadPortletRequest(req);
     
     
      // gets the new information for the container from the request
      // object
      File file = new File();
      file.setTitle(fileForm.getTitle());
      BeanUtils.copyProperties(file,fileForm);
      req.setAttribute(WebKeys.FILE_FORM_EDIT,file);
           
      // gets the current container being edited from the request object
      File currentFile = (File) req.getAttribute(WebKeys.FILE_EDIT);
     
      // parent folder
      String parent = ParamUtil.getString(req, "parent");
      Folder folder = APILocator.getFolderAPI().find(parent, user, false);
      //http://jira.dotmarketing.net/browse/DOTCMS-5899
      if(InodeUtils.isSet(currentFile.getIdentifier())){
        Identifier id = APILocator.getIdentifierAPI().find(currentFile);
        if(id!=null && InodeUtils.isSet(id.getInode())){
          String URI = id.getURI();
          String uriPath = URI.substring(0,URI.lastIndexOf("/")+1);
          String folderPath = APILocator.getIdentifierAPI().find(folder).getPath();
          if(!uriPath.equals(folderPath)){
            id.setURI(folderPath+currentFile.getFileName());
            APILocator.getIdentifierAPI().save(id);
          }
        }
      }

      req.setAttribute(WebKeys.PARENT_FOLDER, folder)// Since the above query is expensive, save it into request object
     
      if(currentFile!=null)
        file.setIdentifier(currentFile.getIdentifier());
     
      _checkPermissions(file, folder, user, httpReq);
     
      // gets user id from request for modified user
      String userId = user.getUserId();
     
      boolean previousShowMenu = file.isShowOnMenu();
     
      long uploadFileMaxSize = Long.parseLong(Config.getStringProperty("UPLOAD_FILE_MAX_SIZE"));

      //Checking the max file size
      java.io.File uploadedFile = uploadReq.getFile("uploadedFile");
     
      if(currentFile!=null && UtilMethods.isSet(currentFile.getInode())){
        java.io.File editedFile = new java.io.File(APILocator.getFileAPI().getAssetIOFile(currentFile).getPath()+"_text");
        if(editedFile.exists()){
          FileChannel ic = new FileInputStream(editedFile).getChannel();
          FileChannel oc = new FileOutputStream(APILocator.getFileAPI().getAssetIOFile(currentFile)).getChannel();
          ic.transferTo(0, ic.size(), oc);
          ic.close();
          oc.close();
        }
      }

     
      //Do we have an uploaded file or not?
      boolean haveUpload = (uploadedFile.exists() && uploadedFile.length()>0);
      boolean tmpFile = true;
     
      if(!haveUpload){

        // look for a edited file in the users session, if it is there, use that
        if(UtilMethods.isSet(fileForm.get_imageToolSaveFile())){
          String x =fileForm.get_imageToolSaveFile().trim();
          if( x != null){
            x = PublicEncryptionFactory.decryptString(x);
            uploadedFile = new java.io.File( x.trim());
            haveUpload = (uploadedFile.exists() && uploadedFile.length()>0);
          }
          else{
            x=null;
          }
          reqImpl.getHttpServletRequest().getSession().removeAttribute(WebKeys.IMAGE_TOOL_SAVE_FILES);
        }
      }
     
     
     
      if(haveUpload) {
        if ((uploadFileMaxSize > 0) && (uploadedFile.length() > uploadFileMaxSize)) {
          // when there is an error saving should unlock working asset
          WebAssetFactory.unLockAsset(currentFile);
          throw new ActionException();
        }
      }
     
     
      // CHECK THE FOLDER PATTERN
      if (UtilMethods.isSet(file.getFileName()) && !APILocator.getFolderAPI().matchFilter(folder, file.getFileName())) {
        SessionMessages.add(req, "error", "message.file_asset.error.filename.filters");
        // when there is an error saving should unlock working asset
        WebAssetFactory.unLockAsset(currentFile);
        throw new ActionException("message.file_asset.error.filename.filters");
      }
     
     
      // Checking permissions
      _checkPermissions(currentFile, folder, user, httpReq);
     
     
      //Setting some flags
      boolean editing = (InodeUtils.isSet(currentFile.getInode()));

     

      if(!haveUpload){
        uploadedFile = APILocator.getFileAPI().getAssetIOFile(currentFile);
        tmpFile = false;
      }
     
     
      // if we don't have a file anywhere, die
      if(!(uploadedFile.exists() && uploadedFile.length()>0)){
        SessionMessages.add(req, "error", "message.file_asset.error.nofile");
        // when there is an error saving should unlock working asset
        WebAssetFactory.unLockAsset(currentFile);
        throw new ActionException("message.file_asset.error.nofile")
      }

      String fileName = (editing) ? currentFile.getFileName() : fileForm.getFileName();
     
      //getting mime type
      String mimeType = APILocator.getFileAPI().getMimeType(fileName);

      file.setMimeType(mimeType);

      if (editing && haveUpload && !
          APILocator.getFileAPI().getMimeType(fileName).equals(APILocator.getFileAPI().getMimeType(uploadedFile.getName()))) {
        SessionMessages.add(req, "error", "message.file_asset.error.mimetype");
        // when there is an error saving should unlock working asset
        Logger.error(this.getClass(), "MimeType Mismatch:" + fileName + " : " + uploadedFile.getName());
        WebAssetFactory.unLockAsset(currentFile);
        HibernateUtil.rollbackTransaction();
        throw new ActionException("message.file_asset.error.mimetype");
      }
 
      // checks if another identifier with the same name exists in the same
      // folder
      if ((!editing) && (APILocator.getFileAPI().fileNameExists(folder, fileName))) {
        SessionMessages.add(req, "error", "message.file_asset.error.filename.exists");
        throw new ActionException("message.file_asset.error.filename.exists");
      }

      //sets new file properties
      file.setFileName(fileName);
      file.setModUser(userId);
     
      if (haveUpload) {
        file.setSize((int)uploadedFile.length());
      }
      else {
        file.setSize(currentFile.getSize());
        file.setWidth(currentFile.getWidth());
        file.setHeight(currentFile.getHeight());
      }
      //Saving the file, this creates the new version and save the new data
      File workingFile = null;
      workingFile = APILocator.getFileAPI().saveFile(file, uploadedFile, folder, user, false);
      APILocator.getVersionableAPI().setWorking(file);
      APILocator.getVersionableAPI().setLocked(file, false, user);
      if(uploadedFile != null && uploadedFile.exists() &&tmpFile){
        uploadedFile.delete();
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.files.model.File

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.