From d222611abb64a99f78ce1289532a397849fb91c3 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Thu, 29 Mar 2018 19:15:56 +0200 Subject: introduces XmlContainerElement to ease searching for child elements and moves XmlHelper to xml package because it is only needed for xml handling --- .../de/thedevstack/conversationsplus/utils/XmlHelper.java | 12 ------------ .../java/de/thedevstack/conversationsplus/xml/Element.java | 11 ++++++++++- src/main/java/de/thedevstack/conversationsplus/xml/Tag.java | 2 -- .../conversationsplus/xml/XmlElementContainer.java | 7 +++++++ .../java/de/thedevstack/conversationsplus/xml/XmlHelper.java | 12 ++++++++++++ 5 files changed, 29 insertions(+), 15 deletions(-) delete mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/XmlHelper.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xml/XmlElementContainer.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xml/XmlHelper.java diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/XmlHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/XmlHelper.java deleted file mode 100644 index 1287f73f..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/utils/XmlHelper.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.thedevstack.conversationsplus.utils; - -public class XmlHelper { - public static String encodeEntities(String content) { - content = content.replace("&", "&"); - content = content.replace("<", "<"); - content = content.replace(">", ">"); - content = content.replace("\"", """); - content = content.replace("'", "'"); - return content; - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java index 429f98db..23836365 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java +++ b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java @@ -6,7 +6,6 @@ import java.util.List; import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; -import de.thedevstack.conversationsplus.utils.XmlHelper; import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException; import de.thedevstack.conversationsplus.xmpp.jid.Jid; @@ -75,6 +74,11 @@ public class Element { return null; } + public Element findChild(XmlElementContainer container) { + Element element = container.getXmlElement(); + return findChild(element.getName(), element.getNamespace()); + } + public String findChildContent(String name, String xmlns) { Element element = findChild(name,xmlns); return element == null ? null : element.getContent(); @@ -88,6 +92,11 @@ public class Element { return findChild(name, xmlns) != null; } + public boolean hasChild(XmlElementContainer container) { + Element element = container.getXmlElement(); + return hasChild(element.getName(), element.getNamespace()); + } + public List getChildren() { return this.children; } diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/Tag.java b/src/main/java/de/thedevstack/conversationsplus/xml/Tag.java index 84e37363..7072b56f 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xml/Tag.java +++ b/src/main/java/de/thedevstack/conversationsplus/xml/Tag.java @@ -5,8 +5,6 @@ import java.util.Iterator; import java.util.Map.Entry; import java.util.Set; -import de.thedevstack.conversationsplus.utils.XmlHelper; - public class Tag { public static final int NO = -1; public static final int START = 0; diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/XmlElementContainer.java b/src/main/java/de/thedevstack/conversationsplus/xml/XmlElementContainer.java new file mode 100644 index 00000000..543e032d --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xml/XmlElementContainer.java @@ -0,0 +1,7 @@ +package de.thedevstack.conversationsplus.xml; + +/** + */ +public interface XmlElementContainer { + Element getXmlElement(); +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/XmlHelper.java b/src/main/java/de/thedevstack/conversationsplus/xml/XmlHelper.java new file mode 100644 index 00000000..1287f73f --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xml/XmlHelper.java @@ -0,0 +1,12 @@ +package de.thedevstack.conversationsplus.utils; + +public class XmlHelper { + public static String encodeEntities(String content) { + content = content.replace("&", "&"); + content = content.replace("<", "<"); + content = content.replace(">", ">"); + content = content.replace("\"", """); + content = content.replace("'", "'"); + return content; + } +} -- cgit v1.2.3