本文整理了Java中org.apache.commons.lang3.StringEscapeUtils.escapeXml11()
方法的一些代码示例,展示了StringEscapeUtils.escapeXml11()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.escapeXml11()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringEscapeUtils
类名称:StringEscapeUtils
方法名:escapeXml11
[英]Escapes the characters in a String using XML entities.
For example: "bread" & "butter" => "bread" & "butter".
XML 1.1 can represent certain control characters, but it cannot represent the null byte or unpaired Unicode surrogate codepoints, even after escaping. escapeXml11 will remove characters that do not fit in the following ranges:
[#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
escapeXml11 will escape characters in the following ranges:
[#x1-#x8] | [#xB-#xC] | [#xE-#x1F] | [#x7F-#x84] | [#x86-#x9F]
The returned string can be inserted into a valid XML 1.1 document. Do not use it for XML 1.0 documents.
[中]使用XML实体转义字符串中的字符。
例如:“面包”和“黄油”=>“面包”和“黄油”。
XML 1.1可以表示某些控制字符,但即使在转义之后,它也不能表示空字节或未配对的Unicode代理代码点。escapeXml11将删除不符合以下范围的字符:
[#x1-#xD7FF]|[#xE000-#xffd]|[#x10000-#x10FFFF]
escapeXml11将转义以下范围内的字符:
[#x1-#x8]|[#xB-#xC]|[#xE-#x1F]|[#x7F-#x84]|[#x86-#x9F]
返回的字符串可以插入到有效的XML 1.1文档中。不要将其用于XML 1.0文档。
代码示例来源:origin: springside/springside4
/**
* Xml转码,将字符串转码为符合XML1.1格式的字符串.
*
* 比如 "bread" & "butter" 转化为 "bread" & "butter"
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml11(xml);
}
代码示例来源:origin: gocd/gocd
private void generateAPIResponse() {
try {
HttpServletRequest httpRequest = request;
if (requestIsOfType(JSON, httpRequest)) {
response.setContentType("application/json");
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("message", jsonMessage);
response.getWriter().print(jsonObject);
} else if (requestIsOfType(XML, httpRequest)) {
response.setContentType("application/xml");
String xml = String.format("<message>%s</message>", StringEscapeUtils.escapeXml11(jsonMessage));
response.getWriter().print(xml);
} else {
generateHTMLResponse();
}
} catch (IOException e) {
LOGGER.error("General IOException: {}", e.getMessage());
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testEscapeXml11() throws Exception {
assertEquals("a<b>c"d'e&f", StringEscapeUtils.escapeXml11("a<b>c\"d'e&f"));
assertEquals("XML 1.1 should not escape \t \n \r",
"a\tb\rc\nd", StringEscapeUtils.escapeXml11("a\tb\rc\nd"));
assertEquals("XML 1.1 should omit #x0",
"ab", StringEscapeUtils.escapeXml11("a\u0000b"));
assertEquals("XML 1.1 should escape #x1-x8 | #xb | #xc | #xe-#x19",
"ab", StringEscapeUtils.escapeXml11("a\u0001\u0008\u000b\u000c\u000e\u001fb"));
assertEquals("XML 1.1 should escape #x7F-#x84 | #x86-#x9F",
"a\u007e„\u0085†Ÿ\u00a0b", StringEscapeUtils.escapeXml11("a\u007e\u007f\u0084\u0085\u0086\u009f\u00a0b"));
assertEquals("XML 1.1 should omit #xd800-#xdfff",
"a\ud7ff \ue000b", StringEscapeUtils.escapeXml11("a\ud7ff\ud800 \udfff \ue000b"));
assertEquals("XML 1.1 should omit #xfffe | #xffff",
"a\ufffdb", StringEscapeUtils.escapeXml11("a\ufffd\ufffe\uffffb"));
}
代码示例来源:origin: lcw2004/one
/**
* Xml 转码.
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml11(xml);
}
代码示例来源:origin: DarLiner/vjtools
/**
* Xml转码,将字符串转码为符合XML1.1格式的字符串.
*
* 比如 "bread" & "butter" 转化为 "bread" & "butter"
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml11(xml);
}
代码示例来源:origin: io.springside/springside-utils
/**
* Xml转码,将字符串转码为符合XML1.1格式的字符串.
*
* 比如 "bread" & "butter" 转化为 "bread" & "butter"
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml11(xml);
}
代码示例来源:origin: xuminwlt/j360-dubbo-app-all
/**
* Xml转码,将字符串转码为符合XML1.1格式的字符串.
*
* 比如 "bread" & "butter" 转化为 "bread" & "butter"
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml11(xml);
}
代码示例来源:origin: org.bonitasoft.platform/platform-setup
static String escapeXmlCharacters(String url) {
return StringEscapeUtils.escapeXml11(url);
}
代码示例来源:origin: bonitasoft/bonita-engine
static String escapeXmlCharacters(String url) {
return StringEscapeUtils.escapeXml11(url);
}
代码示例来源:origin: org.visallo/visallo-core
private static String escapeParts(String prefix, String selection, String suffix) {
StringBuilder str = new StringBuilder();
str.append(StringEscapeUtils.escapeXml11(prefix));
str.append("<span class=\"selection\">");
str.append(StringEscapeUtils.escapeXml11(selection));
str.append("</span>");
str.append(StringEscapeUtils.escapeXml11(suffix));
return str.toString();
}
}
代码示例来源:origin: org.visallo/visallo-core
private static void writeBuffer(List<OffsetItem> started, List<OffsetItem> all, OutputStreamWriter out, char[] buffer, int offset, int len) throws IOException {
String strBuffer = new String(buffer, offset, len);
out.write(StringEscapeUtils.escapeXml11(strBuffer));
}
代码示例来源:origin: fr.ifremer/isis-fish
/**
* {@inheritDoc}
*/
@Override
public void visit(Domain domain, Object label, Object value) {
String content = (String)value;
xmlBuffer.append("<level>");
xmlBuffer.append(StringEscapeUtils.escapeXml11(content));
xmlBuffer.append("</level>");
}
}
代码示例来源:origin: se.ugli.durian/durian-java-dom
private static void appendAttribute(final StringBuilder xml, final String attributeName,
final String attributeValue) {
if (attributeValue != null)
xml.append(SPACE).append(attributeName).append(EQ).append(QUOTE).append(escapeXml11(attributeValue))
.append(QUOTE);
}
代码示例来源:origin: gentics/mesh
private String escapeSafe(String text) {
return StringEscapeUtils.escapeJava(StringEscapeUtils.escapeXml11(new File(text).getAbsolutePath()));
}
代码示例来源:origin: Silverpeas/Silverpeas-Core
public static String escapeXml(String javastring) {
if (isDefined(javastring)) {
return StringEscapeUtils.escapeXml11(javastring);
} else {
return "";
}
}
代码示例来源:origin: org.apache.cxf.fediz/fediz-idp-core
public String serialize(RequestContext context, Element rpToken) {
if (rpToken != null) {
StringWriter sw = new StringWriter();
try {
TransformerFactory tf = TransformerFactory.newInstance();
tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.transform(new DOMSource(rpToken), new StreamResult(sw));
} catch (TransformerException te) {
LOG.warn("nodeToString Transformer Exception");
}
String serializedToken = sw.toString();
return org.apache.commons.lang3.StringEscapeUtils.escapeXml11(serializedToken);
}
return null;
}
}
代码示例来源:origin: Cognifide/aet
public static String escapeUrls(String xmlString) {
Matcher matcher = URL_TAG_PATTERN.matcher(xmlString);
StringBuffer urlTagStringBuffer = new StringBuffer();
while (matcher.find()) {
String attrs = matcher.group(3);
Matcher attrMatcher = ATTRIBUTES_PATTERN.matcher(attrs);
StringBuffer attrsStringBuffer = new StringBuffer();
while (attrMatcher.find()) {
String attr = attrMatcher.group(1);
if (attr.startsWith("description=")) {
validateAttr(attr);
}
if (attr.startsWith("href=")) {
attr = String.format("href=\"%s\"",
StringEscapeUtils.escapeXml11(attr.substring(6, attr.length() - 1)));
}
attrMatcher.appendReplacement(attrsStringBuffer, attr + " ");
}
attrMatcher.appendTail(attrsStringBuffer);
String urlString = String.format("<url %s/>", attrsStringBuffer.toString());
matcher.appendReplacement(urlTagStringBuffer, urlString);
}
matcher.appendTail(urlTagStringBuffer);
return urlTagStringBuffer.toString();
}
代码示例来源:origin: se.ugli.durian/durian-java-dom
private void appendContent(final Collection<Content> contentList, final int indentDepth) {
for (final Content content : contentList)
if (content instanceof Element)
appendElement(content.as(Element.class), indentDepth + 1);
else if (content instanceof Text) {
final String textValue = content.as(Text.class).value();
if (contentList.size() > 1) {
xml.append(lineSeparator);
appendStringWithTab(indentDepth + 1, escapeXml11(textValue));
} else
xml.append(escapeXml11(textValue));
} else
throw new IllegalStateException(content.getClass().getName());
}
代码示例来源:origin: org.apache.uima/ruta-core
public void writeNode(Writer writer, TextNode node) throws IOException {
String value = StringEscapeUtils.escapeXml11(String.valueOf(node.getValue()));
String output = "<node char=\"" + value + "\" isWordEnd=\""
+ Boolean.toString(node.isWordEnd()) + "\">";
writer.write(output);
for (TextNode child : node.getChildren().values()) {
writeNode(writer, child);
}
writer.write("</node>");
}
代码示例来源:origin: Cornutum/tcases
/**
* Writes an attribute definition.
*/
protected void writeAttribute( String name, String value)
{
print( " ");
print( name);
print( "=\"");
// StringEscapeUtils escapes symbols ', < >, &, ", and some control characters
// NumericEntityEscaper translates additional control characters \n, \t, ...
print( NumericEntityEscaper.below(0x20).translate(StringEscapeUtils.escapeXml11(value)));
print( "\"");
}
内容来源于网络,如有侵权,请联系作者删除!