Search in sources :

Example 1 with Direction

use of org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction in project Smack by igniterealtime.

the class CarbonManagerProvider method parse.

@Override
public CarbonExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException, ParseException {
    Direction dir = Direction.valueOf(parser.getName());
    Forwarded<Message> fwd = null;
    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getName().equals("forwarded")) {
            fwd = ForwardedProvider.parseForwardedMessage(parser, xmlEnvironment);
        } else if (eventType == XmlPullParser.Event.END_ELEMENT && dir == Direction.valueOf(parser.getName()))
            done = true;
    }
    if (fwd == null) {
        throw new SmackParsingException("sent/received must contain exactly one <forwarded/> element");
    }
    return new CarbonExtension(dir, fwd);
}
Also used : Message(org.jivesoftware.smack.packet.Message) CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Direction(org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction) SmackParsingException(org.jivesoftware.smack.parsing.SmackParsingException)

Example 2 with Direction

use of org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction in project Smack by igniterealtime.

the class CarbonManagerProvider method parse.

@Override
public CarbonExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
    Direction dir = Direction.valueOf(parser.getName());
    Forwarded fwd = null;
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) {
            fwd = FORWARDED_PROVIDER.parse(parser);
        } else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName()))
            done = true;
    }
    if (fwd == null)
        throw new SmackException("sent/received must contain exactly one <forwarded> tag");
    return new CarbonExtension(dir, fwd);
}
Also used : CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) SmackException(org.jivesoftware.smack.SmackException) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) Direction(org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction)

Aggregations

CarbonExtension (org.jivesoftware.smackx.carbons.packet.CarbonExtension)2 Direction (org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction)2 SmackException (org.jivesoftware.smack.SmackException)1 Message (org.jivesoftware.smack.packet.Message)1 SmackParsingException (org.jivesoftware.smack.parsing.SmackParsingException)1 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)1