Example usage for org.apache.commons.lang3 StringEscapeUtils escapeXml11

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeXml11

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeXml11.

Prototype

public static String escapeXml11(final String input) 

Source Link

Document

Escapes the characters in a String using XML entities.

For example: "bread" & "butter" => "bread" & "butter" .

Usage

From source file:password.pwm.util.java.StringUtil.java

public static String escapeXml(final String input) {
    return StringEscapeUtils.escapeXml11(input);
}

From source file:script.el.elExp.Functions.java

/**
 * Escapes characters that could be interpreted as XML markup.  For example, < will be
 * converted to <./*from   ww  w  .  j a v a2s  .  c  o  m*/
 *
 * @param   str     the string to escape
 * @return  the escaped string
 */
public static String escapeXML(String str) {
    return StringEscapeUtils.escapeXml11(str);
}

From source file:tpt.dbweb.cat.Compare.java

public void compare(List<Iterator<TaggedText>> ttIts, List<String> infos, Path out,
          List<ComparisonResult> evaluations) throws IOException {
      boolean docEvaluationNotFound = false;

      StringWriter sw = new StringWriter();
      PrintWriter ps = new PrintWriter(sw);
      ps.append("<annotators>\n");
      // load files and print annotator info
      for (int i = 0; i < ttIts.size(); i++) {
          ps.append("\t<annotator id='" + i + "' file='");
          ps.append(StringEscapeUtils.escapeXml11(infos.get(i)));
          ps.append("'/>\n");
      }/*from   w  w w.  j a v  a 2  s  .  c  o  m*/
      ps.append("</annotators>\n");

      // print evaluation
      List<Map<String, EvaluationStatistics>> evals = new ArrayList<>();
      Map<String, EvaluationStatistics> eval;
      if (evaluations != null) {
          for (int i = 0; i < evaluations.size(); i++) {
              ComparisonResult combinedEvaluations = evaluations.get(i).combine();
              eval = new TreeMap<>();
              evals.add(eval);

              // type is macro / micro
              for (String type : combinedEvaluations.docidToMetricToResult.keySet()) {
                  Map<String, EvaluationStatistics> metricToResult = combinedEvaluations.docidToMetricToResult
                          .get(type);
                  for (String metric : metricToResult.keySet()) {
                      eval.put(metric + " (" + type + ")", metricToResult.get(metric));
                  }
              }
          }
          ps.print(printMetrics(evals));
          evals.clear();
      }

      // print comparison of articles
      while (ttIts.stream().allMatch(it -> it.hasNext())) {
          List<TaggedText> tts = ttIts.stream().map(it -> it.next()).collect(Collectors.toList());
          tts.forEach(tt -> cleanUp(tt));
          if (!checkTaggedTexts(infos, tts)) {
              break;
          }

          // do comparison and write to output
          ps.print("  <article id='");
          ps.print(tts.get(0).id);
          ps.println("'>");

          ps.print(compare(tts));
          ps.println();

          // print evaluation of article
          if (evaluations != null) {
              docEvaluationNotFound = true;
              for (int i = 0; i < evaluations.size(); i++) {
                  eval = evaluations.get(i).docidToMetricToResult.get(tts.get(0).id);
                  evals.add(eval);
                  if (eval != null) {
                      docEvaluationNotFound = false;
                  }
              }
              if (docEvaluationNotFound == false) {
                  ps.print(printMetrics(evals));
              } else {
              }
          } else {
              docEvaluationNotFound = true;
          }
          if (docEvaluationNotFound) {
              log.warn("evaluation not found for {}", tts.get(0).id);
          }
          ps.println("  </article>");
      }

      if (docEvaluationNotFound && evaluations != null && evaluations.size() > 0) {
          log.warn("available evaluations: {}", evaluations.get(0).docidToMetricToResult.keySet());
      }

      // load template and replace <article/>
      String template = Utility.readResourceAsString("compare-template.xml");
      sw.toString();
      String output = template.replace("<article/>", sw.toString());
      FileUtils.writeStringToFile(out.toFile(), output);
  }

From source file:tpt.dbweb.cat.Compare.java

private void printEntityAttributes(StringBuilder builder, String attributeSuffix, ComparePair pair,
          EntityMention em, Map<String, String> entityMentionToOutput, Map<String, String> entryToShortname) {
      if (em != null) {
          String entity = StringEscapeUtils.escapeXml11(entityMentionToOutput.get(em.entity));
          builder.append(" entity" + attributeSuffix + "='" + entity + "'");
          String shortName = entryToShortname.get(em.entity);
          int length = pair.end - pair.start;
          if (shortName != null && shortName.length() > length + 5) {
              shortName = shortName.substring(0, length + 5) + "";
          }/*  w  w  w .j a  va  2s  .c  o  m*/
          builder.append(" short" + attributeSuffix + "='" + Utility.orElse(shortName, "[none]") + "'");
      } else {
          //builder.append(" entity='-'");
          builder.append(" short" + attributeSuffix + "='[none]'");
      }
  }