Java Code Examples for org.apache.commons.lang3.StringEscapeUtils#escapeXml10()

The following examples show how to use org.apache.commons.lang3.StringEscapeUtils#escapeXml10() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SplitXml.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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(">");
    }
}
 
Example 2
Source File: StringEL.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: Encodes.java    From erp-framework with MIT License 4 votes vote down vote up
/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml10(xml);
}
 
Example 4
Source File: EncodeUtils.java    From frpMgr with MIT License 4 votes vote down vote up
/**
 * Xml 转码.
 */
public static String encodeXml(String xml) {
	return StringEscapeUtils.escapeXml10(xml);
}
 
Example 5
Source File: Encodes.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml10(xml);
}
 
Example 6
Source File: Encodes.java    From mysiteforme with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml10(xml);
}
 
Example 7
Source File: Encodes.java    From easyweb with Apache License 2.0 4 votes vote down vote up
/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml10(xml);
}
 
Example 8
Source File: Encodes.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
/**
 * Xml 转码.
 */
public static String escapeXml(String xml) {
	return StringEscapeUtils.escapeXml10(xml);
}
 
Example 9
Source File: XmlTestResultTest.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public String escapeOrNot(String s) {
    if (s.startsWith("<")) {
        return StringEscapeUtils.escapeXml10(s);
    }
    return s;
}
 
Example 10
Source File: StringUtil.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static String protectForXML(String s) {
	if ("".equals(s)) {
		return "";
	}
	return StringEscapeUtils.escapeXml10(s);
}
 
Example 11
Source File: EscapeTool.java    From velocity-tools with Apache License 2.0 3 votes vote down vote up
/**
 * <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));
}
 
Example 12
Source File: EscapeXmlReference.java    From velocity-engine with Apache License 2.0 2 votes vote down vote up
/**
 * 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());
}