use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class HttpOverXmppReqProviderTest method parseReq.
private static HttpOverXmppReq parseReq(String string) throws Exception {
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppReq);
return (HttpOverXmppReq) iq;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MamFinProviderTest method checkMamFinProvider.
@Test
public void checkMamFinProvider() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(exmapleMamFinXml);
MamFinIQ mamFinIQ = new MamFinIQProvider().parse(parser);
assertFalse(mamFinIQ.isComplete());
assertTrue(mamFinIQ.isStable());
assertNull(mamFinIQ.getQueryId());
RSMSet rsmSet = mamFinIQ.getRSMSet();
assertEquals(rsmSet.getAfter(), "09af3-cc343-b409f");
assertEquals(rsmSet.getMax(), 10);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class AMPExtensionProvider method parse.
/**
* Parses a AMPExtension stanza (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws IOException if an I/O error occurred.
* @throws XmlPullParserException if an error in the XML parser occurred.
*/
@Override
public AMPExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
final String from = parser.getAttributeValue(null, "from");
final String to = parser.getAttributeValue(null, "to");
final String statusString = parser.getAttributeValue(null, "status");
AMPExtension.Status status = null;
if (statusString != null) {
try {
status = AMPExtension.Status.valueOf(statusString);
} catch (IllegalArgumentException ex) {
LOGGER.severe("Found invalid amp status " + statusString);
}
}
AMPExtension ampExtension = new AMPExtension(from, to, status);
String perHopValue = parser.getAttributeValue(null, "per-hop");
if (perHopValue != null) {
boolean perHop = Boolean.parseBoolean(perHopValue);
ampExtension.setPerHop(perHop);
}
boolean done = false;
while (!done) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
if (parser.getName().equals(AMPExtension.Rule.ELEMENT)) {
String actionString = parser.getAttributeValue(null, AMPExtension.Action.ATTRIBUTE_NAME);
String conditionName = parser.getAttributeValue(null, AMPExtension.Condition.ATTRIBUTE_NAME);
String conditionValue = parser.getAttributeValue(null, "value");
AMPExtension.Condition condition = createCondition(conditionName, conditionValue);
AMPExtension.Action action = null;
if (actionString != null) {
try {
action = AMPExtension.Action.valueOf(actionString);
} catch (IllegalArgumentException ex) {
LOGGER.severe("Found invalid rule action value " + actionString);
}
}
if (action == null || condition == null) {
LOGGER.severe("Rule is skipped because either it's action or it's condition is invalid");
} else {
AMPExtension.Rule rule = new AMPExtension.Rule(action, condition);
ampExtension.addRule(rule);
}
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals(AMPExtension.ELEMENT)) {
done = true;
}
}
}
return ampExtension;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class Bookmarks method getConferenceStorage.
private static BookmarkedConference getConferenceStorage(XmlPullParser parser) throws XmlPullParserException, IOException {
String name = parser.getAttributeValue("", "name");
boolean autojoin = ParserUtils.getBooleanAttribute(parser, "autojoin", false);
EntityBareJid jid = ParserUtils.getBareJidAttribute(parser);
BookmarkedConference conf = new BookmarkedConference(jid);
conf.setName(name);
conf.setAutoJoin(autojoin);
// Check for nickname
boolean done = false;
while (!done) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT && "nick".equals(parser.getName())) {
String nickString = parser.nextText();
conf.setNickname(Resourcepart.from(nickString));
} else if (eventType == XmlPullParser.Event.START_ELEMENT && "password".equals(parser.getName())) {
conf.setPassword(parser.nextText());
} else if (eventType == XmlPullParser.Event.START_ELEMENT && "shared_bookmark".equals(parser.getName())) {
conf.setShared(true);
} else if (eventType == XmlPullParser.Event.END_ELEMENT && "conference".equals(parser.getName())) {
done = true;
}
}
return conf;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class BytestreamsProvider method parse.
@Override
public Bytestream parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
boolean done = false;
Bytestream toReturn = new Bytestream();
String id = parser.getAttributeValue("", "sid");
String mode = parser.getAttributeValue("", "mode");
// streamhost
Jid JID = null;
String host = null;
String port = null;
XmlPullParser.Event eventType;
String elementName;
while (!done) {
eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
elementName = parser.getName();
if (elementName.equals(Bytestream.StreamHost.ELEMENT)) {
JID = ParserUtils.getJidAttribute(parser);
host = parser.getAttributeValue("", "host");
port = parser.getAttributeValue("", "port");
} else if (elementName.equals(Bytestream.StreamHostUsed.ELEMENT)) {
toReturn.setUsedHost(ParserUtils.getJidAttribute(parser));
} else if (elementName.equals(Bytestream.Activate.ELEMENT)) {
toReturn.setToActivate(ParserUtils.getJidAttribute(parser));
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
elementName = parser.getName();
if (elementName.equals("streamhost")) {
if (port == null) {
toReturn.addStreamHost(JID, host);
} else {
toReturn.addStreamHost(JID, host, Integer.parseInt(port));
}
JID = null;
host = null;
port = null;
} else if (elementName.equals("query")) {
done = true;
}
}
}
if (mode == null) {
toReturn.setMode(Mode.tcp);
} else {
toReturn.setMode(Bytestream.Mode.fromName(mode));
}
toReturn.setSessionID(id);
return toReturn;
}
Aggregations