KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > provider > XHTMLExtensionProvider


1 /**
2  * $RCSfile$
3  * $Revision: 2407 $
4  * $Date: 2004-11-02 20:37:00 -0300 (Tue, 02 Nov 2004) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

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 /**
29  * The XHTMLExtensionProvider parses XHTML packets.
30  *
31  * @author Gaston Dombiak
32  */

33 public class XHTMLExtensionProvider implements PacketExtensionProvider {
34
35     /**
36      * Creates a new XHTMLExtensionProvider.
37      * ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
38      */

39     public XHTMLExtensionProvider() {
40     }
41
42     /**
43      * Parses a XHTMLExtension packet (extension sub-packet).
44      *
45      * @param parser the XML parser, positioned at the starting element of the extension.
46      * @return a PacketExtension.
47      * @throws Exception if a parsing error occurs.
48      */

49     public PacketExtension parseExtension(XmlPullParser parser)
50         throws Exception JavaDoc {
51         XHTMLExtension xhtmlExtension = new XHTMLExtension();
52         boolean done = false;
53         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();;
54         while (!done) {
55             int eventType = parser.next();
56             if (eventType == XmlPullParser.START_TAG) {
57                 if (parser.getName().equals("body"))
58                     buffer = new StringBuffer JavaDoc();
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