mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 10:49:41 +02:00
Added support for multiple message bodies and language on the message. SMACK-99
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@8113 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
985bc79aca
commit
8e08a8ba4a
11 changed files with 926 additions and 42 deletions
|
@ -61,13 +61,17 @@ public class PacketParserUtils {
|
|||
message.setTo(parser.getAttributeValue("", "to"));
|
||||
message.setFrom(parser.getAttributeValue("", "from"));
|
||||
message.setType(Message.Type.fromString(parser.getAttributeValue("", "type")));
|
||||
String language = getLanguageAttribute(parser);
|
||||
if (language != null && !"".equals(language.trim())) {
|
||||
message.setLanguage(language);
|
||||
}
|
||||
|
||||
// Parse sub-elements. We include extra logic to make sure the values
|
||||
// are only read once. This is because it's possible for the names to appear
|
||||
// in arbitrary sub-elements.
|
||||
boolean done = false;
|
||||
String subject = null;
|
||||
String body = null;
|
||||
String body;
|
||||
String thread = null;
|
||||
Map<String, Object> properties = null;
|
||||
while (!done) {
|
||||
|
@ -81,9 +85,9 @@ public class PacketParserUtils {
|
|||
}
|
||||
}
|
||||
else if (elementName.equals("body")) {
|
||||
if (body == null) {
|
||||
body = parser.nextText();
|
||||
}
|
||||
String xmlLang = getLanguageAttribute(parser);
|
||||
body = parser.nextText();
|
||||
message.addBody(xmlLang, body);
|
||||
}
|
||||
else if (elementName.equals("thread")) {
|
||||
if (thread == null) {
|
||||
|
@ -111,7 +115,6 @@ public class PacketParserUtils {
|
|||
}
|
||||
}
|
||||
message.setSubject(subject);
|
||||
message.setBody(body);
|
||||
message.setThread(thread);
|
||||
// Set packet properties.
|
||||
if (properties != null) {
|
||||
|
@ -140,13 +143,18 @@ public class PacketParserUtils {
|
|||
System.err.println("Found invalid presence type " + typeString);
|
||||
}
|
||||
}
|
||||
|
||||
Presence presence = new Presence(type);
|
||||
presence.setTo(parser.getAttributeValue("", "to"));
|
||||
presence.setFrom(parser.getAttributeValue("", "from"));
|
||||
String id = parser.getAttributeValue("", "id");
|
||||
presence.setPacketID(id == null ? Packet.ID_NOT_AVAILABLE : id);
|
||||
|
||||
String language = getLanguageAttribute(parser);
|
||||
if (language != null && !"".equals(language.trim())) {
|
||||
presence.setLanguage(language);
|
||||
}
|
||||
presence.setPacketID(id == null ? Packet.ID_NOT_AVAILABLE : id);
|
||||
|
||||
// Parse sub-elements
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
|
@ -403,6 +411,18 @@ public class PacketParserUtils {
|
|||
return extension;
|
||||
}
|
||||
|
||||
private static String getLanguageAttribute(XmlPullParser parser) {
|
||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
||||
String attributeName = parser.getAttributeName(i);
|
||||
if ( "xml:lang".equals(attributeName) ||
|
||||
("lang".equals(attributeName) &&
|
||||
"xml".equals(parser.getAttributePrefix(i)))) {
|
||||
return parser.getAttributeValue(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object parseWithIntrospection(String elementName,
|
||||
Class objectClass, XmlPullParser parser) throws Exception
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue