Beispiel #1
0
  /**
   * Get download link of a node which stored binary data
   *
   * @param node Node
   * @return download link
   * @throws Exception
   */
  public static String getDownloadLink(Node node) throws Exception {

    if (!Utils.getRealNode(node).getPrimaryNodeType().getName().equals(NT_FILE)) return null;

    // Get binary data from node
    DownloadService dservice = WCMCoreUtils.getService(DownloadService.class);
    Node jcrContentNode = node.getNode(JCR_CONTENT);
    InputStream input = jcrContentNode.getProperty(JCR_DATA).getStream();

    // Get mimeType of binary data
    String mimeType = jcrContentNode.getProperty(JCR_MIMETYPE).getString();

    // Make download stream
    InputStreamDownloadResource dresource = new InputStreamDownloadResource(input, mimeType);

    // Make extension part for file if it have not yet
    DMSMimeTypeResolver mimeTypeSolver = DMSMimeTypeResolver.getInstance();
    String ext = "." + mimeTypeSolver.getExtension(mimeType);
    String fileName = Utils.getRealNode(node).getName();
    if (fileName.lastIndexOf(ext) < 0 && !mimeTypeSolver.getMimeType(fileName).equals(mimeType)) {
      dresource.setDownloadName(fileName + ext);
    } else {
      dresource.setDownloadName(fileName);
    }

    return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
  }
 public String getDownloadLink(Node node) throws Exception {
   DownloadService dservice = getApplicationComponent(DownloadService.class);
   Node jcrContentNode = node.getNode(org.exoplatform.ecm.webui.utils.Utils.JCR_CONTENT);
   InputStream input =
       jcrContentNode.getProperty(org.exoplatform.ecm.webui.utils.Utils.JCR_DATA).getStream();
   String mimeType =
       jcrContentNode.getProperty(org.exoplatform.ecm.webui.utils.Utils.JCR_MIMETYPE).getString();
   InputStreamDownloadResource dresource = new InputStreamDownloadResource(input, mimeType);
   DMSMimeTypeResolver mimeTypeSolver = DMSMimeTypeResolver.getInstance();
   String ext = mimeTypeSolver.getExtension(mimeType);
   StringBuffer fileNameStrBuffer = new StringBuffer(node.getName());
   if (fileNameStrBuffer.lastIndexOf("." + ext) < 0) {
     fileNameStrBuffer.append(".").append(ext);
   }
   dresource.setDownloadName(fileNameStrBuffer.toString());
   return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
 }
Beispiel #3
0
 public static String getFileSource(FileAttachment attachment) throws Exception {
   DownloadService dservice =
       (DownloadService) PortalContainer.getComponent(DownloadService.class);
   try {
     InputStream input = attachment.getInputStream();
     String fileName = attachment.getName();
     byte[] imageBytes = null;
     if (input != null) {
       imageBytes = new byte[input.available()];
       input.read(imageBytes);
       ByteArrayInputStream byteImage = new ByteArrayInputStream(imageBytes);
       InputStreamDownloadResource dresource = new InputStreamDownloadResource(byteImage, "image");
       dresource.setDownloadName(fileName);
       return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
     }
   } catch (Exception e) {
     log.error("Can not get File Source, exception: " + e.getMessage());
   }
   return "";
 }
Beispiel #4
0
 public static String getThumbnailImage(Node node, String propertyName) throws Exception {
   ThumbnailService thumbnailService =
       Util.getUIPortal().getApplicationComponent(ThumbnailService.class);
   if (node.isNodeType(NT_FILE)) {
     String mimeType = node.getNode(JCR_CONTENT).getProperty(JCR_MIMETYPE).getString();
     if (mimeType.startsWith("image")) {
       Node thumbnailNode = thumbnailService.addThumbnailNode(node);
       InputStream inputStream = node.getNode(JCR_CONTENT).getProperty(JCR_DATA).getStream();
       thumbnailService.createSpecifiedThumbnail(
           thumbnailNode, ImageIO.read(inputStream), propertyName);
     }
   }
   Node thumbnailNode = thumbnailService.getThumbnailNode(node);
   if (thumbnailNode != null && thumbnailNode.hasProperty(propertyName)) {
     DownloadService dservice = Util.getUIPortal().getApplicationComponent(DownloadService.class);
     InputStream input = thumbnailNode.getProperty(propertyName).getStream();
     InputStreamDownloadResource dresource = new InputStreamDownloadResource(input, "image");
     dresource.setDownloadName(node.getName());
     return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
   }
   return null;
 }
Beispiel #5
0
 public static String getDataSource(Attachment attach, DownloadService dservice) throws Exception {
   if (attach != null) {
     try {
       InputStream input = attach.getInputStream();
       byte[] imageBytes = null;
       if (input != null) {
         imageBytes = new byte[input.available()];
         input.read(imageBytes);
         ByteArrayInputStream byteImage = new ByteArrayInputStream(imageBytes);
         InputStreamDownloadResource dresource =
             new InputStreamDownloadResource(byteImage, attach.getMimeType());
         dresource.setDownloadName(attach.getName());
         return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
       }
     } catch (PathNotFoundException ex) {
       if (log.isDebugEnabled()) {
         log.debug("The attachment has no data source", ex);
       }
       return null;
     }
   }
   return null;
 }
Beispiel #6
0
 public static String getThumbnailImage(InputStream input, String downloadName) throws Exception {
   DownloadService dservice = WCMCoreUtils.getService(DownloadService.class);
   InputStreamDownloadResource dresource = new InputStreamDownloadResource(input, "image");
   dresource.setDownloadName(downloadName);
   return dservice.getDownloadLink(dservice.addDownloadResource(dresource));
 }