Skip to content

Commit

Permalink
improve Message parser robustness and I18N for Message bodies (fixes …
Browse files Browse the repository at this point in the history
…SMACK-207 and SMACK-307)

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11824 b35dd754-fafc-0310-a699-88a17e54d16e
  • Loading branch information
henning authored and rtreffer committed Aug 25, 2010
1 parent 38b1acc commit d3d25f3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
35 changes: 19 additions & 16 deletions source/org/jivesoftware/smack/packet/Message.java
Expand Up @@ -598,24 +598,27 @@ public String getMessage() {
return message;
}

public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) { return false; }

Body otherBody = (Body) o;
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + this.language.hashCode();
result = prime * result + this.message.hashCode();
return result;
}

if (language != null ? !language.equals(otherBody.language) : otherBody.language != null) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
return message.equals(otherBody.message);

}

public int hashCode() {
int result;
result = message.hashCode();
result = 31 * result + (language != null ? language.hashCode() : 0);
return result;
if (getClass() != obj.getClass()) {
return false;
}
Body other = (Body) obj;
// simplified comparison because language and message are always set
return this.language.equals(other.language) && this.message.equals(other.message);
}

}
Expand Down Expand Up @@ -660,4 +663,4 @@ public static Type fromString(String name) {
}

}
}
}
8 changes: 6 additions & 2 deletions source/org/jivesoftware/smack/packet/Packet.java
Expand Up @@ -439,11 +439,15 @@ public String getXmlns() {
return this.xmlns;
}

/**
* Returns the default language used for all messages containing localized content.
*
* @return the default language
*/
public static String getDefaultLanguage() {
return DEFAULT_LANGUAGE;
}


public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Expand Down Expand Up @@ -475,4 +479,4 @@ public int hashCode() {
result = 31 * result + (error != null ? error.hashCode() : 0);
return result;
}
}
}
2 changes: 1 addition & 1 deletion source/org/jivesoftware/smack/util/PacketParserUtils.java
Expand Up @@ -153,7 +153,7 @@ else if (eventType == XmlPullParser.END_TAG) {
/**
* Returns the content of a tag as string regardless of any tags included.
*
* @param parser the xml-pull-parser
* @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
Expand Down
Expand Up @@ -11,6 +11,11 @@
import static org.custommonkey.xmlunit.XMLAssert.*;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;

import java.io.IOException;
import java.io.StringReader;
import java.util.Locale;
import java.util.Properties;

import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
import org.jivesoftware.smack.packet.Message;
Expand Down Expand Up @@ -454,6 +459,7 @@ private String determineNonDefaultLanguage() {
for (int i = 0; i < availableLocales.length; i++) {
if (availableLocales[i] != Locale.getDefault()) {
otherLanguage = availableLocales[i].getLanguage().toLowerCase();
break;
}
}
return otherLanguage;
Expand Down

0 comments on commit d3d25f3

Please sign in to comment.