示例#1
0
 public String getPreview(String lang) {
   String preview = getPreviews().get(I18NHelper.checkLanguage(lang));
   if (!StringUtil.isDefined(preview)) {
     Set<String> languages = I18NHelper.getAllSupportedLanguages();
     for (String language : languages) {
       preview = getPreviews().get(language);
       if (StringUtil.isDefined(preview)) {
         return preview;
       }
     }
   }
   return preview;
 }
示例#2
0
 public String getKeywords(String lang) {
   String keywords = getKeywords().get(I18NHelper.checkLanguage(lang));
   if (!StringUtil.isDefined(keywords)) {
     Set<String> languages = I18NHelper.getAllSupportedLanguages();
     for (String language : languages) {
       keywords = getKeywords().get(language);
       if (StringUtil.isDefined(keywords)) {
         return keywords;
       }
     }
   }
   return keywords;
 }
示例#3
0
 public String getTitle(String lang) {
   String title = getTitles().get(I18NHelper.checkLanguage(lang));
   if (!StringUtil.isDefined(title)) {
     Set<String> languages = I18NHelper.getAllSupportedLanguages();
     for (String language : languages) {
       title = getTitles().get(language);
       if (StringUtil.isDefined(title)) {
         return title;
       }
     }
   }
   return title;
 }
示例#4
0
 public void setPreview(String preview, String lang) {
   if (preview != null) {
     getPreviews().put(I18NHelper.checkLanguage(lang), preview);
   }
 }
示例#5
0
 public void setKeywords(String keywords, String lang) {
   if (keywords != null) {
     getKeywords().put(I18NHelper.checkLanguage(lang), keywords);
   }
 }
示例#6
0
 public void setTitle(String title, String lang) {
   if (title != null) {
     getTitles().put(I18NHelper.checkLanguage(lang), title);
   }
 }
 /**
  * Set the new FileDescription with the given path, encoding, format and language. The path must
  * not be null.
  *
  * @param path
  * @param encoding
  * @param format
  * @param lang
  */
 public FileDescription(String path, String encoding, String format, String lang) {
   this.path = path.replace('\\', File.separatorChar);
   this.encoding = encoding;
   this.format = format;
   this.lang = I18NHelper.checkLanguage(lang);
 }
示例#8
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("attachment", "DragAndDrop.doPost", "root.MSG_GEN_ENTER_METHOD");
    HttpRequest request = HttpRequest.decorate(req);
    if (!request.isContentInMultipart()) {
      res.getOutputStream().println("SUCCESS");
      return;
    }

    String userId = req.getParameter("UserId");
    try {
      request.setCharacterEncoding(CharEncoding.UTF_8);
      String componentId = request.getParameter("ComponentId");
      String id = request.getParameter("PubId");
      String lang = I18NHelper.checkLanguage(request.getParameter("lang"));
      SilverTrace.info(
          "attachment",
          "DragAndDrop.doPost",
          "root.MSG_GEN_PARAM_VALUE",
          "componentId = " + componentId + ", id = " + id + ", userId = " + userId);
      boolean bIndexIt = StringUtil.getBooleanValue(request.getParameter("IndexIt"));

      List<FileItem> items = request.getFileItems();
      for (FileItem item : items) {
        SilverTrace.info(
            "attachment",
            "DragAndDrop.doPost",
            "root.MSG_GEN_PARAM_VALUE",
            "item = " + item.getFieldName());
        SilverTrace.info(
            "attachment",
            "DragAndDrop.doPost",
            "root.MSG_GEN_PARAM_VALUE",
            "item = " + item.getName() + "; " + item.getString(CharEncoding.UTF_8));

        if (!item.isFormField()) {
          String fileName = item.getName();
          if (fileName != null) {
            String mimeType = FileUtil.getMimeType(fileName);
            SilverTrace.info(
                "attachment",
                "DragAndDrop.doPost",
                "root.MSG_GEN_PARAM_VALUE",
                "item size = " + item.getSize());
            // create AttachmentDetail Object
            SimpleDocument document =
                new SimpleDocument(
                    new SimpleDocumentPK(null, componentId),
                    id,
                    0,
                    false,
                    new SimpleAttachment(
                        fileName,
                        lang,
                        null,
                        null,
                        item.getSize(),
                        mimeType,
                        userId,
                        new Date(),
                        null));
            document.setDocumentType(determineDocumentType(request));
            File tempFile = File.createTempFile("silverpeas_", fileName);
            try {
              FileUploadUtil.saveToFile(tempFile, item);
              MetadataExtractor extractor = MetadataExtractor.getInstance();
              MetaData metadata = extractor.extractMetadata(tempFile);
              document.setSize(tempFile.length());
              document.setTitle(metadata.getTitle());
              document.setDescription(metadata.getSubject());
              document =
                  AttachmentServiceFactory.getAttachmentService()
                      .createAttachment(document, tempFile, bIndexIt);
            } finally {
              FileUtils.deleteQuietly(tempFile);
            }
            // Specific case: 3d file to convert by Actify Publisher
            ActifyDocumentProcessor.getProcessor().process(document);
          }
        }
      }
    } catch (Exception e) {
      SilverTrace.error("attachment", "DragAndDrop.doPost", "ERREUR", e);
      final StringBuilder sb = new StringBuilder("ERROR: ");
      final String errorMessage =
          SilverpeasTransverseWebErrorUtil.performAppletAlertExceptionMessage(
              e, UserDetail.getById(userId).getUserPreferences().getLanguage());
      if (StringUtil.isDefined(errorMessage)) {
        sb.append(errorMessage);
      } else {
        sb.append(e.getMessage());
      }
      res.getOutputStream().println(sb.toString());
      return;
    }
    res.getOutputStream().println("SUCCESS");
  }