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));
 }