mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-06-27 22:04:50 +02:00
Introducing Smack's own XmlPullParser interface which tries to stay as compatible as possible to XPP3. The interface is used to either wrap StAX's XMLStreamReader if Smack is used on Java SE, and XPP3's XmlPullParser if Smack is used on on Android. Fixes SMACK-591. Also introduce JUnit 5 and non-strict javadoc projects.
92 lines
3.6 KiB
Java
92 lines
3.6 KiB
Java
/**
|
|
*
|
|
* Copyright 2013-2014 Georg Lukas
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* 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.
|
|
*/
|
|
package org.jivesoftware.smackx.forward.provider;
|
|
|
|
import java.io.IOException;
|
|
import java.util.logging.Logger;
|
|
|
|
import org.jivesoftware.smack.packet.Message;
|
|
import org.jivesoftware.smack.packet.Stanza;
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
|
import org.jivesoftware.smack.parsing.SmackParsingException;
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
|
|
|
import org.jivesoftware.smackx.delay.packet.DelayInformation;
|
|
import org.jivesoftware.smackx.delay.provider.DelayInformationProvider;
|
|
import org.jivesoftware.smackx.forward.packet.Forwarded;
|
|
|
|
/**
|
|
* This class implements the {@link ExtensionElementProvider} to parse
|
|
* forwarded messages from a packet. It will return a {@link Forwarded} stanza extension.
|
|
*
|
|
* @author Georg Lukas
|
|
*/
|
|
public class ForwardedProvider extends ExtensionElementProvider<Forwarded> {
|
|
|
|
public static final ForwardedProvider INSTANCE = new ForwardedProvider();
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(ForwardedProvider.class.getName());
|
|
|
|
@Override
|
|
public Forwarded parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
|
|
DelayInformation di = null;
|
|
Stanza packet = null;
|
|
|
|
outerloop: while (true) {
|
|
XmlPullParser.Event eventType = parser.next();
|
|
switch (eventType) {
|
|
case START_ELEMENT:
|
|
String name = parser.getName();
|
|
String namespace = parser.getNamespace();
|
|
switch (name) {
|
|
case DelayInformation.ELEMENT:
|
|
if (DelayInformation.NAMESPACE.equals(namespace)) {
|
|
di = DelayInformationProvider.INSTANCE.parse(parser, parser.getDepth(), null);
|
|
} else {
|
|
LOGGER.warning("Namespace '" + namespace + "' does not match expected namespace '"
|
|
+ DelayInformation.NAMESPACE + "'");
|
|
}
|
|
break;
|
|
case Message.ELEMENT:
|
|
packet = PacketParserUtils.parseMessage(parser);
|
|
break;
|
|
default:
|
|
LOGGER.warning("Unsupported forwarded packet type: " + name);
|
|
}
|
|
break;
|
|
case END_ELEMENT:
|
|
if (parser.getDepth() == initialDepth) {
|
|
break outerloop;
|
|
}
|
|
break;
|
|
default:
|
|
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (packet == null) {
|
|
// TODO: Should be SmackParseException.
|
|
throw new IOException("forwarded extension must contain a packet");
|
|
}
|
|
return new Forwarded(di, packet);
|
|
}
|
|
}
|