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

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

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

StringEscapeUtils.escapeXml介绍

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

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

Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.

Note that Unicode characters greater than 0x7f are as of 3.0, no longer escaped. If you still wish this functionality, you can achieve it via the following: StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );
[中]使用XML实体转义字符串中的字符。
例如:“面包”和“黄油”=>“面包”和“黄油”。
仅支持五个基本XML实体(gt、lt、QUOTE、amp、apos)。不支持DTD或外部实体。
请注意,从3.0开始,大于0x7f的Unicode字符不再转义。如果您仍希望实现此功能,可以通过以下方式实现:StringEscapeUtils。ESCAPE_XML。使用(NumericEntityEscaper.between(0x7f,Integer.MAX_VALUE));

代码示例

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

@Override
  public String getFormattedMessage(String message) {
    return new StringBuilder()
        .append("<access-denied>\n")
        .append("  <message>").append(StringEscapeUtils.escapeXml(message)).append("</message>\n")
        .append("</access-denied>\n")
        .toString();
  }
}

代码示例来源:origin: galenframework/galen

private void writeAttributes(StringWriter sw) {
  for(Pair<String, String> attribute : getAttributes()){
    sw.append(' ');
    sw.append(attribute.getLeft());
    sw.append('=');
    sw.append('"');
    sw.append(StringEscapeUtils.escapeXml(attribute.getRight()));
    sw.append('"');
  }
}
public List<Pair<String, String>> getAttributes() {

代码示例来源:origin: galenframework/galen

public void toXml(String indentation, StringWriter sw) {
  if (type == XmlNodeType.TEXT) {
    sw.append(StringEscapeUtils.escapeXml(name));
  }
  else if (type == XmlNodeType.TEXT_UNESCAPED) {
    sw.append(name);
  }
  else {
    if (parent != null) {
      sw.append("\n");
    }
    sw.append(indentation);
    sw.append("<");
    sw.append(name);
    writeAttributes(sw);
    sw.append(">");
    
    writeChildren(indentation + INDENTATION, sw);
    
    if (childNodes != null && childNodes.size() > 0 && !containsOnlyText()) {
      sw.append("\n");
      sw.append(indentation);
    }
    
    sw.append("</");
    sw.append(name);
    sw.append(">");
  }
}

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

/**
 * Tests https://issues.apache.org/jira/browse/LANG-720
 */
@Test
public void testLang720() {
  final String input = "\ud842\udfb7" + "A";
  final String escaped = StringEscapeUtils.escapeXml(input);
  assertEquals(input, escaped);
}

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

for (TableDescriptor htDesc : tables) { 
  out.write("\n    <tr>\n      <td>\n        <a href=\"/table.jsp?name=");
  out.print( escapeXml(htDesc.getTableName().getNameAsString()) );
  out.write('"');
  out.write('>');
  out.print( escapeXml(
     htDesc.getTableName().getNameAsString()) );
  out.write("\n        </a></td>\n      <td>");

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

@Test
public void testEscapeXml() throws Exception {
  assertEquals("&lt;abc&gt;", StringEscapeUtils.escapeXml("<abc>"));
  assertEquals("<abc>", StringEscapeUtils.unescapeXml("&lt;abc&gt;"));
      "\u00A1", StringEscapeUtils.escapeXml("\u00A1"));
  assertEquals("XML should be able to unescape >0x7f values",
      "\u00A0", StringEscapeUtils.unescapeXml("&#160;"));
  assertEquals("ain&apos;t", StringEscapeUtils.escapeXml("ain't"));
  assertEquals("", StringEscapeUtils.escapeXml(""));
  assertNull(StringEscapeUtils.escapeXml(null));
  assertNull(StringEscapeUtils.unescapeXml(null));

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

out.print( regionStateNode.getProcedure().getProcId() );
out.write("</td>\n                <td>");
out.print( escapeXml(regionStateNode.getProcedure().getState().toString() + (regionStateNode.getProcedure().isBypass() ? "(Bypassed)" : "")) );
out.write("</td>\n            </tr>\n            ");

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

@Test
public void testEscapeSurrogatePairs() throws Exception {
  assertEquals("\uD83D\uDE30", StringEscapeUtils.escapeCsv("\uD83D\uDE30"));
  // Examples from https://en.wikipedia.org/wiki/UTF-16
  assertEquals("\uD800\uDC00", StringEscapeUtils.escapeCsv("\uD800\uDC00"));
  assertEquals("\uD834\uDD1E", StringEscapeUtils.escapeCsv("\uD834\uDD1E"));
  assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeCsv("\uDBFF\uDFFD"));
  assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeHtml3("\uDBFF\uDFFD"));
  assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeHtml4("\uDBFF\uDFFD"));
  assertEquals("\uDBFF\uDFFD", StringEscapeUtils.escapeXml("\uDBFF\uDFFD"));
}

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

out.print( escapeXml(meta.getRegionNameAsString()) );
out.write("</td>\n    <td><a href=\"http://");
out.print( hostAndPort );
out.print( locality);
out.write("</td>\n    <td>");
out.print( escapeXml(Bytes.toString(meta.getStartKey())) );
out.write("</td>\n    <td>");
out.print( escapeXml(Bytes.toString(meta.getEndKey())) );
out.write("</td>\n");
out.print( escapeXml(Bytes.toStringBinary(regionInfo.getRegionName())) );
out.write("</td>\n  ");
out.print( locality);
out.write("</td>\n  <td>");
out.print( escapeXml(Bytes.toStringBinary(regionInfo.getStartKey())));
out.write("</td>\n  <td>");
out.print( escapeXml(Bytes.toStringBinary(regionInfo.getEndKey())));
out.write("</td>\n  <td>");
out.print( state);

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

out.print( proc.hasParent() ? proc.getParentProcId() : "" );
out.write("</td>\n        <td>");
out.print( escapeXml(proc.getState().toString() + (proc.isBypass() ? "(Bypass)" : "")) );
out.write("</td>\n        <td>");
out.print( proc.hasOwner() ? escapeXml(proc.getOwner()) : "" );
out.write("</td>\n        <td>");
out.print( escapeXml(proc.getProcName()) );
out.write("</td>\n        <td>");
out.print( new Date(proc.getSubmittedTime()) );
out.print( new Date(proc.getLastUpdate()) );
out.write("</td>\n        <td>");
out.print( escapeXml(proc.isFailed() ? proc.getException().unwrapRemoteIOException().getMessage() : "") );
out.write("</td>\n        <td>");
out.print( escapeXml(ProcedureDescriber.describeParameters(proc)) );
out.write("</td>\n      </tr>\n    ");
out.print( new Date(pwf.getTimestamp()) );
out.write(" </td>\n              <td> ");
out.print( escapeXml(pwf.toString()) );
out.write(" </td>\n            </tr>\n            ");
out.print( new Date(cwf.getTimestamp()) );
out.write(" </td>\n            <td> ");
out.print( escapeXml(cwf.toString()) );
out.write(" </td>\n          </tr>\n          ");
out.print( escapeXml(ProcedureDescriber.describe(lockedResource.getExclusiveLockOwnerProcedure())) );
out.write("</p>\n    ");

代码示例来源:origin: com.quhaodian/user_hibernate

/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
  return StringEscapeUtils.escapeXml(xml);
}

代码示例来源:origin: wangxinforme/sc

/**
 * Xml 转码.
 */
@SuppressWarnings("deprecation")
public static String escapeXml(String xml) {
  return StringEscapeUtils.escapeXml(xml);
}

代码示例来源:origin: com.quhaodian.discover/discover-user

/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
 return StringEscapeUtils.escapeXml(xml);
}

代码示例来源:origin: org.eclipse.dirigible/dirigible-api-facade-utils

/**
 * Escape XML.
 *
 * @param input
 *            the input
 * @return the escaped input
 */
public static final String escapeXml(String input) {
  return StringEscapeUtils.escapeXml(input);
}

代码示例来源:origin: xautlx/s2jh4net

/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
  return StringEscapeUtils.escapeXml(xml);
}

代码示例来源:origin: XiaoMi/shepher

public static String generateSummary(String content) {
  String summary = StringEscapeUtils.escapeXml(content);
  summary = StringUtils.substring(summary, 0, 50);
  return summary;
}

代码示例来源:origin: denimgroup/threadfix

private static void appendSurfaceLocation(StringBuilder builder, String urlString, String parameterString) {
  if (urlString != null || !parameterString.trim().equals("")) {
    builder.append("\n\t\t\t<SurfaceLocation url=\"").append(escapeXml(urlString)).append("\"");
    if (!"".equals(parameterString)) {
      builder.append(" source=\"Parameter\" value=\"").append(escapeXml(parameterString)).append("\"");
    }
    builder.append("/>");
  }
}

代码示例来源:origin: org.osgi/org.amdatu.remote.discovery.bonjour

private static void appendMultiValues(Writer writer, Collection<?> value) throws IOException {
  for (Iterator<?> it = value.iterator(); it.hasNext();) {
    writer.append("         <value>").append(escapeXml(it.next().toString())).append("</value>").append("\n");
  }
}

代码示例来源:origin: com.galenframework/galen-core

private void writeAttributes(StringWriter sw) {
  for(Pair<String, String> attribute : getAttributes()){
    sw.append(' ');
    sw.append(attribute.getLeft());
    sw.append('=');
    sw.append('"');
    sw.append(StringEscapeUtils.escapeXml(attribute.getRight()));
    sw.append('"');
  }
}
public List<Pair<String, String>> getAttributes() {

代码示例来源:origin: com.lyncode/jtwig-functions

@JtwigFunction(name = "escape", aliases = {"e"})
public String escape (@Parameter String input, @Parameter String strategy) throws FunctionException {
  switch (EscapeStrategy.strategyByName(strategy.toLowerCase())) {
    case JAVASCRIPT:
      return StringEscapeUtils.escapeEcmaScript(input);
    case XML:
      return StringEscapeUtils.escapeXml(input);
    case HTML: // Default html
    default:
      return StringEscapeUtils.escapeHtml4(input);
  }
}

相关文章