2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.utils;
|
|
|
|
|
2019-02-09 19:21:29 +00:00
|
|
|
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("<", "<");
|
|
|
|
content = content.replace(">", ">");
|
|
|
|
content = content.replace("\"", """);
|
|
|
|
content = content.replace("'", "'");
|
2016-06-18 22:07:15 +00:00
|
|
|
content = content.replaceAll("[\\p{Cntrl}&&[^\n\t\r]]", "");
|
2014-10-22 16:38:44 +00:00
|
|
|
return content;
|
|
|
|
}
|
2019-02-09 19:21:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|