下面列出了org.apache.commons.lang3.StringEscapeUtils#escapeXml10 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes atts) throws SAXException {
// Increment the current depth because start a new XML element.
int newDepth = ++depth;
// Output the element and its attributes if it is
// not the root element.
if (newDepth > splitDepth) {
sb.append("<");
sb.append(qName);
final Set<String> attributeNames = new HashSet<>();
int attCount = atts.getLength();
for (int i = 0; i < attCount; i++) {
String attName = atts.getQName(i);
attributeNames.add(attName);
String attValue = StringEscapeUtils.escapeXml10(atts.getValue(i));
sb.append(" ").append(attName).append("=").append("\"").append(attValue).append("\"");
}
// If this is the first node we're outputting write out
// any additional namespace declarations that are required
if (splitDepth == newDepth - 1) {
for (Entry<String, String> entry : prefixMap.entrySet()) {
// If we've already added this namespace as an attribute then continue
if (attributeNames.contains(entry.getKey())) {
continue;
}
sb.append(" ");
sb.append(entry.getKey());
sb.append("=\"");
sb.append(entry.getValue());
sb.append("\"");
}
}
sb.append(">");
}
}
@ElFunction(
prefix = "str",
name = "escapeXML10",
description = "Returns a string safe to embed in an XML 1.0 or 1.1 document."
)
public static String escapeXml10(@ElParam("string") String string) {
return StringEscapeUtils.escapeXml10(string);
}
/**
* Xml 转码.
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml10(xml);
}
/**
* Xml 转码.
*/
public static String encodeXml(String xml) {
return StringEscapeUtils.escapeXml10(xml);
}
/**
* Xml 转码.
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml10(xml);
}
/**
* Xml 转码.
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml10(xml);
}
/**
* Xml 转码.
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml10(xml);
}
/**
* Xml 转码.
*/
public static String escapeXml(String xml) {
return StringEscapeUtils.escapeXml10(xml);
}
public String escapeOrNot(String s) {
if (s.startsWith("<")) {
return StringEscapeUtils.escapeXml10(s);
}
return s;
}
public static String protectForXML(String s) {
if ("".equals(s)) {
return "";
}
return StringEscapeUtils.escapeXml10(s);
}
/**
* <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));
}
/**
* 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());
}