use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class ParseStreamManagementTest method testParseEnabledInvariant.
@Test
public void testParseEnabledInvariant() throws XmlPullParserException, IOException {
String enabledString = new StreamManagement.Enabled("stream-id", false).toXML().toString();
XmlPullParser parser = PacketParserUtils.getParserFor(enabledString);
StreamManagement.Enabled enabled = ParseStreamManagement.enabled(parser);
assertEquals(enabledString, enabled.toXML().toString());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class Xpp3ParserTest method factoryTest.
@Test
public void factoryTest() throws XmlPullParserException, IOException {
Xpp3XmlPullParserFactory xpp3XmlPullParserFactory = new Xpp3XmlPullParserFactory();
XmlPullParser parser = xpp3XmlPullParserFactory.newXmlPullParser(new StringReader("<element/>"));
parser.next();
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class AdHocCommandDataProvider method parse.
@Override
public AdHocCommandData parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
boolean done = false;
AdHocCommandData adHocCommandData = new AdHocCommandData();
DataFormProvider dataFormProvider = new DataFormProvider();
XmlPullParser.Event eventType;
String elementName;
String namespace;
adHocCommandData.setSessionID(parser.getAttributeValue("", "sessionid"));
adHocCommandData.setNode(parser.getAttributeValue("", "node"));
// Status
String status = parser.getAttributeValue("", "status");
if (AdHocCommand.Status.executing.toString().equalsIgnoreCase(status)) {
adHocCommandData.setStatus(AdHocCommand.Status.executing);
} else if (AdHocCommand.Status.completed.toString().equalsIgnoreCase(status)) {
adHocCommandData.setStatus(AdHocCommand.Status.completed);
} else if (AdHocCommand.Status.canceled.toString().equalsIgnoreCase(status)) {
adHocCommandData.setStatus(AdHocCommand.Status.canceled);
}
// Action
String action = parser.getAttributeValue("", "action");
if (action != null) {
Action realAction = AdHocCommand.Action.valueOf(action);
if (realAction == null || realAction.equals(Action.unknown)) {
adHocCommandData.setAction(Action.unknown);
} else {
adHocCommandData.setAction(realAction);
}
}
while (!done) {
eventType = parser.next();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
elementName = parser.getName();
if (parser.getName().equals("actions")) {
String execute = parser.getAttributeValue("", "execute");
if (execute != null) {
adHocCommandData.setExecuteAction(AdHocCommand.Action.valueOf(execute));
}
} else if (parser.getName().equals("next")) {
adHocCommandData.addAction(AdHocCommand.Action.next);
} else if (parser.getName().equals("complete")) {
adHocCommandData.addAction(AdHocCommand.Action.complete);
} else if (parser.getName().equals("prev")) {
adHocCommandData.addAction(AdHocCommand.Action.prev);
} else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
adHocCommandData.setForm(dataFormProvider.parse(parser));
} else if (parser.getName().equals("note")) {
String typeString = parser.getAttributeValue("", "type");
AdHocCommandNote.Type type;
if (typeString != null) {
type = AdHocCommandNote.Type.valueOf(typeString);
} else {
// Type is optional and 'info' if not present.
type = AdHocCommandNote.Type.info;
}
String value = parser.nextText();
adHocCommandData.addNote(new AdHocCommandNote(type, value));
} else if (parser.getName().equals("error")) {
StanzaError error = PacketParserUtils.parseError(parser);
adHocCommandData.setError(error);
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals("command")) {
done = true;
}
}
}
return adHocCommandData;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class XHTMLExtensionProvider method parse.
@Override
public XHTMLExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws IOException, XmlPullParserException {
XHTMLExtension xhtmlExtension = new XHTMLExtension();
while (true) {
XmlPullParser.Event eventType = parser.getEventType();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
String name = parser.getName();
if (name.equals(Message.BODY)) {
xhtmlExtension.addBody(PacketParserUtils.parseElement(parser));
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getDepth() == initialDepth) {
return xhtmlExtension;
}
}
parser.next();
}
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class RosterExchangeProvider method parse.
/**
* Parses a RosterExchange 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 RosterExchange parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
RosterExchange rosterExchange = new RosterExchange();
boolean done = false;
RemoteRosterEntry remoteRosterEntry;
Jid jid = null;
String name = "";
ArrayList<String> groupsName = new ArrayList<>();
while (!done) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
if (parser.getName().equals("item")) {
// Reset this variable since they are optional for each item
groupsName = new ArrayList<>();
// Initialize the variables from the parsed XML
jid = ParserUtils.getJidAttribute(parser);
name = parser.getAttributeValue("", "name");
}
if (parser.getName().equals("group")) {
groupsName.add(parser.nextText());
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals("item")) {
// Create packet.
remoteRosterEntry = new RemoteRosterEntry(jid, name, groupsName.toArray(new String[groupsName.size()]));
rosterExchange.addRosterEntry(remoteRosterEntry);
}
if (parser.getName().equals("x")) {
done = true;
}
}
}
return rosterExchange;
}
Aggregations