Пример #1
0
 private void printTags(OsmEntity entity) {
   for (int i = 0; i < entity.getNumberOfTags(); i++) {
     OsmTag tag = entity.getTag(i);
     String key = tag.getKey();
     String value = tag.getValue();
     key = escaper.translate(key);
     value = escaper.translate(value);
     out.println("    <tag k=\"" + key + "\" v=\"" + value + "\"/>");
   }
 }
Пример #2
0
 private void printMetadata(OsmMetadata metadata) {
   if (metadata == null) {
     return;
   }
   out.print(" version=\"" + metadata.getVersion() + "\"");
   out.print(" timestamp=\"" + formatter.print(metadata.getTimestamp()) + "\"");
   if (metadata.getUid() >= 0) {
     out.print(" uid=\"" + metadata.getUid() + "\"");
     String user = metadata.getUser();
     if (user != null) {
       user = escaper.translate(user);
     }
     out.print(" user=\"" + user + "\"");
   }
   out.print(" changeset=\"" + metadata.getChangeset() + "\"");
 }
 public static String escapeTwitterStatusText(final CharSequence text) {
   if (text == null) return null;
   return ESCAPE_TWITTER_RAW_TEXT.translate(text);
 }
  private void processMailContent(
      PublicationDetail pubDetail,
      File file,
      ImportReportManager reportManager,
      UnitReport unitReport,
      GEDImportExport gedIE,
      boolean isVersioningUsed)
      throws ImportExportException {

    String componentId = gedIE.getCurrentComponentId();
    UserDetail userDetail = gedIE.getCurentUserDetail();
    MailExtractor extractor = null;
    Mail mail = null;
    try {
      extractor = Extractor.getExtractor(file);
      mail = extractor.getMail();
    } catch (Exception e) {
      SilverTrace.error(
          "importExport",
          "RepositoriesTypeManager.processMailContent",
          "importExport.EX_CANT_EXTRACT_MAIL_DATA",
          e);
    }
    if (mail != null) {
      // save mail data into dedicated form
      String content = mail.getBody();
      PublicationContentType pubContent = new PublicationContentType();
      XMLModelContentType modelContent = new XMLModelContentType("mail");
      pubContent.setXMLModelContentType(modelContent);
      List<XMLField> fields = new ArrayList<XMLField>();
      modelContent.setFields(fields);

      XMLField subject = new XMLField("subject", mail.getSubject());
      fields.add(subject);

      XMLField body = new XMLField("body", ESCAPE_ISO8859_1.translate(content));
      fields.add(body);

      XMLField date = new XMLField("date", DateUtil.getOutputDateAndHour(mail.getDate(), "fr"));
      fields.add(date);

      InternetAddress address = mail.getFrom();
      String from = "";
      if (StringUtil.isDefined(address.getPersonal())) {
        from += address.getPersonal() + " - ";
      }
      from += "<a href=\"mailto:" + address.getAddress() + "\">" + address.getAddress() + "</a>";
      XMLField fieldFROM = new XMLField("from", from);
      fields.add(fieldFROM);

      Address[] recipients = mail.getAllRecipients();
      String to = "";
      for (Address recipient : recipients) {
        InternetAddress ia = (InternetAddress) recipient;
        if (StringUtil.isDefined(ia.getPersonal())) {
          to += ia.getPersonal() + " - ";
        }
        to += "<a href=\"mailto:" + ia.getAddress() + "\">" + ia.getAddress() + "</a></br>";
      }
      XMLField fieldTO = new XMLField("to", to);
      fields.add(fieldTO);

      // save form
      gedIE.createPublicationContent(
          reportManager,
          unitReport,
          Integer.parseInt(pubDetail.getPK().getId()),
          pubContent,
          userDetail.getId(),
          null);

      // extract each file from mail...
      try {
        List<AttachmentDetail> documents = new ArrayList<AttachmentDetail>();

        List<MailAttachment> attachments = extractor.getAttachments();
        for (MailAttachment attachment : attachments) {
          if (attachment != null) {
            AttachmentDetail attDetail = new AttachmentDetail();
            AttachmentPK pk = new AttachmentPK("unknown", "useless", componentId);
            attDetail.setLogicalName(attachment.getName());
            attDetail.setPhysicalName(attachment.getPath());
            attDetail.setAuthor(userDetail.getId());
            attDetail.setSize(attachment.getSize());
            attDetail.setPK(pk);

            documents.add(attDetail);
          }
        }

        // ... and save it
        if (isVersioningUsed) {
          // versioning mode
          VersioningImportExport versioningIE = new VersioningImportExport(userDetail);
          versioningIE.importDocuments(
              pubDetail.getPK().getId(),
              componentId,
              documents,
              Integer.parseInt(userDetail.getId()),
              pubDetail.isIndexable());
        } else {
          // classic mode
          AttachmentImportExport attachmentIE = new AttachmentImportExport();
          attachmentIE.importAttachments(
              pubDetail.getPK().getId(),
              componentId,
              documents,
              userDetail.getId(),
              pubDetail.isIndexable());
        }
      } catch (Exception e) {
        SilverTrace.error(
            "importExport", "RepositoriesTypeManager.processMailContent", "root.EX_NO_MESSAGE", e);
      }
    }
  }
 /**
  * Unescapes a string containing XML entity escapes to a string containing the actual Unicode
  * characters corresponding to the escapes.
  *
  * <p>Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs
  * or external entities.
  *
  * <p>Note that numerical \\u Unicode codes are unescaped to their respective Unicode characters.
  * This may change in future releases.
  *
  * @param input the {@code String} to unescape, may be null
  * @return a new unescaped {@code String}, {@code null} if null string input
  * @see #escapeXml(String)
  */
 public static final String unescapeXml(final String input) {
   return UNESCAPE_XML.translate(input);
 }
 /**
  * Returns a {@code String} value for an unescaped CSV column.
  *
  * <p>If the value is enclosed in double quotes, and contains a comma, newline or double quote,
  * then quotes are removed.
  *
  * <p>Any double quote escaped characters (a pair of double quotes) are unescaped to just one
  * double quote.
  *
  * <p>If the value is not enclosed in double quotes, or is and does not contain a comma, newline
  * or double quote, then the String value is returned unchanged. see <a
  * href="http://en.wikipedia.org/wiki/Comma-separated_values">Wikipedia</a> and <a
  * href="http://tools.ietf.org/html/rfc4180">RFC 4180</a>.
  *
  * @param input the input CSV column String, may be null
  * @return the input String, with enclosing double quotes removed and embedded double quotes
  *     unescaped, {@code null} if null string input
  * @since 2.4
  */
 public static final String unescapeCsv(final String input) {
   return UNESCAPE_CSV.translate(input);
 }
 /**
  * Unescapes a string containing entity escapes to a string containing the actual Unicode
  * characters corresponding to the escapes. Supports only HTML 3.0 entities.
  *
  * @param input the {@code String} to unescape, may be null
  * @return a new unescaped {@code String}, {@code null} if null string input
  * @since 3.0
  */
 public static final String unescapeHtml3(final String input) {
   return UNESCAPE_HTML3.translate(input);
 }
 /**
  * Escapes the characters in a {@code String} using HTML entities.
  *
  * <p>For example:
  *
  * <p><code>"bread" & "butter"</code> becomes:
  *
  * <p><code>&amp;quot;bread&amp;quot; &amp;amp; &amp;quot;butter&amp;quot;</code>.
  *
  * <p>Supports all known HTML 4.0 entities, including funky accents. Note that the commonly used
  * apostrophe escape character (&amp;apos;) is not a legal entity and so is not supported).
  *
  * @param input the {@code String} to escape, may be null
  * @return a new escaped {@code String}, {@code null} if null string input
  * @see <a href="http://hotwired.lycos.com/webmonkey/reference/special_characters/">ISO
  *     Entities</a>
  * @see <a href="http://www.w3.org/TR/REC-html32#latin1">HTML 3.2 Character Entities for ISO
  *     Latin-1</a>
  * @see <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">HTML 4.0 Character entity
  *     references</a>
  * @see <a href="http://www.w3.org/TR/html401/charset.html#h-5.3">HTML 4.01 Character
  *     References</a>
  * @see <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML 4.01 Code
  *     positions</a>
  * @since 3.0
  */
 public static final String escapeHtml4(final String input) {
   return ESCAPE_HTML4.translate(input);
 }
 /**
  * Unescapes any Json literals found in the {@code String}.
  *
  * <p>For example, it will turn a sequence of {@code '\'} and {@code 'n'} into a newline
  * character, unless the {@code '\'} is preceded by another {@code '\'}.
  *
  * @see #unescapeJava(String)
  * @param input the {@code String} to unescape, may be null
  * @return A new unescaped {@code String}, {@code null} if null string input
  * @since 3.2
  */
 public static final String unescapeJson(final String input) {
   return UNESCAPE_JSON.translate(input);
 }
 /**
  * Unescapes any EcmaScript literals found in the {@code String}.
  *
  * <p>For example, it will turn a sequence of {@code '\'} and {@code 'n'} into a newline
  * character, unless the {@code '\'} is preceded by another {@code '\'}.
  *
  * @see #unescapeJava(String)
  * @param input the {@code String} to unescape, may be null
  * @return A new unescaped {@code String}, {@code null} if null string input
  * @since 3.0
  */
 public static final String unescapeEcmaScript(final String input) {
   return UNESCAPE_ECMASCRIPT.translate(input);
 }
 /**
  * Unescapes any Java literals found in the {@code String}. For example, it will turn a sequence
  * of {@code '\'} and {@code 'n'} into a newline character, unless the {@code '\'} is preceded by
  * another {@code '\'}.
  *
  * @param input the {@code String} to unescape, may be null
  * @return a new unescaped {@code String}, {@code null} if null string input
  */
 public static final String unescapeJava(final String input) {
   return UNESCAPE_JAVA.translate(input);
 }