mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
improve Message parser robustness and I18N for Message bodies (fixes SMACK-207 and SMACK-307)
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11824 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
7e01c66374
commit
cb5310c984
4 changed files with 538 additions and 88 deletions
|
@ -68,8 +68,15 @@ public class PacketParserUtils {
|
|||
message.setFrom(parser.getAttributeValue("", "from"));
|
||||
message.setType(Message.Type.fromString(parser.getAttributeValue("", "type")));
|
||||
String language = getLanguageAttribute(parser);
|
||||
|
||||
// determine message's default language
|
||||
String defaultLanguage = null;
|
||||
if (language != null && !"".equals(language.trim())) {
|
||||
message.setLanguage(language);
|
||||
message.setLanguage(language);
|
||||
defaultLanguage = language;
|
||||
}
|
||||
else {
|
||||
defaultLanguage = Packet.getDefaultLanguage();
|
||||
}
|
||||
|
||||
// Parse sub-elements. We include extra logic to make sure the values
|
||||
|
@ -77,7 +84,6 @@ public class PacketParserUtils {
|
|||
// in arbitrary sub-elements.
|
||||
boolean done = false;
|
||||
String subject = null;
|
||||
String body;
|
||||
String thread = null;
|
||||
Map<String, Object> properties = null;
|
||||
while (!done) {
|
||||
|
@ -92,8 +98,15 @@ public class PacketParserUtils {
|
|||
}
|
||||
else if (elementName.equals("body")) {
|
||||
String xmlLang = getLanguageAttribute(parser);
|
||||
body = parser.nextText();
|
||||
message.addBody(xmlLang, body);
|
||||
if (xmlLang == null) {
|
||||
xmlLang = defaultLanguage;
|
||||
}
|
||||
|
||||
String body = parseContent(parser);
|
||||
|
||||
if (message.getBody(xmlLang) == null) {
|
||||
message.addBody(xmlLang, body);
|
||||
}
|
||||
}
|
||||
else if (elementName.equals("thread")) {
|
||||
if (thread == null) {
|
||||
|
@ -131,6 +144,25 @@ public class PacketParserUtils {
|
|||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of a tag as string regardless of any tags included.
|
||||
*
|
||||
* @param parser the XML pull parser
|
||||
* @return the content of a tag as string
|
||||
* @throws XmlPullParserException if parser encounters invalid XML
|
||||
* @throws IOException if an IO error occurs
|
||||
*/
|
||||
private static String parseContent(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException {
|
||||
String content = "";
|
||||
int parserDepth = parser.getDepth();
|
||||
while (!(parser.next() == XmlPullParser.END_TAG && parser
|
||||
.getDepth() == parserDepth)) {
|
||||
content += parser.getText();
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a presence packet.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue