2003-09-14 16:46:38 +02:00
|
|
|
/**
|
|
|
|
*
|
2021-07-06 12:33:11 +02:00
|
|
|
* Copyright 2003-2007 Jive Software, 2014-2021 Florian Schmaus
|
2003-09-14 16:46:38 +02:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:37:00 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2003-09-14 16:46:38 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2003-09-14 16:46:38 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2003-09-14 16:46:38 +02:00
|
|
|
*/
|
2014-02-15 11:35:08 +01:00
|
|
|
package org.jivesoftware.smackx.xhtmlim.provider;
|
2003-09-14 16:46:38 +02:00
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-07-05 14:19:31 +02:00
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2014-07-05 15:04:35 +02:00
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2003-09-14 16:46:38 +02:00
|
|
|
/**
|
|
|
|
* The XHTMLExtensionProvider parses XHTML packets.
|
|
|
|
*
|
2014-07-05 15:04:35 +02:00
|
|
|
* @author Florian Schmaus
|
2003-09-14 16:46:38 +02:00
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class XHTMLExtensionProvider extends ExtensionElementProvider<XHTMLExtension> {
|
2014-10-07 21:15:20 +02:00
|
|
|
|
2014-03-06 09:42:25 +01:00
|
|
|
@Override
|
2019-02-15 23:21:30 +01:00
|
|
|
public XHTMLExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws IOException, XmlPullParserException {
|
2003-09-14 16:46:38 +02:00
|
|
|
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
2014-03-06 09:42:25 +01:00
|
|
|
|
|
|
|
while (true) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.getEventType();
|
|
|
|
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
2021-07-06 12:33:11 +02:00
|
|
|
String name = parser.getName();
|
2014-07-05 15:04:35 +02:00
|
|
|
if (name.equals(Message.BODY)) {
|
|
|
|
xhtmlExtension.addBody(PacketParserUtils.parseElement(parser));
|
2006-07-10 20:15:26 +02:00
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
2014-10-07 21:15:20 +02:00
|
|
|
if (parser.getDepth() == initialDepth) {
|
2014-03-06 09:42:25 +01:00
|
|
|
return xhtmlExtension;
|
2006-07-10 20:15:26 +02:00
|
|
|
}
|
2003-09-14 16:46:38 +02:00
|
|
|
}
|
2014-07-05 15:04:35 +02:00
|
|
|
parser.next();
|
2003-09-14 16:46:38 +02:00
|
|
|
}
|
2014-03-06 09:42:25 +01:00
|
|
|
}
|
2003-09-14 16:46:38 +02:00
|
|
|
}
|