aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/xml
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/xml')
-rw-r--r--src/main/java/eu/siacs/conversations/xml/Element.java42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java
index 4e11ee2c..31edec52 100644
--- a/src/main/java/eu/siacs/conversations/xml/Element.java
+++ b/src/main/java/eu/siacs/conversations/xml/Element.java
@@ -5,12 +5,14 @@ import java.util.Hashtable;
import java.util.List;
import eu.siacs.conversations.utils.XmlHelper;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
public class Element {
protected String name;
- protected Hashtable<String, String> attributes = new Hashtable<String, String>();
+ protected Hashtable<String, String> attributes = new Hashtable<>();
protected String content;
- protected List<Element> children = new ArrayList<Element>();
+ protected List<Element> children = new ArrayList<>();
public Element(String name) {
this.name = name;
@@ -103,6 +105,42 @@ public class Element {
}
}
+ public Jid getJid() {
+ final String jid = this.getAttribute("jid");
+ if (jid != null && !jid.isEmpty()) {
+ try {
+ return Jid.fromString(jid);
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public Jid getTo() {
+ final String to = this.getAttribute("to");
+ if (to != null && !to.isEmpty()) {
+ try {
+ return Jid.fromString(to);
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public Jid getFrom() {
+ final String from = this.getAttribute("from");
+ if (from != null && !from.isEmpty()) {
+ try {
+ return Jid.fromString(from);
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
public Hashtable<String, String> getAttributes() {
return this.attributes;
}