migrated more jid parsing to use getAttributeAsJid. added error logging

This commit is contained in:
iNPUTmice 2014-12-15 17:29:17 +01:00
parent 25d8546ae8
commit e084266595
4 changed files with 8 additions and 32 deletions

View file

@ -60,16 +60,7 @@ public class Bookmark extends Element implements ListItem {
@Override @Override
public Jid getJid() { public Jid getJid() {
final String jid = this.getAttribute("jid"); return this.getAttributeAsJid("jid");
if (jid != null) {
try {
return Jid.fromString(jid);
} catch (final InvalidJidException e) {
return null;
}
} else {
return null;
}
} }
@Override @Override

View file

@ -53,12 +53,7 @@ public abstract class AbstractParser {
protected void updateLastseen(final Element packet, final Account account, protected void updateLastseen(final Element packet, final Account account,
final boolean presenceOverwrite) { final boolean presenceOverwrite) {
Jid from; Jid from = packet.getAttributeAsJid("from");
try {
from = Jid.fromString(packet.getAttribute("from")).toBareJid();
} catch (final InvalidJidException e) {
return;
}
String presence = from == null || from.isBareJid() ? "" : from.getResourcepart(); String presence = from == null || from.isBareJid() ? "" : from.getResourcepart();
Contact contact = account.getRoster().getContact(from); Contact contact = account.getRoster().getContact(from);
long timestamp = getTimestamp(packet); long timestamp = getTimestamp(packet);

View file

@ -1,9 +1,12 @@
package eu.siacs.conversations.xml; package eu.siacs.conversations.xml;
import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.XmlHelper; import eu.siacs.conversations.utils.XmlHelper;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
@ -111,6 +114,7 @@ public class Element {
try { try {
return Jid.fromString(jid); return Jid.fromString(jid);
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
Log.e(Config.LOGTAG, "could not parse jid " + jid);
return null; return null;
} }
} }

View file

@ -1,7 +1,6 @@
package eu.siacs.conversations.xmpp.stanzas; package eu.siacs.conversations.xmpp.stanzas;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
public class AbstractStanza extends Element { public class AbstractStanza extends Element {
@ -11,24 +10,11 @@ public class AbstractStanza extends Element {
} }
public Jid getTo() { public Jid getTo() {
try { return getAttributeAsJid("to");
return Jid.fromString(getAttribute("to"));
} catch (final InvalidJidException e) {
return null;
}
} }
public Jid getFrom() { public Jid getFrom() {
String from = getAttribute("from"); return getAttributeAsJid("from");
if (from == null) {
return null;
} else {
try {
return Jid.fromString(from);
} catch (final InvalidJidException e) {
return null;
}
}
} }
public String getId() { public String getId() {