use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class SmackTestUtil method parse.
@SuppressWarnings("unchecked")
public static <E extends Element> E parse(Reader reader, AbstractProvider<E> abstractProvider, XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
XmlPullParser parser = getParserFor(reader, parserKind);
final E element;
if (abstractProvider instanceof Provider) {
Provider<E> provider = (Provider<E>) abstractProvider;
element = provider.parse(parser);
} else if (abstractProvider instanceof IqProvider) {
IqData iqData = PacketParserUtils.parseIqData(parser);
parser.next();
ParserUtils.forwardToStartElement(parser);
IqProvider<?> iqProvider = (IqProvider<?>) abstractProvider;
element = (E) iqProvider.parse(parser, iqData);
} else {
throw new AssertionError();
}
return element;
}
use of org.jivesoftware.smack.xml.XmlPullParser 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);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class AbstractHttpOverXmppProvider method parseData.
/**
* Parses Data element if any.
*
* @param parser parser
* @return Data or null if no data
*
* @throws XmlPullParserException if an error in the XML parser occurred.
* @throws IOException if an I/O error occurred.
*/
protected AbstractHttpOverXmpp.Data parseData(XmlPullParser parser) throws XmlPullParserException, IOException {
NamedElement child = null;
boolean done = false;
AbstractHttpOverXmpp.Data data = null;
/* We are either at start of data or end of req/res */
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) {
while (!done) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
switch(parser.getName()) {
case ELEMENT_TEXT:
child = parseText(parser);
break;
case ELEMENT_BASE_64:
child = parseBase64(parser);
break;
case ELEMENT_CHUNKED_BASE_64:
child = parseChunkedBase64(parser);
break;
case ELEMENT_XML:
child = parseXml(parser);
break;
case ELEMENT_IBB:
child = parseIbb(parser);
break;
case ELEMENT_SIPUB:
// implemented yet
throw new UnsupportedOperationException("sipub is not supported yet");
case ELEMENT_JINGLE:
// implemented yet
throw new UnsupportedOperationException("jingle is not supported yet");
default:
// other elements are not allowed
throw new IllegalArgumentException("unsupported child tag: " + parser.getName());
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals(ELEMENT_DATA)) {
done = true;
}
}
}
data = new AbstractHttpOverXmpp.Data(child);
}
return data;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class JingleFileTransferProvider method parse.
@Override
public JingleFileTransfer parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException, ParseException {
ArrayList<JingleContentDescriptionChildElement> payloads = new ArrayList<>();
JingleFileTransferChild.Builder builder = JingleFileTransferChild.getBuilder();
String elementName;
while (true) {
XmlPullParser.TagEvent tag = parser.nextTag();
switch(tag) {
case START_ELEMENT:
elementName = parser.getName();
switch(elementName) {
case JingleFileTransferChild.ELEM_DATE:
builder.setDate(XmppDateTime.parseXEP0082Date(parser.nextText()));
break;
case JingleFileTransferChild.ELEM_DESC:
builder.setDescription(parser.nextText());
break;
case JingleFileTransferChild.ELEM_MEDIA_TYPE:
builder.setMediaType(parser.nextText());
break;
case JingleFileTransferChild.ELEM_NAME:
builder.setName(parser.nextText());
break;
case JingleFileTransferChild.ELEM_SIZE:
builder.setSize(Integer.parseInt(parser.nextText()));
break;
case Range.ELEMENT:
Range range = parseRangeElement(parser);
builder.setRange(range);
break;
case HashElement.ELEMENT:
HashElement hashElement = HashElementProvider.INSTANCE.parse(parser);
builder.setHash(hashElement);
break;
}
break;
case END_ELEMENT:
elementName = parser.getName();
switch(elementName) {
case JingleFileTransferChild.ELEMENT:
payloads.add(builder.build());
builder = JingleFileTransferChild.getBuilder();
break;
case JingleContentDescription.ELEMENT:
return new JingleFileTransfer(payloads);
}
break;
}
}
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class ContentElementProvider method parsePayload.
private static void parsePayload(XmlPullParser parser, XmlEnvironment outerXmlEnvironment, ContentElement.Builder builder) throws IOException, XmlPullParserException, SmackParsingException {
final int initialDepth = parser.getDepth();
while (true) {
XmlPullParser.Event tag = parser.next();
if (tag == XmlPullParser.Event.START_ELEMENT) {
String name = parser.getName();
String namespace = parser.getNamespace();
XmlElement element = PacketParserUtils.parseExtensionElement(name, namespace, parser, outerXmlEnvironment);
builder.addPayloadItem(element);
}
if (tag == XmlPullParser.Event.END_ELEMENT && parser.getDepth() == initialDepth) {
return;
}
}
}
Aggregations