use of org.jivesoftware.smackx.commands.AdHocCommandNote in project ecf by eclipse.
the class AdHocCommandDataProvider method parseIQ.
public IQ parseIQ(XmlPullParser parser) throws Exception {
boolean done = false;
AdHocCommandData adHocCommandData = new AdHocCommandData();
DataFormProvider dataFormProvider = new DataFormProvider();
int 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();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG) {
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((DataForm) dataFormProvider.parseExtension(parser));
} else if (parser.getName().equals("note")) {
AdHocCommandNote.Type type = AdHocCommandNote.Type.valueOf(parser.getAttributeValue("", "type"));
String value = parser.nextText();
adHocCommandData.addNote(new AdHocCommandNote(type, value));
} else if (parser.getName().equals("error")) {
XMPPError error = PacketParserUtils.parseError(parser);
adHocCommandData.setError(error);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("command")) {
done = true;
}
}
}
return adHocCommandData;
}
use of org.jivesoftware.smackx.commands.AdHocCommandNote in project Smack by igniterealtime.
the class AdHocCommandDataProvider method parse.
@Override
public AdHocCommandData parse(XmlPullParser parser, int initialDepth) throws Exception {
boolean done = false;
AdHocCommandData adHocCommandData = new AdHocCommandData();
DataFormProvider dataFormProvider = new DataFormProvider();
int 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();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG) {
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")) {
XMPPError.Builder error = PacketParserUtils.parseError(parser);
adHocCommandData.setError(error);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("command")) {
done = true;
}
}
}
return adHocCommandData;
}
use of org.jivesoftware.smackx.commands.AdHocCommandNote in project ecf by eclipse.
the class AdHocCommandData method getChildElementXML.
@Override
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<command xmlns=\"http://jabber.org/protocol/commands\"");
buf.append(" node=\"").append(node).append("\"");
if (sessionID != null) {
if (!sessionID.equals("")) {
buf.append(" sessionid=\"").append(sessionID).append("\"");
}
}
if (status != null) {
buf.append(" status=\"").append(status).append("\"");
}
if (action != null) {
buf.append(" action=\"").append(action).append("\"");
}
if (lang != null) {
if (!lang.equals("")) {
buf.append(" lang=\"").append(lang).append("\"");
}
}
buf.append(">");
if (getType() == Type.RESULT) {
buf.append("<actions");
if (executeAction != null) {
buf.append(" execute=\"").append(executeAction).append("\"");
}
if (actions.size() == 0) {
buf.append("/>");
} else {
buf.append(">");
for (AdHocCommand.Action action : actions) {
buf.append("<").append(action).append("/>");
}
buf.append("</actions>");
}
}
if (form != null) {
buf.append(form.toXML());
}
for (AdHocCommandNote note : notes) {
buf.append("<note type=\"").append(note.getType().toString()).append("\">");
buf.append(note.getValue());
buf.append("</note>");
}
// TODO ERRORS
// if (getError() != null) {
// buf.append(getError().toXML());
// }
buf.append("</command>");
return buf.toString();
}
use of org.jivesoftware.smackx.commands.AdHocCommandNote in project Smack by igniterealtime.
the class AdHocCommandData method getIQChildElementBuilder.
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.attribute("node", node);
xml.optAttribute("sessionid", sessionID);
xml.optAttribute("status", status);
xml.optAttribute("action", action);
xml.rightAngleBracket();
if (getType() == Type.result) {
xml.halfOpenElement("actions");
xml.optAttribute("execute", executeAction);
if (actions.size() == 0) {
xml.closeEmptyElement();
} else {
xml.rightAngleBracket();
for (AdHocCommand.Action action : actions) {
xml.emptyElement(action);
}
xml.closeElement("actions");
}
}
if (form != null) {
xml.append(form.toXML());
}
for (AdHocCommandNote note : notes) {
xml.halfOpenElement("note").attribute("type", note.getType().toString()).rightAngleBracket();
xml.append(note.getValue());
xml.closeElement("note");
}
return xml;
}
use of org.jivesoftware.smackx.commands.AdHocCommandNote 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;
}
Aggregations