anotherim/src/main/java/eu/siacs/conversations/utils/XmlHelper.java

31 lines
847 B
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.utils;
import eu.siacs.conversations.xml.Element;
2014-10-22 16:38:44 +00:00
public class XmlHelper {
public static String encodeEntities(String content) {
content = content.replace("&", "&");
content = content.replace("<", "&lt;");
content = content.replace(">", "&gt;");
content = content.replace("\"", "&quot;");
content = content.replace("'", "&apos;");
content = content.replaceAll("[\\p{Cntrl}&&[^\n\t\r]]", "");
2014-10-22 16:38:44 +00:00
return content;
}
public static String printElementNames(final Element element) {
final StringBuilder builder = new StringBuilder();
builder.append('[');
if (element != null) {
for (Element child : element.getChildren()) {
if (builder.length() != 1) {
builder.append(',');
}
builder.append(child.getName());
}
}
builder.append(']');
return builder.toString();
}
2014-10-22 16:38:44 +00:00
}