1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 00:02:06 +01:00

Make XHTMLText use XmlStringBuidler

also define all element and attribute names as constants.
This commit is contained in:
Florian Schmaus 2014-07-05 14:19:31 +02:00
parent 8526f8ab29
commit d8d88d9abd
6 changed files with 185 additions and 206 deletions

View file

@ -47,6 +47,8 @@ import java.util.*;
*/ */
public class Message extends Packet { public class Message extends Packet {
public static final String BODY = "body";
private Type type = Type.normal; private Type type = Type.normal;
private String thread = null; private String thread = null;
private String language; private String language;
@ -440,9 +442,9 @@ public class Message extends Packet {
// Skip the default language // Skip the default language
if(body.equals(defaultBody)) if(body.equals(defaultBody))
continue; continue;
buf.halfOpenElement("body").xmllangAttribute(body.getLanguage()).rightAngelBracket(); buf.halfOpenElement(BODY).xmllangAttribute(body.getLanguage()).rightAngelBracket();
buf.escape(body.getMessage()); buf.escape(body.getMessage());
buf.closeElement("body"); buf.closeElement(BODY);
} }
buf.optElement("thread", thread); buf.optElement("thread", thread);
// Append the error subpacket if the message type is an error. // Append the error subpacket if the message type is an error.

View file

@ -185,7 +185,7 @@ public class PacketParserUtils {
message.addSubject(xmlLang, subject); message.addSubject(xmlLang, subject);
} }
} }
else if (elementName.equals("body")) { else if (elementName.equals(Message.BODY)) {
String xmlLang = getLanguageAttribute(parser); String xmlLang = getLanguageAttribute(parser);
if (xmlLang == null) { if (xmlLang == null) {
xmlLang = defaultLanguage; xmlLang = defaultLanguage;

View file

@ -37,8 +37,6 @@ import java.util.List;
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class XHTMLManager { public class XHTMLManager {
private final static String namespace = "http://jabber.org/protocol/xhtml-im";
// Enable the XHTML support on every established connection // Enable the XHTML support on every established connection
// The ServiceDiscoveryManager class should have been already initialized // The ServiceDiscoveryManager class should have been already initialized
static { static {
@ -57,7 +55,7 @@ public class XHTMLManager {
* @return an Iterator for the bodies in the message or null if none. * @return an Iterator for the bodies in the message or null if none.
*/ */
public static List<String> getBodies(Message message) { public static List<String> getBodies(Message message) {
XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension("html", namespace); XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension(XHTMLExtension.ELEMENT, XHTMLExtension.NAMESPACE);
if (xhtmlExtension != null) if (xhtmlExtension != null)
return xhtmlExtension.getBodies(); return xhtmlExtension.getBodies();
else else
@ -71,7 +69,7 @@ public class XHTMLManager {
* @param body the string to add as an XHTML body to the message * @param body the string to add as an XHTML body to the message
*/ */
public static void addBody(Message message, String body) { public static void addBody(Message message, String body) {
XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension("html", namespace); XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension(XHTMLExtension.ELEMENT, XHTMLExtension.NAMESPACE);
if (xhtmlExtension == null) { if (xhtmlExtension == null) {
// Create an XHTMLExtension and add it to the message // Create an XHTMLExtension and add it to the message
xhtmlExtension = new XHTMLExtension(); xhtmlExtension = new XHTMLExtension();
@ -88,7 +86,7 @@ public class XHTMLManager {
* @return a boolean indicating whether the message is an XHTML message * @return a boolean indicating whether the message is an XHTML message
*/ */
public static boolean isXHTMLMessage(Message message) { public static boolean isXHTMLMessage(Message message) {
return message.getExtension("html", namespace) != null; return message.getExtension(XHTMLExtension.ELEMENT, XHTMLExtension.NAMESPACE) != null;
} }
/** /**
@ -105,10 +103,10 @@ public class XHTMLManager {
return; return;
if (enabled) { if (enabled) {
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(namespace); ServiceDiscoveryManager.getInstanceFor(connection).addFeature(XHTMLExtension.NAMESPACE);
} }
else { else {
ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(namespace); ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(XHTMLExtension.NAMESPACE);
} }
} }
@ -119,7 +117,7 @@ public class XHTMLManager {
* @return a boolean indicating if the XHTML support is enabled for the given connection * @return a boolean indicating if the XHTML support is enabled for the given connection
*/ */
public static boolean isServiceEnabled(XMPPConnection connection) { public static boolean isServiceEnabled(XMPPConnection connection) {
return ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(namespace); return ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(XHTMLExtension.NAMESPACE);
} }
/** /**
@ -134,6 +132,6 @@ public class XHTMLManager {
*/ */
public static boolean isServiceEnabled(XMPPConnection connection, String userID) public static boolean isServiceEnabled(XMPPConnection connection, String userID)
throws NoResponseException, XMPPErrorException, NotConnectedException { throws NoResponseException, XMPPErrorException, NotConnectedException {
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, namespace); return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, XHTMLExtension.NAMESPACE);
} }
} }

View file

@ -17,7 +17,8 @@
package org.jivesoftware.smackx.xhtmlim; package org.jivesoftware.smackx.xhtmlim;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.XmlStringBuilder;
/** /**
* An XHTMLText represents formatted text. This class also helps to build valid * An XHTMLText represents formatted text. This class also helps to build valid
@ -27,9 +28,9 @@ import org.jivesoftware.smack.util.StringUtils;
*/ */
public class XHTMLText { public class XHTMLText {
private static final String NAMESPACE = "http://www.w3.org/1999/xhtml"; public static final String NAMESPACE = "http://www.w3.org/1999/xhtml";
private StringBuilder text = new StringBuilder(30); private final XmlStringBuilder text = new XmlStringBuilder();
/** /**
* Creates a new XHTMLText with body tag params. * Creates a new XHTMLText with body tag params.
@ -41,58 +42,53 @@ public class XHTMLText {
appendOpenBodyTag(style, lang); appendOpenBodyTag(style, lang);
} }
public static final String A = "a";
public static final String HREF = "href";
public static final String STYLE = "style";
/** /**
* Appends a tag that indicates that an anchor section begins. * Appends a tag that indicates that an anchor section begins.
* *
* @param href indicates the URL being linked to * @param href indicates the URL being linked to
* @param style the XHTML style of the anchor * @param style the XHTML style of the anchor
*/ */
public void appendOpenAnchorTag(String href, String style) { public XHTMLText appendOpenAnchorTag(String href, String style) {
StringBuilder sb = new StringBuilder("<a"); text.halfOpenElement(A);
if (href != null) { text.optAttribute(HREF, href);
sb.append(" href=\""); text.optAttribute(STYLE, style);
sb.append(href); text.rightAngelBracket();
sb.append("\""); return this;
}
if (style != null) {
sb.append(" style=\"");
sb.append(style);
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
* Appends a tag that indicates that an anchor section ends. * Appends a tag that indicates that an anchor section ends.
* *
*/ */
public void appendCloseAnchorTag() { public XHTMLText appendCloseAnchorTag() {
text.append("</a>"); text.closeElement(A);
return this;
} }
public static final String BLOCKQUOTE = "blockquote";
/** /**
* Appends a tag that indicates that a blockquote section begins. * Appends a tag that indicates that a blockquote section begins.
* *
* @param style the XHTML style of the blockquote * @param style the XHTML style of the blockquote
*/ */
public void appendOpenBlockQuoteTag(String style) { public XHTMLText appendOpenBlockQuoteTag(String style) {
StringBuilder sb = new StringBuilder("<blockquote"); text.halfOpenElement(BLOCKQUOTE);
if (style != null) { text.optAttribute(STYLE, style);
sb.append(" style=\""); text.rightAngelBracket();
sb.append(style); return this;
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
* Appends a tag that indicates that a blockquote section ends. * Appends a tag that indicates that a blockquote section ends.
* *
*/ */
public void appendCloseBlockQuoteTag() { public XHTMLText appendCloseBlockQuoteTag() {
text.append("</blockquote>"); text.closeElement(BLOCKQUOTE);
return this;
} }
/** /**
@ -101,114 +97,113 @@ public class XHTMLText {
* @param style the XHTML style of the body * @param style the XHTML style of the body
* @param lang the language of the body * @param lang the language of the body
*/ */
private void appendOpenBodyTag(String style, String lang) { private XHTMLText appendOpenBodyTag(String style, String lang) {
StringBuilder sb = new StringBuilder("<body xmlns=\"" + NAMESPACE + "\""); text.halfOpenElement(Message.BODY);
if (style != null) { text.xmlnsAttribute(NAMESPACE);
sb.append(" style=\""); text.optElement(STYLE, style);
sb.append(style); text.xmllangAttribute(lang);
sb.append("\""); text.rightAngelBracket();
} return this;
if (lang != null) {
sb.append(" xml:lang=\"");
sb.append(lang);
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** public XHTMLText appendCloseBodyTag() {
* Appends a tag that indicates that a body section ends. text.closeElement(Message.BODY);
* return this;
*/
private String closeBodyTag() {
return "</body>";
} }
public static final String BR = "br";
public static final String CITE = "cite";
public static final String CODE = "code";
/** /**
* Appends a tag that inserts a single carriage return. * Appends a tag that inserts a single carriage return.
* *
*/ */
public void appendBrTag() { public XHTMLText appendBrTag() {
text.append("<br/>"); text.closeElement(BR);
return this;
} }
/** /**
* Appends a tag that indicates a reference to work, such as a book, report or web site. * Appends a tag that indicates a reference to work, such as a book, report or web site.
* *
*/ */
public void appendOpenCiteTag() { public XHTMLText appendOpenCiteTag() {
text.append("<cite>"); text.openElement(CITE);
return this;
} }
/** /**
* Appends a tag that indicates text that is the code for a program. * Appends a tag that indicates text that is the code for a program.
* *
*/ */
public void appendOpenCodeTag() { public XHTMLText appendOpenCodeTag() {
text.append("<code>"); text.openElement(CODE);
return this;
} }
/** /**
* Appends a tag that indicates end of text that is the code for a program. * Appends a tag that indicates end of text that is the code for a program.
* *
*/ */
public void appendCloseCodeTag() { public XHTMLText appendCloseCodeTag() {
text.append("</code>"); text.closeElement(CODE);
return this;
} }
public static final String EM = "em";
/** /**
* Appends a tag that indicates emphasis. * Appends a tag that indicates emphasis.
* *
*/ */
public void appendOpenEmTag() { public XHTMLText appendOpenEmTag() {
text.append("<em>"); text.openElement(EM);
return this;
} }
/** /**
* Appends a tag that indicates end of emphasis. * Appends a tag that indicates end of emphasis.
* *
*/ */
public void appendCloseEmTag() { public XHTMLText appendCloseEmTag() {
text.append("</em>"); text.closeElement(EM);
return this;
} }
public static final String H = "h";
/** /**
* Appends a tag that indicates a header, a title of a section of the message. * Appends a tag that indicates a header, a title of a section of the message.
* *
* @param level the level of the Header. It should be a value between 1 and 3 * @param level the level of the Header. It must be a value between 1 and 3
* @param style the XHTML style of the blockquote * @param style the XHTML style of the blockquote
*/ */
public void appendOpenHeaderTag(int level, String style) { public XHTMLText appendOpenHeaderTag(int level, String style) {
if (level > 3 || level < 1) { if (level > 3 || level < 1) {
return; throw new IllegalArgumentException("Level must be between 1 and 3");
} }
StringBuilder sb = new StringBuilder("<h"); text.halfOpenElement(H + Integer.toString(level));
sb.append(level); text.optAttribute(STYLE, style);
if (style != null) { text.rightAngelBracket();
sb.append(" style=\""); return this;
sb.append(style);
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
* Appends a tag that indicates that a header section ends. * Appends a tag that indicates that a header section ends.
* *
* @param level the level of the Header. It should be a value between 1 and 3 * @param level the level of the Header. It must be a value between 1 and 3
*/ */
public void appendCloseHeaderTag(int level) { public XHTMLText appendCloseHeaderTag(int level) {
if (level > 3 || level < 1) { if (level > 3 || level < 1) {
return; throw new IllegalArgumentException("Level must be between 1 and 3");
} }
StringBuilder sb = new StringBuilder("</h"); text.closeElement(H + Integer.toBinaryString(level));
sb.append(level); return this;
sb.append(">");
text.append(sb.toString());
} }
public static final String IMG = "img";
/** /**
* Appends a tag that indicates an image. * Appends a tag that indicates an image.
* *
@ -218,51 +213,30 @@ public class XHTMLText {
* @param src where to get the picture * @param src where to get the picture
* @param width how wide is the picture * @param width how wide is the picture
*/ */
public void appendImageTag(String align, String alt, String height, String src, String width) { public XHTMLText appendImageTag(String align, String alt, String height, String src, String width) {
StringBuilder sb = new StringBuilder("<img"); text.halfOpenElement(IMG);
if (align != null) { text.optAttribute("align", align);
sb.append(" align=\""); text.optAttribute("alt", alt);
sb.append(align); text.optAttribute("height", height);
sb.append("\""); text.optAttribute("src", src);
} text.optAttribute("width", width);
if (alt != null) { text.rightAngelBracket();
sb.append(" alt=\""); return this;
sb.append(alt);
sb.append("\"");
}
if (height != null) {
sb.append(" height=\"");
sb.append(height);
sb.append("\"");
}
if (src != null) {
sb.append(" src=\"");
sb.append(src);
sb.append("\"");
}
if (width != null) {
sb.append(" width=\"");
sb.append(width);
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
public static final String LI = "li";
public static final String OL = "ol";
/** /**
* Appends a tag that indicates the start of a new line item within a list. * Appends a tag that indicates the start of a new line item within a list.
* *
* @param style the style of the line item * @param style the style of the line item
*/ */
public void appendLineItemTag(String style) { public XHTMLText appendLineItemTag(String style) {
StringBuilder sb = new StringBuilder("<li"); text.halfOpenElement(LI);
if (style != null) { text.optAttribute(STYLE, style);
sb.append(" style=\""); text.rightAngelBracket();
sb.append(style); return this;
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
@ -271,65 +245,59 @@ public class XHTMLText {
* *
* @param style the style of the ordered list * @param style the style of the ordered list
*/ */
public void appendOpenOrderedListTag(String style) { public XHTMLText appendOpenOrderedListTag(String style) {
StringBuilder sb = new StringBuilder("<ol"); text.halfOpenElement(OL);
if (style != null) { text.optAttribute(STYLE, style);
sb.append(" style=\""); text.rightAngelBracket();
sb.append(style); return this;
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
* Appends a tag that indicates that an ordered list section ends. * Appends a tag that indicates that an ordered list section ends.
* *
*/ */
public void appendCloseOrderedListTag() { public XHTMLText appendCloseOrderedListTag() {
text.append("</ol>"); text.closeElement(OL);
return this;
} }
public static final String UL = "ul";
/** /**
* Appends a tag that creates an unordered list. The unordered part means that the items * Appends a tag that creates an unordered list. The unordered part means that the items
* in the list are not in any particular order. * in the list are not in any particular order.
* *
* @param style the style of the unordered list * @param style the style of the unordered list
*/ */
public void appendOpenUnorderedListTag(String style) { public XHTMLText appendOpenUnorderedListTag(String style) {
StringBuilder sb = new StringBuilder("<ul"); text.halfOpenElement(UL);
if (style != null) { text.optAttribute(STYLE, style);
sb.append(" style=\""); text.rightAngelBracket();
sb.append(style); return this;
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
* Appends a tag that indicates that an unordered list section ends. * Appends a tag that indicates that an unordered list section ends.
* *
*/ */
public void appendCloseUnorderedListTag() { public XHTMLText appendCloseUnorderedListTag() {
text.append("</ul>"); text.closeElement(UL);
return this;
} }
public static final String P = "p";
/** /**
* Appends a tag that indicates the start of a new paragraph. This is usually rendered * Appends a tag that indicates the start of a new paragraph. This is usually rendered
* with two carriage returns, producing a single blank line in between the two paragraphs. * with two carriage returns, producing a single blank line in between the two paragraphs.
* *
* @param style the style of the paragraph * @param style the style of the paragraph
*/ */
public void appendOpenParagraphTag(String style) { public XHTMLText appendOpenParagraphTag(String style) {
StringBuilder sb = new StringBuilder("<p"); text.halfOpenElement(P);
if (style != null) { text.optAttribute(STYLE, style);
sb.append(" style=\""); text.rightAngelBracket();
sb.append(style); return this;
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
@ -337,72 +305,75 @@ public class XHTMLText {
* with two carriage returns, producing a single blank line in between the two paragraphs. * with two carriage returns, producing a single blank line in between the two paragraphs.
* *
*/ */
public void appendCloseParagraphTag() { public XHTMLText appendCloseParagraphTag() {
text.append("</p>"); text.closeElement(P);
return this;
} }
public static final String Q = "q";
/** /**
* Appends a tag that indicates that an inlined quote section begins. * Appends a tag that indicates that an inlined quote section begins.
* *
* @param style the style of the inlined quote * @param style the style of the inlined quote
*/ */
public void appendOpenInlinedQuoteTag(String style) { public XHTMLText appendOpenInlinedQuoteTag(String style) {
StringBuilder sb = new StringBuilder("<q"); text.halfOpenElement(Q);
if (style != null) { text.optAttribute(STYLE, style);
sb.append(" style=\""); text.rightAngelBracket();
sb.append(style); return this;
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
* Appends a tag that indicates that an inlined quote section ends. * Appends a tag that indicates that an inlined quote section ends.
* *
*/ */
public void appendCloseInlinedQuoteTag() { public XHTMLText appendCloseInlinedQuoteTag() {
text.append("</q>"); text.closeElement(Q);
return this;
} }
public static final String SPAN = "span";
/** /**
* Appends a tag that allows to set the fonts for a span of text. * Appends a tag that allows to set the fonts for a span of text.
* *
* @param style the style for a span of text * @param style the style for a span of text
*/ */
public void appendOpenSpanTag(String style) { public XHTMLText appendOpenSpanTag(String style) {
StringBuilder sb = new StringBuilder("<span"); text.halfOpenElement(SPAN);
if (style != null) { text.optAttribute(STYLE, style);
sb.append(" style=\""); text.rightAngelBracket();
sb.append(style); return this;
sb.append("\"");
}
sb.append(">");
text.append(sb.toString());
} }
/** /**
* Appends a tag that indicates that a span section ends. * Appends a tag that indicates that a span section ends.
* *
*/ */
public void appendCloseSpanTag() { public XHTMLText appendCloseSpanTag() {
text.append("</span>"); text.closeElement(SPAN);
return this;
} }
public static final String STRONG = "strong";
/** /**
* Appends a tag that indicates text which should be more forceful than surrounding text. * Appends a tag that indicates text which should be more forceful than surrounding text.
* *
*/ */
public void appendOpenStrongTag() { public XHTMLText appendOpenStrongTag() {
text.append("<strong>"); text.openElement(STRONG);
return this;
} }
/** /**
* Appends a tag that indicates that a strong section ends. * Appends a tag that indicates that a strong section ends.
* *
*/ */
public void appendCloseStrongTag() { public XHTMLText appendCloseStrongTag() {
text.append("</strong>"); text.closeElement(STRONG);
return this;
} }
/** /**
@ -410,8 +381,9 @@ public class XHTMLText {
* *
* @param textToAppend the text to append * @param textToAppend the text to append
*/ */
public void append(String textToAppend) { public XHTMLText append(String textToAppend) {
text.append(StringUtils.escapeForXML(textToAppend)); text.escape(textToAppend);
return this;
} }
/** /**
@ -422,7 +394,11 @@ public class XHTMLText {
* @return the text of the XHTMLText * @return the text of the XHTMLText
*/ */
public String toString() { public String toString() {
return text.toString().concat(closeBodyTag()); appendCloseBodyTag();
return text.toString();
} }
public XmlStringBuilder toXML() {
return text;
}
} }

View file

@ -18,6 +18,7 @@
package org.jivesoftware.smackx.xhtmlim.packet; package org.jivesoftware.smackx.xhtmlim.packet;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.XmlStringBuilder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -38,6 +39,9 @@ import java.util.List;
*/ */
public class XHTMLExtension implements PacketExtension { public class XHTMLExtension implements PacketExtension {
public static final String ELEMENT = "html";
public static final String NAMESPACE = "http://jabber.org/protocol/xhtml-im";
private List<String> bodies = new ArrayList<String>(); private List<String> bodies = new ArrayList<String>();
/** /**
@ -47,7 +51,7 @@ public class XHTMLExtension implements PacketExtension {
* @return the XML element name of the packet extension. * @return the XML element name of the packet extension.
*/ */
public String getElementName() { public String getElementName() {
return "html"; return ELEMENT;
} }
/** /**
@ -57,7 +61,7 @@ public class XHTMLExtension implements PacketExtension {
* @return the XML namespace of the packet extension. * @return the XML namespace of the packet extension.
*/ */
public String getNamespace() { public String getNamespace() {
return "http://jabber.org/protocol/xhtml-im"; return NAMESPACE;
} }
/** /**
@ -76,16 +80,16 @@ public class XHTMLExtension implements PacketExtension {
* </pre> * </pre>
* *
*/ */
public String toXML() { @Override
StringBuilder buf = new StringBuilder(); public XmlStringBuilder toXML() {
buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append( XmlStringBuilder xml = new XmlStringBuilder(this);
"\">"); xml.rightAngelBracket();
// Loop through all the bodies and append them to the string buffer // Loop through all the bodies and append them to the string buffer
for (String body : getBodies()) { for (String body : getBodies()) {
buf.append(body); xml.append(body);
} }
buf.append("</").append(getElementName()).append(">"); xml.closeElement(this);
return buf.toString(); return xml;
} }
/** /**

View file

@ -16,6 +16,7 @@
*/ */
package org.jivesoftware.smackx.xhtmlim.provider; package org.jivesoftware.smackx.xhtmlim.provider;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
@ -31,8 +32,6 @@ import java.io.IOException;
* @author Vyacheslav Blinov * @author Vyacheslav Blinov
*/ */
public class XHTMLExtensionProvider implements PacketExtensionProvider { public class XHTMLExtensionProvider implements PacketExtensionProvider {
public static final String BODY_ELEMENT = "body";
@Override @Override
public PacketExtension parseExtension(XmlPullParser parser) throws IOException, XmlPullParserException { public PacketExtension parseExtension(XmlPullParser parser) throws IOException, XmlPullParserException {
XHTMLExtension xhtmlExtension = new XHTMLExtension(); XHTMLExtension xhtmlExtension = new XHTMLExtension();
@ -47,7 +46,7 @@ public class XHTMLExtensionProvider implements PacketExtensionProvider {
int eventType = parser.next(); int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) { if (eventType == XmlPullParser.START_TAG) {
boolean appendNamespace = false; boolean appendNamespace = false;
if (BODY_ELEMENT.equals(parser.getName())) { if (Message.BODY.equals(parser.getName())) {
buffer = new StringBuilder(); buffer = new StringBuilder();
tagDepth = parser.getDepth(); tagDepth = parser.getDepth();
appendNamespace = true; appendNamespace = true;
@ -67,7 +66,7 @@ public class XHTMLExtensionProvider implements PacketExtensionProvider {
// handle self-closing tags by our own means // handle self-closing tags by our own means
appendEndTag(buffer, parser, tagStarted); appendEndTag(buffer, parser, tagStarted);
tagStarted = false; tagStarted = false;
if (BODY_ELEMENT.equals(name) && parser.getDepth() <= tagDepth) { if (Message.BODY.equals(name) && parser.getDepth() <= tagDepth) {
xhtmlExtension.addBody(buffer.toString()); xhtmlExtension.addBody(buffer.toString());
} }
} }