mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-24 17:52:17 -05:00
provide helper function for getting the content of a child directly
This commit is contained in:
parent
7824c01748
commit
e32f380dae
@ -75,12 +75,7 @@ public class Bookmark extends Element implements ListItem {
|
||||
}
|
||||
|
||||
public String getNick() {
|
||||
Element nick = this.findChild("nick");
|
||||
if (nick != null) {
|
||||
return nick.getContent();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return this.findChildContent("nick");
|
||||
}
|
||||
|
||||
public void setNick(String nick) {
|
||||
@ -96,12 +91,7 @@ public class Bookmark extends Element implements ListItem {
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
Element password = this.findChild("password");
|
||||
if (password != null) {
|
||||
return password.getContent();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return this.findChildContent("password");
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
|
@ -70,10 +70,6 @@ public abstract class AbstractParser {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
Element data = item.findChild("data", "urn:xmpp:avatar:data");
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
return data.getContent();
|
||||
return item.findChildContent("data", "urn:xmpp:avatar:data");
|
||||
}
|
||||
}
|
||||
|
@ -1994,8 +1994,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||
Element vCard = packet.findChild("vCard","vcard-temp");
|
||||
Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
|
||||
Element binval = photo != null ? photo.findChild("BINVAL") : null;
|
||||
String image = binval != null ? binval.getContent() : null;
|
||||
String image = photo != null ? photo.findChildContent("BINVAL") : null;
|
||||
if (image != null) {
|
||||
avatar.image = image;
|
||||
if (getFileBackend().save(avatar)) {
|
||||
|
@ -57,6 +57,11 @@ public class Element {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String findChildContent(String name) {
|
||||
Element element = findChild(name);
|
||||
return element == null ? null : element.getContent();
|
||||
}
|
||||
|
||||
public Element findChild(String name, String xmlns) {
|
||||
for (Element child : this.children) {
|
||||
if (child.getName().equals(name)
|
||||
@ -67,6 +72,11 @@ public class Element {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String findChildContent(String name, String xmlns) {
|
||||
Element element = findChild(name,xmlns);
|
||||
return element == null ? null : element.getContent();
|
||||
}
|
||||
|
||||
public boolean hasChild(final String name) {
|
||||
return findChild(name) != null;
|
||||
}
|
||||
|
@ -83,8 +83,7 @@ public class Avatar {
|
||||
}
|
||||
|
||||
public static Avatar parsePresence(Element x) {
|
||||
Element photo = x != null ? x.findChild("photo") : null;
|
||||
String hash = photo != null ? photo.getContent() : null;
|
||||
String hash = x == null ? null : x.findChildContent("photo");
|
||||
if (hash == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -66,4 +66,27 @@ public class MessagePacket extends AbstractStanza {
|
||||
return TYPE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
public MessagePacket getForwardedMessagePacket(String name, String namespace) {
|
||||
Element wrapper = findChild(name, namespace);
|
||||
if (wrapper == null) {
|
||||
return null;
|
||||
}
|
||||
Element forwarded = wrapper.findChild("forwarded","urn:xmpp:forward:0");
|
||||
if (forwarded == null) {
|
||||
return null;
|
||||
}
|
||||
return MessagePacket.create(forwarded.findChild("message"));
|
||||
}
|
||||
|
||||
|
||||
public static MessagePacket create(Element element) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
MessagePacket packet = new MessagePacket();
|
||||
packet.setAttributes(element.getAttributes());
|
||||
packet.setChildren(element.getChildren());
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user