From e084266595855033d04950bf2fc1ea4ab244f1fe Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 15 Dec 2014 17:29:17 +0100 Subject: [PATCH] migrated more jid parsing to use getAttributeAsJid. added error logging --- .../siacs/conversations/entities/Bookmark.java | 11 +---------- .../conversations/parser/AbstractParser.java | 7 +------ .../eu/siacs/conversations/xml/Element.java | 4 ++++ .../xmpp/stanzas/AbstractStanza.java | 18 ++---------------- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 70d852fe8..209056485 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -60,16 +60,7 @@ public class Bookmark extends Element implements ListItem { @Override public Jid getJid() { - final String jid = this.getAttribute("jid"); - if (jid != null) { - try { - return Jid.fromString(jid); - } catch (final InvalidJidException e) { - return null; - } - } else { - return null; - } + return this.getAttributeAsJid("jid"); } @Override diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java index c80346b7d..39cbff4f1 100644 --- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java +++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java @@ -53,12 +53,7 @@ public abstract class AbstractParser { protected void updateLastseen(final Element packet, final Account account, final boolean presenceOverwrite) { - Jid from; - try { - from = Jid.fromString(packet.getAttribute("from")).toBareJid(); - } catch (final InvalidJidException e) { - return; - } + Jid from = packet.getAttributeAsJid("from"); String presence = from == null || from.isBareJid() ? "" : from.getResourcepart(); Contact contact = account.getRoster().getContact(from); long timestamp = getTimestamp(packet); diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java index c25b90175..9455d9e8f 100644 --- a/src/main/java/eu/siacs/conversations/xml/Element.java +++ b/src/main/java/eu/siacs/conversations/xml/Element.java @@ -1,9 +1,12 @@ package eu.siacs.conversations.xml; +import android.util.Log; + import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import eu.siacs.conversations.Config; import eu.siacs.conversations.utils.XmlHelper; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; @@ -111,6 +114,7 @@ public class Element { try { return Jid.fromString(jid); } catch (final InvalidJidException e) { + Log.e(Config.LOGTAG, "could not parse jid " + jid); return null; } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java index 9e0514729..1a49b45e3 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java +++ b/src/main/java/eu/siacs/conversations/xmpp/stanzas/AbstractStanza.java @@ -1,7 +1,6 @@ package eu.siacs.conversations.xmpp.stanzas; import eu.siacs.conversations.xml.Element; -import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; public class AbstractStanza extends Element { @@ -11,24 +10,11 @@ public class AbstractStanza extends Element { } public Jid getTo() { - try { - return Jid.fromString(getAttribute("to")); - } catch (final InvalidJidException e) { - return null; - } + return getAttributeAsJid("to"); } public Jid getFrom() { - String from = getAttribute("from"); - if (from == null) { - return null; - } else { - try { - return Jid.fromString(from); - } catch (final InvalidJidException e) { - return null; - } - } + return getAttributeAsJid("from"); } public String getId() {