1 20 21 package org.jivesoftware.smackx.provider; 22 23 import org.jivesoftware.smack.packet.PacketExtension; 24 import org.jivesoftware.smack.provider.PacketExtensionProvider; 25 import org.jivesoftware.smackx.packet.XHTMLExtension; 26 import org.xmlpull.v1.XmlPullParser; 27 28 33 public class XHTMLExtensionProvider implements PacketExtensionProvider { 34 35 39 public XHTMLExtensionProvider() { 40 } 41 42 49 public PacketExtension parseExtension(XmlPullParser parser) 50 throws Exception { 51 XHTMLExtension xhtmlExtension = new XHTMLExtension(); 52 boolean done = false; 53 StringBuffer buffer = new StringBuffer ();; 54 while (!done) { 55 int eventType = parser.next(); 56 if (eventType == XmlPullParser.START_TAG) { 57 if (parser.getName().equals("body")) 58 buffer = new StringBuffer (); 59 buffer.append(parser.getText()); 60 } else if (eventType == XmlPullParser.TEXT) { 61 if (buffer != null) buffer.append(parser.getText()); 62 } else if (eventType == XmlPullParser.END_TAG) { 63 if (parser.getName().equals("body")) { 64 buffer.append(parser.getText()); 65 xhtmlExtension.addBody(buffer.toString()); 66 } 67 else if (parser.getName().equals(xhtmlExtension.getElementName())) { 68 done = true; 69 } 70 else 71 buffer.append(parser.getText()); 72 } 73 } 74 75 return xhtmlExtension; 76 } 77 78 } 79 | Popular Tags |