/**
  * Return the path to the document file.
  *
  * @return the path to the document file.
  */
 public String getDocumentPath() {
   if (isPhysicalPathAbsolute()) {
     return FilenameUtils.separatorsToSystem(physicalName);
   }
   String directory =
       FileRepositoryManager.getAbsolutePath(getInstanceId(), new String[] {CONTEXT});
   directory = FilenameUtils.separatorsToSystem(directory);
   if (!directory.endsWith(File.separator)) {
     directory += File.separator;
   }
   return directory + getPhysicalName();
 }
예제 #2
0
  /**
   * Method declaration
   *
   * @param req
   * @param res
   * @throws IOException
   * @throws ServletException
   * @see
   */
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    SilverTrace.info("peasUtil", "FileServer.doPost", "root.MSG_GEN_ENTER_METHOD");
    String mimeType = req.getParameter(MIME_TYPE_PARAMETER);
    String sourceFile = req.getParameter(SOURCE_FILE_PARAMETER);
    String archiveIt = req.getParameter(ARCHIVE_IT_PARAMETER);
    String dirType = req.getParameter(DIR_TYPE_PARAMETER);
    String userId = req.getParameter(USER_ID_PARAMETER);
    String componentId = req.getParameter(COMPONENT_ID_PARAMETER);
    String typeUpload = req.getParameter(TYPE_UPLOAD_PARAMETER);
    String zip = req.getParameter(ZIP_PARAMETER);
    String fileName = req.getParameter(FILE_NAME_PARAMETER);
    String tempDirectory = FileRepositoryManager.getTemporaryPath("useless", componentId);
    File tempFile = null;
    String attachmentId = req.getParameter(ATTACHMENT_ID_PARAMETER);
    String language = req.getParameter(LANGUAGE_PARAMETER);
    if (!StringUtil.isDefined(attachmentId)) {
      attachmentId = req.getParameter(VERSION_ID_PARAMETER);
    }
    SimpleDocument attachment = null;
    if (StringUtil.isDefined(attachmentId)) {
      attachment =
          AttachmentServiceFactory.getAttachmentService()
              .searchDocumentById(new SimpleDocumentPK(attachmentId, componentId), language);
      if (attachment != null) {
        mimeType = attachment.getContentType();
        sourceFile = attachment.getFilename();
      }
    }
    HttpSession session = req.getSession(true);
    MainSessionController mainSessionCtrl =
        (MainSessionController)
            session.getAttribute(MainSessionController.MAIN_SESSION_CONTROLLER_ATT);
    if ((mainSessionCtrl == null) || (!isUserAllowed(mainSessionCtrl, componentId))) {
      SilverTrace.warn(
          "peasUtil",
          "FileServer.doPost",
          "root.MSG_GEN_SESSION_TIMEOUT",
          "NewSessionId="
              + session.getId()
              + URLManager.getApplicationURL()
              + GeneralPropertiesManager.getString("sessionTimeout"));
      res.sendRedirect(
          URLManager.getApplicationURL() + GeneralPropertiesManager.getString("sessionTimeout"));
      return;
    }

    String filePath = null;
    if (typeUpload != null) {
      filePath = sourceFile;
    } else {
      if (dirType != null) {
        if (dirType.equals(GeneralPropertiesManager.getString("RepositoryTypeTemp"))) {
          filePath = FileRepositoryManager.getTemporaryPath("useless", componentId) + sourceFile;
        }
      } else if (attachment != null) {
        // the file to download is not in a temporary directory
        filePath = attachment.getAttachmentPath();
      } else {
        String directory = req.getParameter(DIRECTORY_PARAMETER);
        filePath =
            FileRepositoryManager.getAbsolutePath(componentId)
                + directory
                + File.separator
                + sourceFile;
      }
    }
    res.setContentType(mimeType);
    SilverTrace.debug("peasUtil", "FileServer.doPost()", "root.MSG_GEN_PARAM_VALUE", " zip=" + zip);
    if (zip != null) {
      res.setContentType(MimeTypes.ARCHIVE_MIME_TYPE);
      tempFile = File.createTempFile("zipfile", ".zip", new File(tempDirectory));
      SilverTrace.debug(
          "peasUtil",
          "FileServer.doPost()",
          "root.MSG_GEN_PARAM_VALUE",
          " filePath ="
              + filePath
              + " tempFile.getCanonicalPath()="
              + tempFile.getCanonicalPath()
              + " fileName="
              + fileName);
      ZipManager.compressFile(filePath, tempFile.getCanonicalPath());
      filePath = tempFile.getCanonicalPath();
    }

    // display the preview code generated by the production tools
    if (zip == null) {
      if (tempFile != null) {
        sendFile(res, tempFile.getCanonicalPath());
      } else {
        sendFile(res, filePath);
      }
    }

    if (tempFile != null) {
      SilverTrace.info(
          "peasUtil",
          "FileServer.doPost()",
          "root.MSG_GEN_ENTER_METHOD",
          " tempFile != null " + tempFile);
      FileUtils.deleteQuietly(tempFile);
    }

    if (StringUtil.isDefined(archiveIt)) {
      String nodeId = req.getParameter(NODE_ID_PARAMETER);
      String pubId = req.getParameter(PUBLICATION_ID_PARAMETER);
      ForeignPK pubPK = new ForeignPK(pubId, componentId);
      try {
        StatisticBm statisticBm =
            EJBUtilitaire.getEJBObjectRef(JNDINames.STATISTICBM_EJBHOME, StatisticBm.class);
        statisticBm.addStat(userId, pubPK, 1, "Publication");
      } catch (Exception ex) {
        SilverTrace.warn(
            "peasUtil",
            "FileServer.doPost",
            "peasUtil.CANNOT_WRITE_STATISTICS",
            "pubPK = " + pubPK + " and nodeId = " + nodeId,
            ex);
      }
    }
  }
예제 #3
0
 public String getSpaceBasePath(String spaceId) {
   return FileRepositoryManager.getAbsolutePath("Space" + spaceId, new String[] {"look"});
 }