Package com.dotmarketing.portlets.contentlet.business

Examples of com.dotmarketing.portlets.contentlet.business.BinaryContentExporter


      if(key.startsWith("CONTENT_EXPORTERS")) {
        String[]  exporterClasses = Config.getStringArrayProperty(key);
        for(String exporterClassName : exporterClasses) {
          try {
            Class<BinaryContentExporter> exporterClass = (Class<BinaryContentExporter>) Class.forName(exporterClassName);
            BinaryContentExporter exporter = exporterClass.newInstance();
            if(exportersByPathMapping.containsKey(exporter.getPathMapping()))
              Logger.warn(BinaryExporterServlet.class, "There is already an exporter registered to path " + exporter.getPathMapping() +
                  " this new exporter: " + exporter.getName() + " will replace the previously registered: " +
                  exportersByPathMapping.get(exporter.getPathMapping()).getName());

            Logger.info(this, "Exporter \"" + exporter.getName() + "\" registered for path /" + exporter.getPathMapping());
            exportersByPathMapping.put(exporter.getPathMapping(), exporter);

          } catch (ClassNotFoundException e) {
            Logger.warn(BinaryExporterServlet.class, e.getMessage(), e);
          } catch (InstantiationException e) {
            Logger.warn(BinaryExporterServlet.class, e.getMessage(), e);
View Full Code Here


    else{
      assetIdentifier = uuid;
    }

    String fieldVarName = uriPieces.length > 3?uriPieces[3]:null;
    BinaryContentExporter exporter = exportersByPathMapping.get(exporterPath);
    if(exporter == null) {
      Logger.warn(this, "No exporter for path " + exporterPath + " is registered. Requested url = " + uri);
      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    UserWebAPI userWebAPI = WebAPILocator.getUserWebAPI();
    ContentletAPI contentAPI = APILocator.getContentletAPI();
    BinaryContentExporter.BinaryContentExporterData data = null;
    File inputFile = null;
    HttpSession session = req.getSession(false);
    List<String> tempBinaryImageInodes = null;
        if ( session != null && session.getAttribute( Contentlet.TEMP_BINARY_IMAGE_INODES_LIST ) != null ) {
            tempBinaryImageInodes = (List<String>) session.getAttribute( Contentlet.TEMP_BINARY_IMAGE_INODES_LIST );
        } else {
            tempBinaryImageInodes = new ArrayList<String>();
        }

        boolean isTempBinaryImage = tempBinaryImageInodes.contains(assetInode);
    try {
      User user = userWebAPI.getLoggedInUser(req);
      boolean respectFrontendRoles = !userWebAPI.isLoggedToBackend(req);
      String downloadName = "file_asset";
      long lang = APILocator.getLanguageAPI().getDefaultLanguage().getId();
      try {
        String x = null;
        if (session != null) {
          x = (String) session.getAttribute(WebKeys.HTMLPAGE_LANGUAGE);
        } else {
          x = (String) req.getAttribute(WebKeys.HTMLPAGE_LANGUAGE);
        }
        lang = Long.parseLong(x);
      } catch(Exception e){
        // Number parsing exception
      }

      boolean isContent = false;
      try {
        isContent = isContent(uuid, byInode, lang, respectFrontendRoles);
      }catch (DotStateException e) {
        resp.sendError(404);
        return;
      }

      if (isContent){
        Contentlet content = null;
        if(byInode) {
          if(isTempBinaryImage)
            content = contentAPI.find(assetInode, APILocator.getUserAPI().getSystemUser(), respectFrontendRoles);
          else
            content = contentAPI.find(assetInode, user, respectFrontendRoles);
          assetIdentifier = content.getIdentifier();
        } else {
            boolean live=userWebAPI.isLoggedToFrontend(req);
            if (req.getSession(false) != null && req.getSession().getAttribute("tm_date")!=null) {
                live=true;
                Identifier ident=APILocator.getIdentifierAPI().find(assetIdentifier);
                if(UtilMethods.isSet(ident.getSysPublishDate()) || UtilMethods.isSet(ident.getSysExpireDate())) {
                    Date fdate=new Date(Long.parseLong((String)req.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!
                }
            }
          content = contentAPI.findContentletByIdentifier(assetIdentifier, live, lang, user, respectFrontendRoles);
          assetInode = content.getInode();
        }
        Field field = content.getStructure().getFieldVar(fieldVarName);
        if(field == null){
          Logger.debug(this,"Field " + fieldVarName + " does not exists within structure " + content.getStructure().getVelocityVarName());
          resp.sendError(404);
          return;
        }

        if(isTempBinaryImage)
          inputFile = contentAPI.getBinaryFile(content.getInode(), field.getVelocityVarName(), APILocator.getUserAPI().getSystemUser());
        else
          inputFile = contentAPI.getBinaryFile(content.getInode(), field.getVelocityVarName(), user);
        if(inputFile == null){
          Logger.debug(this,"binary file '" + fieldVarName + "' does not exist for inode " + content.getInode());
          resp.sendError(404);
          return;
        }
        downloadName = inputFile.getName();
      }
      else{
        // if we are using this as a "Save as" from the image too
        fieldVarName = WebKeys.EDITED_IMAGE_FILE_ASSET;
        com.dotmarketing.portlets.files.model.File dotFile = null;

        // get the identifier from cache
        if(byInode) {
          dotFile = fileAPI.find(assetInode,user,false);
          downloadName = dotFile.getFileName();
          //com.dotmarketing.portlets.files.model.File dotFile = APILocator.getFileAPI().get(assetIdentifier, user, respectFrontendRoles);
          assetIdentifier = dotFile.getIdentifier();
        }
        Identifier id = APILocator.getIdentifierAPI().find(assetIdentifier);

        // no identifier, no soup!
        if(id == null || ! UtilMethods.isSet(id.getInode())){
          Logger.debug(this,"Identifier: " + assetIdentifier +"not found");
          resp.sendError(404);
          return;
        }

        boolean hasLive = (LiveCache.getPathFromCache(id.getURI(), id.getHostId()) != null);
        // no live version and front end, no soup
        if(respectFrontendRoles && ! hasLive){
          Logger.debug(this,"File :" + id.getInode() +"is not live");
          resp.sendError(404);
          return;
        }
        // no permissions, no soup!
        if(!APILocator.getPermissionAPI().doesUserHavePermission(id, PermissionAPI.PERMISSION_READ, user)){
          Logger.debug(this,"user: " + user + " does not have read on File :" + id.getInode());
          if(WebAPILocator.getUserWebAPI().isLoggedToFrontend(req)){
            resp.sendError(403);
          }else{
            resp.sendError(401);
          }
          return;
        }

        if(assetInode != null){
          inputFile = new File(fileAPI.getRealAssetPath(assetInode, UtilMethods.getFileExtension(dotFile.getFileName())));
        }
        else if(respectFrontendRoles){
          if(realPath != null){
            inputFile = new File(realPath + LiveCache.getPathFromCache(id.getURI(), id.getHostId()));
          }else{
            inputFile = new File(FileUtil.getRealPath(assetPath + LiveCache.getPathFromCache(id.getURI(), id.getHostId())));
          }
        }else{
          if(realPath != null){
            inputFile = new File(realPath + WorkingCache.getPathFromCache(id.getURI(), id.getHostId()));
          }else{
            inputFile = new File(FileUtil.getRealPath(assetPath + WorkingCache.getPathFromCache(id.getURI(), id.getHostId())));
          }
        }
      }
      //DOTCMS-5674
      if(UtilMethods.isSet(fieldVarName)){
        params.put("fieldVarName", new String[]{fieldVarName});
        params.put("assetInodeOrIdentifier", new String[]{uuid});
      }
      data = exporter.exportContent(inputFile, params);

      // THIS IS WHERE THE MAGIC HAPPENS
      // save to session if user looking to edit a file
      if (req.getParameter(WebKeys.IMAGE_TOOL_SAVE_FILES) != null) {
                Map<String, String> files;
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.contentlet.business.BinaryContentExporter

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.