org.apache.commons.lang3.StringEscapeUtils.escapeXml10()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(284)

本文整理了Java中org.apache.commons.lang3.StringEscapeUtils.escapeXml10()方法的一些代码示例,展示了StringEscapeUtils.escapeXml10()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeXml10()方法的具体详情如下:
包路径:org.apache.commons.lang3.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeXml10

StringEscapeUtils.escapeXml10介绍

[英]Escapes the characters in a String using XML entities.

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

Note that XML 1.0 is a text-only format: it cannot represent control characters or unpaired Unicode surrogate codepoints, even after escaping. escapeXml10 will remove characters that do not fit in the following ranges:

#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

Though not strictly necessary, escapeXml10 will escape characters in the following ranges:

[#x7F-#x84] | [#x86-#x9F]

The returned string can be inserted into a valid XML 1.0 or XML 1.1 document. If you want to allow more non-text characters in an XML 1.1 document, use #escapeXml11(String).
[中]

代码示例

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testEscapeXml10() throws Exception {
  assertEquals("a&lt;b&gt;c&quot;d&apos;e&amp;f", StringEscapeUtils.escapeXml10("a<b>c\"d'e&f"));
  assertEquals("XML 1.0 should not escape \t \n \r",
      "a\tb\rc\nd", StringEscapeUtils.escapeXml10("a\tb\rc\nd"));
  assertEquals("XML 1.0 should omit most #x0-x8 | #xb | #xc | #xe-#x19",
      "ab", StringEscapeUtils.escapeXml10("a\u0000\u0001\u0008\u000b\u000c\u000e\u001fb"));
  assertEquals("XML 1.0 should omit #xd800-#xdfff",
      "a\ud7ff  \ue000b", StringEscapeUtils.escapeXml10("a\ud7ff\ud800 \udfff \ue000b"));
  assertEquals("XML 1.0 should omit #xfffe | #xffff",
      "a\ufffdb", StringEscapeUtils.escapeXml10("a\ufffd\ufffe\uffffb"));
  assertEquals("XML 1.0 should escape #x7f-#x84 | #x86 - #x9f, for XML 1.1 compatibility",
      "a\u007e&#127;&#132;\u0085&#134;&#159;\u00a0b", StringEscapeUtils.escapeXml10("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"));
}

代码示例来源:origin: yusufsyaifudin/indonesia-ner

/**
 * Escaping xml text
 * @param XmlWithSpecial
 * @return
 */
public String escapeXml(String XmlWithSpecial) {
  String escapedXml = StringEscapeUtils.escapeXml10(XmlWithSpecial);
  return escapedXml;
}

代码示例来源:origin: jenkinsci/warnings-plugin

/**
   * Escapes the characters in a {@code String} using XML entities.
   *
   * @param text the text to escape
   * @return the escaped text
   * @see StringEscapeUtils#escapeXml11
   */
  protected String escapeXml(final String text) {
    return StringEscapeUtils.escapeXml10(text);
  }
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_ldap

private String getWriteValue(final Object value)
{
  if (value instanceof String) {
    // assume it's sensitive data
    return StringEscapeUtils.escapeXml10((String)value);
  }
  if (value instanceof byte[]) {
    return StringEscapeUtils.escapeXml10(new String((byte[])value, StandardCharsets.UTF_8));
  }
  return StringEscapeUtils.escapeXml10(value.toString());
}

代码示例来源:origin: com.almis.awe/awe-model

/**
 * Fixes an string value for a criteria
 *
 * @param value String value
 * @return Value fixed
 */
public static String fixHTMLValue(String value) {
 return StringEscapeUtils.escapeXml10(value).trim();
}

代码示例来源:origin: org.apache.velocity/velocity-engine-core

/**
 * Escape all XML entities.
 *
 * @param text
 * @return An escaped String.
 * @see <a href="http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/StringEscapeUtils.html#escapeXml10%28java.lang.String%29">StringEscapeUtils</a>
 */
protected String escape(Object text)
{
  return StringEscapeUtils.escapeXml10(text.toString());
}

代码示例来源:origin: pl.edu.icm.yadda/s2-browse

private String removeLangPrefixAndEscape(final String txt) {
  if (txt != null && txt.length() > 2) {
    return org.apache.commons.lang3.StringEscapeUtils.escapeXml10(txt.substring(3));
  } else {
    return txt;
  }
}

代码示例来源:origin: org.apache.velocity.tools/velocity-tools-generic

/**
 * <p>Escapes the characters in a <code>String</code> using XML entities.</p>
 * <p>Delegates the process to {@link StringEscapeUtils#escapeXml(java.lang.String)}.</p>
 *
 * @param string the string to escape, may be null
 * @return a new escaped <code>String</code>, <code>null</code> if null string input
 *
 * @see StringEscapeUtils#escapeXml(String)
 */
public String xml(Object string)
{
  if (string == null)
  {
    return null;
  }
  return StringEscapeUtils.escapeXml10(String.valueOf(string));
}

代码示例来源:origin: apache/roller

public String getTerm() {
  String query = searchRequest.getQuery();
  return (query == null)
    ? "" : StringEscapeUtils.escapeXml10(query);
}

代码示例来源:origin: MKergall/osmbonuspack

protected boolean writeKMLExtendedData(Writer writer){
  if (mExtendedData == null)
    return true;
  try {
    writer.write("<ExtendedData>\n");
    for (Map.Entry<String, String> entry : mExtendedData.entrySet()) {
      String name = entry.getKey();
      String value = entry.getValue();
      writer.write("<Data name=\""+name+"\"><value>"+StringEscapeUtils.escapeXml10(value)+"</value></Data>\n");
    }
    writer.write("</ExtendedData>\n");
    return true;
  } catch (IOException e) {
    e.printStackTrace();
    return false;
  }
}

代码示例来源:origin: tinyMediaManager/tinyMediaManager

/**
 * Sets the proxy password.
 * 
 * @param newValue
 *          the new proxy password
 */
public void setProxyPassword(String newValue) {
 newValue = StringEscapeUtils.escapeXml10(newValue);
 String oldValue = this.proxyPassword;
 this.proxyPassword = newValue;
 firePropertyChange(PROXY_PASSWORD, oldValue, newValue);
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_functions

/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler)
    throws InvalidVariableException {
  String rawString = ((CompoundVariable) values[0]).execute();
  return StringEscapeUtils.escapeXml10(rawString);
}

代码示例来源:origin: MKergall/osmbonuspack

public void writeAsKML(Writer writer){
  try {
    writer.write("<IconStyle>\n");
    super.writeAsKML(writer);
    //write the specifics:
    if (mScale != 1.0f)
      writer.write("<scale>"+mScale+"</scale>\n");
    if (mHeading != 0.0f)
      writer.write("<heading>"+mHeading+"</heading>\n");
    if (mHref != null)
      writer.write("<Icon><href>"+StringEscapeUtils.escapeXml10(mHref)+"</href></Icon>\n");
    mHotSpot.writeAsKML(writer);
    writer.write("</IconStyle>\n");
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: MKergall/osmbonuspack

/** write elements specific to GroundOverlay in KML format */
@Override public void writeKMLSpecifics(Writer writer){
  try {
    writer.write("<color>"+ColorStyle.colorAsKMLString(mColor)+"</color>\n");
    writer.write("<Icon><href>"+StringEscapeUtils.escapeXml10(mIconHref)+"</href></Icon>\n");
    writer.write("<LatLonBox>");
    GeoPoint pNW = mCoordinates.get(0);
    GeoPoint pSE = mCoordinates.get(1);
    writer.write("<north>"+pNW.getLatitude()+"</north>");
    writer.write("<south>"+pSE.getLatitude()+"</south>");
    writer.write("<east>"+pSE.getLongitude()+"</east>");
    writer.write("<west>"+pNW.getLongitude()+"</west>");
    writer.write("<rotation>"+mRotation+"</rotation>");
    writer.write("</LatLonBox>\n");
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.kie.workbench.stunner/kie-wb-common-stunner-bpmn-backend

public void setName(String value) {
  if (value == null || value.isEmpty()) {
    return;
  }
  flowElement.setName(StringEscapeUtils.escapeXml10(value.trim()));
  CustomElement.name.of(flowElement).set(value);
}

代码示例来源:origin: org.kie.workbench.stunner/kie-wb-common-stunner-bpmn-backend

public void setName(String value) {
  lane.setName(StringEscapeUtils.escapeXml10(value.trim()));
  CustomElement.name.of(lane).set(value);
}

代码示例来源:origin: org.teiid/teiid-olingo

static void writeError(ServletRequest request, TeiidProcessingException e,
    HttpServletResponse httpResponse, int statusCode) throws IOException {
  httpResponse.setStatus(statusCode);
  ContentType contentType = ContentType.parse(request.getContentType());
  PrintWriter writer = httpResponse.getWriter();
  String code = e.getCode()==null?"":e.getCode(); //$NON-NLS-1$
  String message = e.getMessage()==null?"":e.getMessage(); //$NON-NLS-1$
  if (contentType == null || contentType.isCompatible(ContentType.APPLICATION_JSON)) {
    httpResponse.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
    writer.write("{ \"error\": { \"code\": \""+StringEscapeUtils.escapeJson(code)+"\", \"message\": \""+StringEscapeUtils.escapeJson(message)+"\" } }"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  } else {
    httpResponse.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_XML.toContentTypeString()); 
    writer.write("<m:error xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:code>"+StringEscapeUtils.escapeXml10(code)+"</m:code><m:message>"+StringEscapeUtils.escapeXml10(message)+"</m:message></m:error>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  }
  writer.close();
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

@Override
public List<IToken> process(IToken token, Stack<Object> state,
    Map<String, Object> processorContext,
    IFilteringContext context) {
  List<IToken> result = new ArrayList<IToken>(1);
  if(token.getType() != TokenType.TEXT) {
    result.add(token);
    return result;
  }
  String text = StringEscapeUtils.unescapeHtml(token.getText());
  //unescaping again in order to properly handle escaped html entities in data from Baztech
  text = StringEscapeUtils.unescapeHtml(text);
  // see #9410 - old commons lang can't process UTF-16 supplementary
  // this is why commons lang 3 is used
  // TODO: fully migrate to commons lang 3???
  text = org.apache.commons.lang3.StringEscapeUtils.escapeXml10(text);
  
  result.add(new SimpleToken(text, TokenType.TEXT));
  return result;
}

代码示例来源:origin: org.kie.workbench.stunner/kie-wb-common-stunner-bpmn-backend

@Test
  public void JBPM_7523_shouldPreserveNameChars() {
    Lane lane = bpmn2.createLane();

    PropertyWriterFactory writerFactory = new PropertyWriterFactory();
    LanePropertyWriter w = writerFactory.of(lane);

    String aWeirdName = "   XXX  !!@@ <><> ";
    String aWeirdDoc = "   XXX  !!@@ <><> Docs ";
    w.setName(aWeirdName);
    w.setDocumentation(aWeirdDoc);

    assertThat(lane.getName()).isEqualTo(StringEscapeUtils.escapeXml10(aWeirdName.trim()));
    assertThat(CustomElement.name.of(lane).get()).isEqualTo(asCData(aWeirdName));
    assertThat(lane.getDocumentation().get(0).getText()).isEqualTo(asCData(aWeirdDoc));

  }
}

代码示例来源:origin: org.phenotips/patient-tools

protected String generateFormField(String[] fieldNames)
{
  if (fieldNames[NO] != null) {
    return String.format(
      "<div class='%s%s'><span class='yes-no-picker'>%s%s%s</span> <span title='%s'>%s</span></div>",
      DEFAULT_CSS_CLASS,
      this.expandable ? EXPANDABLE_CSS_CLASS : "",
      generateCheckbox("none", this.value, "", (!isSelected(YES) && !isSelected(NO)), "na", "NA"),
      generateCheckbox(fieldNames[YES], this.value, this.hint, isSelected(YES), "yes", "Y"),
      generateCheckbox(fieldNames[NO], this.value, this.hint, isSelected(NO), "no", "N"),
      this.term == null ? this.title + "\n(custom term)"
        : (this.term.getName() + (StringUtils.isNotBlank(this.term.getDescription())
          ? "\n" + StringEscapeUtils.escapeXml10(this.term.getDescription()) : "")),
      generateLabel(fieldNames[YES] + '_' + this.value, "yes-no-picker-label", this.title));
  } else {
    return generateCheckbox(fieldNames[YES], this.value, this.hint, isSelected(YES), DEFAULT_CSS_CLASS
      + (this.expandable ? EXPANDABLE_CSS_CLASS : ""), this.title);
  }
}

相关文章