aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/XmlHelper.java
blob: d990661e6d98aef181b9de1e3ae107fc481fdf5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package de.pixart.messenger.utils;

import de.pixart.messenger.xml.Element;

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]]", "");
        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();
    }
}