From f15900426d4713b48eb96e0ad0b1cdda5a86becf Mon Sep 17 00:00:00 2001 From: Sam Whited Date: Thu, 6 Nov 2014 14:10:03 -0500 Subject: Update more files to use JID objects --- .../java/eu/siacs/conversations/xml/Element.java | 42 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/xml') diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java index 4e11ee2cd..31edec526 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 attributes = new Hashtable(); + protected Hashtable attributes = new Hashtable<>(); protected String content; - protected List children = new ArrayList(); + protected List 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 getAttributes() { return this.attributes; } -- cgit v1.2.3