2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
2014-07-16 11:46:30 +02:00
|
|
|
* Copyright 2013-2014 Georg Lukas
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2019-02-05 10:41:50 +01:00
|
|
|
import java.io.IOException;
|
2015-01-09 11:02:11 +01:00
|
|
|
import java.util.logging.Logger;
|
2014-10-07 21:15:20 +02:00
|
|
|
|
2015-01-09 11:02:11 +01:00
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2015-02-05 11:17:27 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2019-02-10 19:01:47 +01:00
|
|
|
import org.jivesoftware.smack.parsing.SmackParsingException;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-06-30 13:36:49 +02:00
|
|
|
import org.jivesoftware.smackx.delay.packet.DelayInformation;
|
2015-01-09 11:02:11 +01:00
|
|
|
import org.jivesoftware.smackx.delay.provider.DelayInformationProvider;
|
|
|
|
import org.jivesoftware.smackx.forward.packet.Forwarded;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
2019-02-05 10:41:50 +01:00
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
2015-02-26 18:41:17 +01:00
|
|
|
* This class implements the {@link ExtensionElementProvider} to parse
|
2018-03-31 14:17:30 +02:00
|
|
|
* forwarded messages from a packet. It will return a {@link Forwarded} stanza extension.
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* @author Georg Lukas
|
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class ForwardedProvider extends ExtensionElementProvider<Forwarded> {
|
2014-10-07 21:15:20 +02:00
|
|
|
|
2016-07-23 15:45:45 +02:00
|
|
|
public static final ForwardedProvider INSTANCE = new ForwardedProvider();
|
|
|
|
|
2015-01-09 11:02:11 +01:00
|
|
|
private static final Logger LOGGER = Logger.getLogger(ForwardedProvider.class.getName());
|
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
2019-02-10 19:01:47 +01:00
|
|
|
public Forwarded parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackParsingException {
|
2014-06-30 13:36:49 +02:00
|
|
|
DelayInformation di = null;
|
2015-02-05 11:17:27 +01:00
|
|
|
Stanza packet = null;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-01-09 11:02:11 +01:00
|
|
|
outerloop: while (true) {
|
2014-02-17 23:58:40 +01:00
|
|
|
int eventType = parser.next();
|
2015-01-09 11:02:11 +01:00
|
|
|
switch (eventType) {
|
|
|
|
case XmlPullParser.START_TAG:
|
|
|
|
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());
|
|
|
|
} else {
|
|
|
|
LOGGER.warning("Namespace '" + namespace + "' does not match expected namespace '"
|
|
|
|
+ DelayInformation.NAMESPACE + "'");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Message.ELEMENT:
|
2014-02-17 23:58:40 +01:00
|
|
|
packet = PacketParserUtils.parseMessage(parser);
|
2015-01-09 11:02:11 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOGGER.warning("Unsupported forwarded packet type: " + name);
|
|
|
|
}
|
2015-03-23 09:27:15 +01:00
|
|
|
break;
|
2015-01-09 11:02:11 +01:00
|
|
|
case XmlPullParser.END_TAG:
|
|
|
|
if (parser.getDepth() == initialDepth) {
|
|
|
|
break outerloop;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-09 11:02:11 +01:00
|
|
|
|
2019-02-05 10:41:50 +01:00
|
|
|
if (packet == null) {
|
|
|
|
// TODO: Should be SmackParseException.
|
|
|
|
throw new IOException("forwarded extension must contain a packet");
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
return new Forwarded(di, packet);
|
|
|
|
}
|
|
|
|
}
|