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

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

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

StringEscapeUtils.escapeXml11介绍

暂无

代码示例

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * XML Encodes the provided text.
 *
 * @param text the text to encode
 * @return the XML encoded text
 */
public String xml(String text) {
  if (text == null || text.isEmpty()) {
    return text;
  }
  return StringEscapeUtils.escapeXml11(text);
}

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

private void writeAttributesEntry(final Map<String, String> attributes, final TarArchiveOutputStream tout) throws IOException {
  final StringBuilder sb = new StringBuilder();
  sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE properties\n  SYSTEM \"http://java.sun.com/dtd/properties.dtd\">\n");
  sb.append("<properties>");
  for (final Map.Entry<String, String> entry : attributes.entrySet()) {
    final String escapedKey = StringEscapeUtils.escapeXml11(entry.getKey());
    final String escapedValue = StringEscapeUtils.escapeXml11(entry.getValue());
    sb.append("\n  <entry key=\"").append(escapedKey).append("\">").append(escapedValue).append("</entry>");
  }
  sb.append("</properties>");
  final byte[] metaBytes = sb.toString().getBytes(StandardCharsets.UTF_8);
  final TarArchiveEntry attribEntry = new TarArchiveEntry(FILENAME_ATTRIBUTES);
  attribEntry.setMode(tarPermissions);
  attribEntry.setSize(metaBytes.length);
  tout.putArchiveEntry(attribEntry);
  tout.write(metaBytes);
  tout.closeArchiveEntry();
}

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

@Test
public void testEscapeXml11() {
  assertEquals("a&lt;b&gt;c&quot;d&apos;e&amp;f", StringEscapeUtils.escapeXml11("a<b>c\"d'e&f"));
  assertEquals("a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd"),
      "XML 1.1 should not escape \t \n \r");
  assertEquals("ab", StringEscapeUtils.escapeXml11("a\u0000b"),
      "XML 1.1 should omit #x0");
  assertEquals("a&#1;&#8;&#11;&#12;&#14;&#31;b",
      StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb"),
      "XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19");
  assertEquals("a\u007e&#127;&#132;\u0085&#134;&#159;\u00a0b",
      StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"),
      "XML 1.1 should escape #x7F-#x84 | #x86-#x9F");
  assertEquals("a\ud7ff  \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b"),
      "XML 1.1 should omit #xd800-#xdfff");
  assertEquals("a\ufffdb", StringEscapeUtils.escapeXml11("a\ufffd\ufffe\uffffb"),
      "XML 1.1 should omit #xfffe | #xffff");
}

代码示例来源:origin: com.jwebmp.jre10/jwebmp-core

/**
 * Escape characters for text appearing as XML data, between tags.
 *
 * @param aText
 *
 * @return
 */
public static String forXML(String aText)
{
  return StringEscapeUtils.escapeXml11(aText);
}

代码示例来源:origin: pwm-project/pwm

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

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

/**
 * Escape characters for text appearing as XML data, between tags.
 *
 * @param aText
 *
 * @return
 */
public static String forXML(String aText)
{
  return StringEscapeUtils.escapeXml11(aText);
}

代码示例来源:origin: com.jwebmp.jre11/jwebmp-core

/**
 * Escape characters for text appearing as XML data, between tags.
 *
 * @param aText
 *
 * @return
 */
public static String forXML(String aText)
{
  return StringEscapeUtils.escapeXml11(aText);
}

代码示例来源:origin: dhis2/dhis2-core

/**
 * XML-escapes the given String.
 * @param object the String.
 * @return an XML-escaped representation.
 */
public String xmlEncode( String object )
{
  return StringEscapeUtils.escapeXml11( object );
}

代码示例来源:origin: org.owasp/dependency-check-core

/**
 * XML Encodes the provided text.
 *
 * @param text the text to encode
 * @return the XML encoded text
 */
public String xml(String text) {
  if (text == null || text.isEmpty()) {
    return text;
  }
  return StringEscapeUtils.escapeXml11(text);
}

代码示例来源:origin: wso2/wso2-synapse

/**
 * Escapes XML special characters
 *
 * @param msgCtx Message Context
 * @param value XML String which needs to be escaped
 * @return XML special char escaped string
 */
private String escapeXMLEnvelope(MessageContext msgCtx, String value) {
  String xmlVersion = "1.0"; //Default is set to 1.0
  try {
    xmlVersion = checkXMLVersion(msgCtx);
  } catch (IOException e) {
    log.error("Error reading message envelope", e);
  } catch (SAXException e) {
    log.error("Error parsing message envelope", e);
  } catch (ParserConfigurationException e) {
    log.error("Error building message envelope document", e);
  }
  if("1.1".equals(xmlVersion)) {
    return org.apache.commons.text.StringEscapeUtils.escapeXml11(value);
  } else {
    return org.apache.commons.text.StringEscapeUtils.escapeXml10(value);
  }
}

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

private File customAnimation(final Job job, final URI input, final Map<String, String> metadata)
    throws IOException, NotFoundException {
 logger.debug("Start customizing the animation");
 File output = new File(workspace.rootDirectory(), String.format("animate/%d/%s.%s", job.getId(),
     FilenameUtils.getBaseName(input.getPath()), FilenameUtils.getExtension(input.getPath())));
 FileUtils.forceMkdirParent(output);
 String animation;
 try {
  animation = FileUtils.readFileToString(new File(input), "UTF-8");
 } catch (IOException e) {
  // Maybe no local file?
  logger.debug("Falling back to workspace to read {}", input);
  try (InputStream in = workspace.read(input)) {
   animation = IOUtils.toString(in, "UTF-8");
  }
 }
 // replace all metadata
 for (Map.Entry<String, String> entry: metadata.entrySet()) {
  String value = StringEscapeUtils.escapeXml11(entry.getValue());
  animation = animation.replaceAll("\\{\\{" + entry.getKey() + "\\}\\}", value);
 }
 // write new animation file
 FileUtils.write(output, animation, "utf-8");
 return output;
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public static void storeMap(Element parentElement, Map<String, String> map) {
  if (map == null) {
    return;
  }
  Element mapElem = parentElement.addElement("map");
  for (Map.Entry<String, String> entry : map.entrySet()) {
    Element entryElem = mapElem.addElement("entry");
    entryElem.addAttribute("key", entry.getKey());
    Element valueElem = entryElem.addElement("value");
    if (entry.getValue() != null) {
      String value = StringEscapeUtils.escapeXml11(entry.getValue());
      valueElem.setText(value);
    }
  }
}

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

private void processCharacters( Characters event ) {
 Level level = stack.peek();
 Node node = stack.peek().node;
 if( event.isCData() ) {
  node.appendChild( document.createCDATASection( event.getData() ) );
 } else {
  node.appendChild( document.createTextNode( event.getData() ) );
 }
 if( !currentlyBuffering() ) {
  String value = event.getData();
  if( !event.isWhiteSpace() ) {
   if( level.scopeConfig == null || level.scopeConfig.getSelectors().isEmpty() ) {
    value = filterText( extractQName( node ), value, null );
   } else {
    UrlRewriteFilterPathDescriptor path = pickFirstMatchingPath( level );
    if( path instanceof UrlRewriteFilterApplyDescriptor ) {
     String rule = ((UrlRewriteFilterApplyDescriptor)path).rule();
     value = filterText( extractQName( node ), value, rule );
    }
   }
  }
  if( event.isCData() ) {
   writer.write( "<![CDATA[" );
   writer.write( value );
   writer.write( "]]>" );
  } else {
   writer.write( StringEscapeUtils.escapeXml11( value ) );
  }
 }
}

代码示例来源:origin: kermitt2/entity-fishing

processedEntities.stream().forEach(e -> {
  sbDocument.append("\t\t").append("<annotation>").append("\n");
  sbDocument.append("\t\t\t").append("<mention>").append(escapeXml11(e.getRawName())).append("</mention>").append("\n");
  sbDocument.append("\t\t\t").append("<wikiName>").append(escapeXml11(title)).append("</wikiName>").append("\n");
  sbDocument.append("\t\t\t").append("<wikidataId>").append(e.getWikidataId()).append("</wikidataId>").append("\n");
  sbDocument.append("\t\t\t").append("<wikipediaId>").append(String.valueOf(wikipediaExternalRef)).append("</wikipediaId>").append("\n");

代码示例来源:origin: com.infotel.seleniumRobot/core

protected String encodeString(String message, String format) {
  if (encoded) {
    return message;
  }
  String newMessage;
  switch (format) {
  case "xml":
    newMessage = StringEscapeUtils.escapeXml11(message);
    break;
  case "csv":
    newMessage = StringEscapeUtils.escapeCsv(message);
    break;
  case "html":
    newMessage = StringEscapeUtils.escapeHtml4(message);
    break;
  case "json":
    newMessage = StringEscapeUtils.escapeJson(message);
    break;
  default:
    throw new CustomSeleniumTestsException("only escaping of 'xml', 'html', 'csv', 'json' is allowed");
  }
  return newMessage;
}

相关文章