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.carbons.provider;
|
|
|
|
|
2019-02-05 10:41:50 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
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;
|
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-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
|
|
|
import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction;
|
2015-01-09 11:02:11 +01:00
|
|
|
import org.jivesoftware.smackx.forward.packet.Forwarded;
|
2014-10-07 21:15:20 +02:00
|
|
|
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
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
|
|
|
* carbon copied messages from a packet. It will return a {@link CarbonExtension} stanza extension.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* @author Georg Lukas
|
|
|
|
*
|
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class CarbonManagerProvider extends ExtensionElementProvider<CarbonExtension> {
|
2014-10-07 21:15:20 +02:00
|
|
|
|
|
|
|
private static final ForwardedProvider FORWARDED_PROVIDER = new ForwardedProvider();
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
2019-02-15 23:21:30 +01:00
|
|
|
public CarbonExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
|
2014-02-17 23:58:40 +01:00
|
|
|
Direction dir = Direction.valueOf(parser.getName());
|
|
|
|
Forwarded fwd = null;
|
|
|
|
|
|
|
|
boolean done = false;
|
|
|
|
while (!done) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.next();
|
|
|
|
if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getName().equals("forwarded")) {
|
2014-10-07 21:15:20 +02:00
|
|
|
fwd = FORWARDED_PROVIDER.parse(parser);
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
else if (eventType == XmlPullParser.Event.END_ELEMENT && dir == Direction.valueOf(parser.getName()))
|
2014-02-17 23:58:40 +01:00
|
|
|
done = true;
|
|
|
|
}
|
2019-02-05 10:41:50 +01:00
|
|
|
if (fwd == null) {
|
|
|
|
// TODO: Should be SmackParseException.
|
|
|
|
throw new IOException("sent/received must contain exactly one <forwarded> tag");
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
return new CarbonExtension(dir, fwd);
|
|
|
|
}
|
|
|
|
}
|