use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class Avatar method parseMetadata.
public static Avatar parseMetadata(Element items) {
Element item = items.findChild("item");
if (item == null) {
return null;
}
Element metadata = item.findChild("metadata");
if (metadata == null) {
return null;
}
String primaryId = item.getAttribute("id");
if (primaryId == null) {
return null;
}
for (Element child : metadata.getChildren()) {
if (child.getName().equals("info") && primaryId.equals(child.getAttribute("id"))) {
Avatar avatar = new Avatar();
String height = child.getAttribute("height");
String width = child.getAttribute("width");
String size = child.getAttribute("bytes");
try {
if (height != null) {
avatar.height = Integer.parseInt(height);
}
if (width != null) {
avatar.width = Integer.parseInt(width);
}
if (size != null) {
avatar.size = Long.parseLong(size);
}
} catch (NumberFormatException e) {
return null;
}
avatar.type = child.getAttribute("type");
String hash = child.getAttribute("id");
if (!isValidSHA1(hash)) {
return null;
}
avatar.sha1sum = hash;
avatar.origin = Origin.PEP;
return avatar;
}
}
return null;
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class MessagePacket method setBody.
public void setBody(String text) {
this.children.remove(findChild("body"));
Element body = new Element("body");
body.setContent(text);
this.children.add(0, body);
}
use of eu.siacs.conversations.xml.Element in project Conversations by siacs.
the class JingleConnectionManager method deliverIbbPacket.
public void deliverIbbPacket(Account account, IqPacket packet) {
String sid = null;
Element payload = null;
if (packet.hasChild("open", "http://jabber.org/protocol/ibb")) {
payload = packet.findChild("open", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid");
} else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
payload = packet.findChild("data", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid");
} else if (packet.hasChild("close", "http://jabber.org/protocol/ibb")) {
payload = packet.findChild("close", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid");
}
if (sid != null) {
for (JingleConnection connection : connections) {
if (connection.getAccount() == account && connection.hasTransportId(sid)) {
JingleTransport transport = connection.getTransport();
if (transport instanceof JingleInbandTransport) {
JingleInbandTransport inbandTransport = (JingleInbandTransport) transport;
inbandTransport.deliverPayload(packet, payload);
return;
}
}
}
Log.d(Config.LOGTAG, "couldn't deliver payload: " + payload.toString());
} else {
Log.d(Config.LOGTAG, "no sid found in incoming ibb packet");
}
}
Aggregations