Package com.dotmarketing.portlets.files.model

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


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


 
  @SuppressWarnings("unchecked")
  public void _getVersionBackWebAsset(ActionRequest req, ActionResponse res, PortletConfig config, ActionForm form,
      User user) throws Exception {
   
    File workingFile = (File) super._getVersionBackWebAsset(req, res, config, form, user, File.class,
        WebKeys.FILE_EDIT);
    File fileVersion = (File) req.getAttribute(WebKeys.FILE_EDIT);
    Identifier identifier = APILocator.getIdentifierAPI().find(fileVersion);
    String parentInode = req.getParameter("parent");
    Folder parent = null;
    if (parentInode != null && parentInode.length() != 0 && !parentInode.equalsIgnoreCase("")) {
      // the parent is being passed through the request
      parent = (Folder) InodeFactory.getInode(parentInode, Folder.class);
      Logger.debug(this, "Parent Folder=" + parent.getInode());
    } else {
      parent = APILocator.getFolderAPI().findParentFolder(workingFile, user, false);
      Logger.debug(this, "Parent Folder=" + parent.getInode());
    }
   
    WebAsset webAsset = (WebAsset) APILocator.getVersionableAPI().findWorkingVersion(identifier, user, false);
    WebAssetFactory.createAsset(fileVersion, user == null?"":user.getUserId(),parent, identifier,true);
    /*if (!webAsset.getInode().equals(fileVersion.getInode())) {
      webAsset.setWorking(false);
      HibernateUtil.saveOrUpdate(webAsset);
    }*/

    WorkingCache.removeAssetFromCache(workingFile);
    WorkingCache.addToWorkingAssetToCache(workingFile);
    APILocator.getFileAPI().invalidateCache(workingFile);
    APILocator.getFileAPI().invalidateCache(fileVersion);
    if (fileVersion.isLive()){
      LiveCache.removeAssetFromCache(fileVersion);
      LiveCache.addToLiveAssetToCache(fileVersion);
    }
  }
View Full Code Here

            perAPI.removePermissions((File)file);

            List<Versionable> versions = APILocator.getVersionableAPI().findAllVersions(identifier, APILocator.getUserAPI().getDefaultUser(),false);
           
            for (Versionable versionV : versions) {
              File version = (File) versionV;
              //assets cache
              if (version.isLive())
                  LiveCache.removeAssetFromCache(version);
              if (version.isWorking())
                WorkingCache.removeAssetFromCache(version);
 
        InodeFactory.deleteInode(version);
            }
            APILocator.getIdentifierAPI().delete(identifier);
View Full Code Here

   
  }
 
  public boolean accept(java.io.File dir, String name) {
    for (Versionable version : versions) {
      File file = (File)version;
      if (name.startsWith(String.valueOf(file.getInode()) + "_thumb")
          || name.startsWith(String.valueOf(file.getInode()) + "_resized")
          || name.contains(WebKeys.GENERATED_FILE)
      )
        return true;
    }
    return false;
View Full Code Here

  @Override
  protected List<File> getRelatedFiles(Contentlet contentlet) throws DotDataException {
      HibernateUtil dh = new HibernateUtil(File.class);

        File f = new File();
        String tableName = f.getType();

        String sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", tree tree, inode "
        + tableName + "_1_ where tree.parent = ? and tree.child = " + tableName + ".inode and " + tableName
        + "_1_.inode = " + tableName + ".inode and "+tableName+"_1_.type ='"+tableName+"'";

View Full Code Here

  public void init(Object initData) {

  }

  public File getNewFile(){
    return new File();
  }
View Full Code Here

        }else{
        p = WorkingCache.getPathFromCache(id.getURI(), id.getHostId());
        }
    } catch (Exception e1) {
      Logger.error(FileTool.class,e1.getMessage(),e1);
      return new File();
    }
        p = p.substring(5, p.lastIndexOf("."));
        IFileAsset file = null;
    try {
      if(id!=null && InodeUtils.isSet(id.getId()) && id.getAssetType().equals("contentlet")){
        Contentlet cont = APILocator.getContentletAPI().findContentletByIdentifier(id.getId(), true, APILocator.getLanguageAPI().getDefaultLanguage().getId(), APILocator.getUserAPI().getSystemUser(), false);
        if(cont!=null && InodeUtils.isSet(cont.getInode())){
          file = APILocator.getFileAssetAPI().fromContentlet(cont);
        }
      }else{
        file = fileAPI.find(p, userAPI.getSystemUser(), false);
      }

    } catch (Exception e) {
      Logger.error(FileTool.class,e.getMessage(),e);
    }
    if(file == null){
      file = new File();
    }
    return file;
  }
View Full Code Here

          id = request.getParameter("inode");
        }
        String url = (request.getParameter("path") != null) ? request.getParameter("path"): request.getParameter("url");

        Identifier identifier = null;
        File file = null;
        //Contentlet contentlet = null;


        String inode = null;
        Boolean fileAsContent = false;


        if(UtilMethods.isSet(url)) {
            //If path is the dotasset portlet
            if(url.startsWith("/dotAsset")) {
            StringTokenizer _st = new StringTokenizer(url, "/");
            String _fileName = null;
            while(_st.hasMoreElements()){
              _fileName = _st.nextToken();
            }
                id = UtilMethods.getFileName(_fileName); // Sets the identifier
            } else {
            //If it's a regular path
              Host currentHost;
        try {
          currentHost = WebAPILocator.getHostWebAPI().getCurrentHost(request);
          String path = LiveCache.getPathFromCache(url, currentHost);
          String cinode=path.split("/")[3];
          id=APILocator.getIdentifierAPI().findFromInode(cinode).getId();
        } catch (Exception e) {
          Logger.error(ResizeImageServlet.class, e.getMessage(), e);
          throw new ServletException(e.getMessage(), e);
        }


            }
        }

        // if we have an id
        if( UtilMethods.isSet(id) ) {

          try {
            identifier = APILocator.getIdentifierAPI().loadFromCache(id);
            if(identifier != null && (InodeUtils.isSet(identifier.getInode()))) {
              //it's an identifier
              String path = null;
              try {
                path = (liveMode) ? LiveCache.getPathFromCache(identifier.getURI(), identifier.getHostId())
              : WorkingCache.getPathFromCache(identifier.getURI(), identifier.getHostId());
              } catch(DotContentletStateException e) {
                path = WorkingCache.getPathFromCache(identifier.getURI(), identifier.getHostId());
              }

              if(path==null) {
                  Logger.debug(this.getClass(), "Can't find path with URI " + identifier.getURI());
                  return;
                }

                inode = UtilMethods.getFileName(path);
            } else {
              //it might be an inode
              try {
                file = APILocator.getFileAPI().find(id, user, true);
              } catch(Exception e) {
                Contentlet c = APILocator.getContentletAPI().find(id, user, true);
                fileAsContent = UtilMethods.isSet(c);
              }
                  if(file != null && (InodeUtils.isSet(file.getInode()))) {
                    inode = file.getInode();
                    identifier = APILocator.getIdentifierAPI().find(file.getIdentifier());
                  } else{
                    //Finally it's not a file and we did the first round trip to database
                    //then we do the second round trip to database to find the identifier,
                    //but after this the next hit will find it cached.
                    identifier = APILocator.getIdentifierAPI().find(id);
                    if(identifier != null && (InodeUtils.isSet(identifier.getInode())) ) {
                  String path = LiveCache.getPathFromCache(identifier.getURI(), identifier.getHostId());
                      inode = UtilMethods.getFileName(path);
                    }
                  }
            }
      } catch (Exception e) {
        System.out.println(e);
      }

        }


        if (!InodeUtils.isSet(inode) && !fileAsContent) {
            response.sendError(404);
            return;
        }

        try {
      //Checking permissions
          /**
           * Build a fake proxy file object so we
           * can get inheritable permissions on it
           * without having to hit cache or db
           */

            file = null;
            if(identifier!=null && UtilMethods.isSet(identifier.getInode())){
              file = new File();
              file.setIdentifier(identifier.getInode());
            }
            else{
              try {
                file = APILocator.getFileAPI().find(inode, user, true);
                identifier.setId(file.getIdentifier());
        } catch (Exception e) {
          Logger.error(ResizeImageServlet.class,e.getMessage(),e);
        }

            }

            if (file!=null && !permissionAPI.doesUserHavePermission(file, PERMISSION_READ, user, true)) {
              if(user == null)
                //Sending user to unauthorized the might send him to login
                response.sendError(401, "The requested file is unauthorized");
              else
                //sending the user to forbidden
                response.sendError(403, "The requested file is forbidden");
               return;
            }
    } catch (DotDataException e1) {
      Logger.error(this,e1.getMessage());
      response.sendError(500,e1.getMessage());
      return;
    }



        String h = request.getParameter("h");
        String w = request.getParameter("w");

        String maxh = request.getParameter("maxh");
        String maxw = request.getParameter("maxw");

        int height = Config.getIntProperty("DEFAULT_HEIGHT");
        int width = Config.getIntProperty("DEFAULT_WIDTH");
        int imageWidth = 0;
        int imageHeight = 0;
        double imageRatio = 0;

        try {

            if (fileAsContent || inode != null && inode.length() > 0 && InodeUtils.isSet(inode)) {

              boolean isSet = false;
              boolean isCont = false;
              String fileName = "";
              String inodeOrId = "";

              String contAssetPath = "";
              int imgWidth = 0;
              int imgLength = 0;
              String ext = "";
              if(fileAsContent || id!=null && InodeUtils.isSet(identifier.getId()) && identifier.getAssetType().equals("contentlet")){
                Contentlet cont = null;

                if(fileAsContent) {
                  cont = APILocator.getContentletAPI().find(id, user, true);
                  inode = id;
                } else {
                  try {
                      boolean live=true;
                          if(request.getSession().getAttribute("tm_date")!=null) {
                              live=true;
                              Identifier ident=APILocator.getIdentifierAPI().find(id);
                              if(UtilMethods.isSet(ident.getSysPublishDate()) || UtilMethods.isSet(ident.getSysExpireDate())) {
                                  Date fdate=new Date(Long.parseLong((String)request.getSession().getAttribute("tm_date")));
                                  if(UtilMethods.isSet(ident.getSysPublishDate()) && ident.getSysPublishDate().before(fdate))
                                      live=false;
                                  if(UtilMethods.isSet(ident.getSysExpireDate()) && ident.getSysExpireDate().before(fdate))
                                      return; // expired!
                              }
                          }
                    cont = APILocator.getContentletAPI().findContentletByIdentifier(id, live, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, true);
                  }
                  catch(DotContentletStateException e) {
                    cont = APILocator.getContentletAPI().findContentletByIdentifier(id, false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, true);
                  }

                  if(cont==null) {
                    Logger.debug(this.getClass(), "Can't find content with id " + id);
                    return;
                  }
                }

                FileAsset fa = APILocator.getFileAssetAPI().fromContentlet(cont);
                isSet = InodeUtils.isSet(cont.getInode());
                fileName = fa.getFileName();
                isCont = true;
                inodeOrId = cont.getInode();
              contAssetPath = APILocator.getFileAssetAPI().getRealAssetPath(cont.getInode());
              java.util.Map<String, Object> keyValueMap = null;
              String JSONValue = cont.getStringProperty(FileAssetAPI.META_DATA_FIELD);
              //Convert JSON to Table Display {key, value, order}
              if(UtilMethods.isSet(JSONValue)){
                keyValueMap =  com.dotmarketing.portlets.structure.model.KeyValueFieldUtil.JSONValueToHashMap(JSONValue);
                if(UtilMethods.isSet((String)keyValueMap.get("width"))){
                  imgWidth = Integer.parseInt((String)keyValueMap.get("width"));
                }
                if(UtilMethods.isSet((String)keyValueMap.get("height"))){
                  imgLength = Integer.parseInt((String)keyValueMap.get("height"));
                }
              }
              if(!contAssetPath.endsWith(java.io.File.separator)){
                contAssetPath += java.io.File.separator;
              }
              ext = fa.getExtension();
              }else if(InodeUtils.isSet(identifier.getId())){
                    file = fileAPI.find(inode,user,true);
                    isSet =InodeUtils.isSet(file.getInode());
                    fileName = file.getFileName();
                    inodeOrId = inode;
                    imgWidth = file.getWidth();
                    imgLength = file.getHeight();
                    ext = file.getExtension();
              }


                if (isSet) {
                    // Set the size
View Full Code Here

      Contentlet slideShow = results.get(0);
      String slideShowTitle = (String)conAPI.getFieldValue(slideShow, slideShowTitleF);
      String slideShowCredits = (String)conAPI.getFieldValue(slideShow, slideShowCreditsF);
      String slideShowAudioTitle = (String)conAPI.getFieldValue(slideShow, slideShowAudioTitleF);
      String slideShowAudioFileInode = (String)conAPI.getFieldValue(slideShow, slideShowAudioFileF);
      File slideShowFile = (File) InodeFactory.getInode(slideShowAudioFileInode, File.class);
     
      List<Contentlet> slideImages = RelationshipFactory.getAllRelationshipRecords(relationship, slideShow, true, true);
     
      sw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");

      sw.write("<slidesInfo>\n");
      sw.write("  <baseInfo>\n");
      sw.write("    <intTotalImg>" + slideImages.size() + "</intTotalImg>\n");
      sw.write("    <strTitle>" + XMLUtils.xmlEscape(slideShowTitle) + "</strTitle>\n");
      sw.write("    <strCredits>" + XMLUtils.xmlEscape(slideShowCredits) + "</strCredits>\n");
      sw.write("    <strAudio>" + XMLUtils.xmlEscape(slideShowAudioTitle) + "</strAudio>\n");
      sw.write("  </baseInfo>\n");
      sw.write("  <strSound>\n");
      sw.write("    <strPathSound>" + (slideShowFile.getURI() == null || slideShowFile.getURI().equals("")?"":slideShowFile.getURI()) + "</strPathSound>\n");
      sw.write("  </strSound>\n");

      StringBuffer imagesPathsXML = new StringBuffer ();
      StringBuffer imagesTimingXML = new StringBuffer ();
      StringBuffer imagesTextXML = new StringBuffer ();
      for (Contentlet slide : slideImages) {
        // only show live slides
        if (!slide.isLive()) {
          continue;
        }

        //String slideTitle = (String)ContentletFactory.getFieldValue(slide, slideTitleF);
        String slideTextBody = (String)conAPI.getFieldValue(slide, slideTextBodyF);
        long slideTiming = (Long)conAPI.getFieldValue(slide, slideTimingF);
        String slideImageInode = (String)conAPI.getFieldValue(slide, slideImageF);
        //File slideImage = (File) InodeFactory.getInode(slideImageInode, File.class);
        //Identifier slideImageIdentifier = (Identifier) InodeFactory.getInode(slideImageInode, Identifier.class);
        Identifier slideImageIdentifier = APILocator.getIdentifierAPI().find(slideImageInode);
        File slideImage = (File)APILocator.getVersionableAPI().findWorkingVersion(slideImageIdentifier, user, true);

        imagesPathsXML.append("    <strPath>" + (slideImage.getURI() == null || slideImage.getURI().equals("")?"":slideImage.getURI()) + "</strPath>\n");
        imagesTimingXML.append("    <imgInterval>" + slideTiming + "</imgInterval>\n");
        imagesTextXML.append("    <strOver>" + XMLUtils.xmlEscape(slideTextBody) + "</strOver>\n");
      }

      sw.write("  <strImages>\n");
View Full Code Here

              contAssetPath = APILocator.getFileAssetAPI().getRealAssetPath(cont.getInode());
              if(!contAssetPath.endsWith(java.io.File.separator)){
                contAssetPath += java.io.File.separator;
              }
              }else if(id!=null && InodeUtils.isSet(id.getId())){
                    File file = fileAPI.find(inode,user,true);
                    Identifier tempId = APILocator.getIdentifierAPI().loadFromCache(file.getIdentifier());
                    isSet =InodeUtils.isSet(file.getInode());
                    boolean isInodeUUID = false;
                    //Verify if file asset inode is UUID (1.9+) or a simple string (legacy image from 1.7)
            try{
              String tempInode = RegEX.find(file.getInode(), "[\\w]{8}(-[\\w]{4}){3}-[\\w]{12}").get(0).getMatch();
              if(UtilMethods.isSet(tempInode))
                //Image/file as content, from 1.9+ version
                isInodeUUID = true;
            }
            catch (Exception e){
              //Legacy image, the inode is not a valid UUID string.
              isInodeUUID = false;
            }
            if(isInodeUUID && "contentlet".equals(tempId.getAssetType()))
              fileName = file.getFileName();
            else
              fileName = inode + "." + UtilMethods.getFileExtension(file.getFileName());
                    inodeOrId = inode;
              }


                if (isSet) {
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.