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() {
|
public String getNick() {
|
||||||
Element nick = this.findChild("nick");
|
return this.findChildContent("nick");
|
||||||
if (nick != null) {
|
|
||||||
return nick.getContent();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNick(String nick) {
|
public void setNick(String nick) {
|
||||||
@ -96,12 +91,7 @@ public class Bookmark extends Element implements ListItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
Element password = this.findChild("password");
|
return this.findChildContent("password");
|
||||||
if (password != null) {
|
|
||||||
return password.getContent();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
|
@ -70,10 +70,6 @@ public abstract class AbstractParser {
|
|||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Element data = item.findChild("data", "urn:xmpp:avatar:data");
|
return item.findChildContent("data", "urn:xmpp:avatar:data");
|
||||||
if (data == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return data.getContent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1994,8 +1994,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
Element vCard = packet.findChild("vCard","vcard-temp");
|
Element vCard = packet.findChild("vCard","vcard-temp");
|
||||||
Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
|
Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
|
||||||
Element binval = photo != null ? photo.findChild("BINVAL") : null;
|
String image = photo != null ? photo.findChildContent("BINVAL") : null;
|
||||||
String image = binval != null ? binval.getContent() : null;
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
avatar.image = image;
|
avatar.image = image;
|
||||||
if (getFileBackend().save(avatar)) {
|
if (getFileBackend().save(avatar)) {
|
||||||
|
@ -57,6 +57,11 @@ public class Element {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String findChildContent(String name) {
|
||||||
|
Element element = findChild(name);
|
||||||
|
return element == null ? null : element.getContent();
|
||||||
|
}
|
||||||
|
|
||||||
public Element findChild(String name, String xmlns) {
|
public Element findChild(String name, String xmlns) {
|
||||||
for (Element child : this.children) {
|
for (Element child : this.children) {
|
||||||
if (child.getName().equals(name)
|
if (child.getName().equals(name)
|
||||||
@ -67,6 +72,11 @@ public class Element {
|
|||||||
return null;
|
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) {
|
public boolean hasChild(final String name) {
|
||||||
return findChild(name) != null;
|
return findChild(name) != null;
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,7 @@ public class Avatar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Avatar parsePresence(Element x) {
|
public static Avatar parsePresence(Element x) {
|
||||||
Element photo = x != null ? x.findChild("photo") : null;
|
String hash = x == null ? null : x.findChildContent("photo");
|
||||||
String hash = photo != null ? photo.getContent() : null;
|
|
||||||
if (hash == null) {
|
if (hash == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -66,4 +66,27 @@ public class MessagePacket extends AbstractStanza {
|
|||||||
return TYPE_NORMAL;
|
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