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

32 lines
1 KiB
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.utils;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
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]]", "");
return content;
}
public static String printElementNames(final Element element) {
final List<String> features =
element == null
? Collections.emptyList()
: Lists.transform(
element.getChildren(),
child -> child != null ? child.getName() : null);
return Joiner.on(", ").join(features);
}
2014-10-22 16:38:44 +00:00
}