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;
 }
 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;
 }
 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;
 }
 SimpleDocument fillDocument(Node node, String lang) throws RepositoryException {
   SimpleDocumentPK pk =
       new SimpleDocumentPK(
           node.getIdentifier(), getStringProperty(node, SLV_PROPERTY_INSTANCEID));
   long oldSilverpeasId = getLongProperty(node, SLV_PROPERTY_OLD_ID);
   pk.setOldSilverpeasId(oldSilverpeasId);
   String language = lang;
   if (language == null) {
     language = I18NHelper.defaultLanguage;
   }
   SimpleAttachment file = getAttachment(node, language);
   if (file == null) {
     Iterator<String> iter = I18NHelper.getLanguages();
     while (iter.hasNext() && file == null) {
       file = getAttachment(node, iter.next());
     }
   }
   SimpleDocument doc =
       new SimpleDocument(
           pk,
           getStringProperty(node, SLV_PROPERTY_FOREIGN_KEY),
           getIntProperty(node, SLV_PROPERTY_ORDER),
           getBooleanProperty(node, SLV_PROPERTY_VERSIONED),
           getStringProperty(node, SLV_PROPERTY_OWNER),
           getDateProperty(node, SLV_PROPERTY_RESERVATION_DATE),
           getDateProperty(node, SLV_PROPERTY_ALERT_DATE),
           getDateProperty(node, SLV_PROPERTY_EXPIRY_DATE),
           getStringProperty(node, SLV_PROPERTY_COMMENT),
           file);
   doc.setRepositoryPath(node.getPath());
   doc.setCloneId(getStringProperty(node, SLV_PROPERTY_CLONE));
   doc.setMajorVersion(getIntProperty(node, SLV_PROPERTY_MAJOR));
   doc.setMinorVersion(getIntProperty(node, SLV_PROPERTY_MINOR));
   doc.setStatus(getStringProperty(node, SLV_PROPERTY_STATUS));
   doc.setDocumentType(DocumentType.fromFolderName(node.getParent().getName()));
   String nodeName = node.getName();
   if ("jcr:frozenNode".equals(nodeName)) {
     nodeName = doc.computeNodeName();
     doc.setNodeName(nodeName);
     if (!node.getSession().nodeExists(doc.getFullJcrPath())) {
       nodeName = SimpleDocument.VERSION_PREFIX + doc.getOldSilverpeasId();
     }
   }
   doc.setNodeName(nodeName);
   doc.setPublicDocument(!doc.isVersioned() || doc.getMinorVersion() == 0);
   // Forbidden download for roles
   String forbiddenDownloadForRoles =
       getStringProperty(node, SLV_PROPERTY_FORBIDDEN_DOWNLOAD_FOR_ROLES);
   if (StringUtil.isDefined(forbiddenDownloadForRoles)) {
     doc.addRolesForWhichDownloadIsForbidden(SilverpeasRole.listFrom(forbiddenDownloadForRoles));
   }
   return doc;
 }
 public void setPreview(String preview, String lang) {
   if (preview != null) {
     getPreviews().put(I18NHelper.checkLanguage(lang), preview);
   }
 }
 public void setKeywords(String keywords, String lang) {
   if (keywords != null) {
     getKeywords().put(I18NHelper.checkLanguage(lang), keywords);
   }
 }
 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);
 }
  /**
   * 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");
  }