use of org.jivesoftware.smackx.xdata.provider.DataFormProvider in project Zom-Android by zom.
the class XmppConnection method addProviderManagerExtensions.
public static void addProviderManagerExtensions() {
ProviderManager.addIQProvider("query", "jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Time
try {
ProviderManager.addIQProvider("query", "jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
} catch (ClassNotFoundException e) {
Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time");
}
// Pings
ProviderManager.addIQProvider("ping", "urn:xmpp:ping", new PingProvider());
// Roster Exchange
// providerManager.addExtensionProvider("x", "jabber:x:roster", new RosterExchangeProvider());
ProviderManager.addIQProvider("vCard", "vcard-temp", new VCardProvider());
// Message Events
// providerManager.addExtensionProvider("x", "jabber:x:event",
// new MessageEventProvider());
// XHTML
ProviderManager.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
// Group Chat Invitations
ProviderManager.addExtensionProvider("x", "jabber:x:conference", new GroupChatInvitation.Provider());
// Service Discovery # Items
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
// Service Discovery # Info
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Data Forms
ProviderManager.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
// MUC User
ProviderManager.addExtensionProvider("x", "http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Version
try {
ProviderManager.addIQProvider("query", "jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
} catch (ClassNotFoundException e) {
// Not sure what's happening here.
}
// VCard
ProviderManager.addIQProvider("vCard", "vcard-temp", new VCardProvider());
// Offline Message Requests
ProviderManager.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
// Offline Message Indicator
ProviderManager.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
// Last Activity
ProviderManager.addIQProvider("query", "jabber:iq:last", new LastActivity.Provider());
// User Search
ProviderManager.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());
// SharedGroupsInfo
ProviderManager.addIQProvider("sharedgroup", "http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
ProviderManager.addExtensionProvider("addresses", "http://jabber.org/protocol/address", new MultipleAddressesProvider());
// FileTransfer
ProviderManager.addIQProvider("si", "http://jabber.org/protocol/si", new StreamInitiationProvider());
// Privacy
ProviderManager.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
ProviderManager.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
ProviderManager.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
ProviderManager.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
ProviderManager.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
ProviderManager.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
ProviderManager.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
ProviderManager.addIQProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
// Offline Message Indicator
ProviderManager.addExtensionProvider("offline", "http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
ProviderManager.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
// pm.addExtensionProvider("status ","", new XMLPlayerList());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
ProviderManager.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Private Data Storage
// ProviderManager.addIQProvider("query","jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
// Time
/**
* try {
* ProviderManager.addIQProvider("query","jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time"));
* } catch (ClassNotFoundException e) {
* Log.w("TestClient", "Can't load class for org.jivesoftware.smackx.packet.Time");
* }
*/
// Roster Exchange
// ProviderManager.addExtensionProvider("x","jabber:x:roster", new RosterExchangeProvider());
// Message Events
// ProviderManager.addExtensionProvider("x","jabber:x:event", new MessageEventProvider());
// Chat State
ChatStateExtensionProvider csep = new ChatStateExtensionProvider();
ProviderManager.addExtensionProvider("active", "http://jabber.org/protocol/chatstates", csep);
ProviderManager.addExtensionProvider("composing", "http://jabber.org/protocol/chatstates", csep);
ProviderManager.addExtensionProvider("paused", "http://jabber.org/protocol/chatstates", csep);
ProviderManager.addExtensionProvider("inactive", "http://jabber.org/protocol/chatstates", csep);
ProviderManager.addExtensionProvider("gone", "http://jabber.org/protocol/chatstates", csep);
// XHTML
// ProviderManager.addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider());
// Group Chat Invitations
// ProviderManager.addExtensionProvider("x","jabber:x:conference", new GroupChatInvitation.Provider());
// Service Discovery # Items
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
// Service Discovery # Info
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
// Data Forms
// ProviderManager.addExtensionProvider("x","jabber:x:data", new DataFormProvider());
// MUC User
// ProviderManager.addExtensionProvider("x","http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Delayed Delivery
// ProviderManager.addExtensionProvider("x","jabber:x:delay", new DelayInformationProvider());
// Version
/**
* try {
* ProviderManager.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version"));
* } catch (ClassNotFoundException err) {
* // Not sure what's happening here.
* }
*/
// VCard
// ProviderManager.addIQProvider("vCard","vcard-temp", new VCardProvider());
// Offline Message Requests
// ProviderManager.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
// Offline Message Indicator
// ProviderManager.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());
// Last Activity
// ProviderManager.addIQProvider("query","jabber:iq:last", new LastActivity.Provider());
// User Search
// ProviderManager.addIQProvider("query","jabber:iq:search", new UserSearch.Provider());
// SharedGroupsInfo
// ProviderManager.addIQProvider("sharedgroup","http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
// ProviderManager.addExtensionProvider("addresses","http://jabber.org/protocol/address", new MultipleAddressesProvider());
// FileTransfer
// ProviderManager.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider());
// ProviderManager.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
// Privacy
/**
* ProviderManager.addIQProvider("query","jabber:iq:privacy", new PrivacyProvider());
* ProviderManager.addIQProvider("command", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider());
* ProviderManager.addExtensionProvider("malformed-action", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.MalformedActionError());
* ProviderManager.addExtensionProvider("bad-locale", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadLocaleError());
* ProviderManager.addExtensionProvider("bad-payload", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadPayloadError());
* ProviderManager.addExtensionProvider("bad-sessionid", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.BadSessionIDError());
* ProviderManager.addExtensionProvider("session-expired", "http://jabber.org/protocol/commands", new AdHocCommandDataProvider.SessionExpiredError());
*/
}
use of org.jivesoftware.smackx.xdata.provider.DataFormProvider in project Smack by igniterealtime.
the class StreamInitiationProvider method parse.
@Override
public StreamInitiation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
// si
String id = parser.getAttributeValue("", "id");
String mimeType = parser.getAttributeValue("", "mime-type");
StreamInitiation initiation = new StreamInitiation();
// file
String name = null;
String size = null;
String hash = null;
String date = null;
String desc = null;
boolean isRanged = false;
// feature
DataForm form = null;
DataFormProvider dataFormProvider = new DataFormProvider();
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
String elementName = parser.getName();
String namespace = parser.getNamespace();
if (elementName.equals("file")) {
name = parser.getAttributeValue("", "name");
size = parser.getAttributeValue("", "size");
hash = parser.getAttributeValue("", "hash");
date = parser.getAttributeValue("", "date");
} else if (elementName.equals("desc")) {
desc = parser.nextText();
} else if (elementName.equals("range")) {
isRanged = true;
} else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
form = dataFormProvider.parse(parser);
}
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
if (parser.getName().equals("file")) {
long fileSize = 0;
if (size != null && size.trim().length() != 0) {
try {
fileSize = Long.parseLong(size);
} catch (NumberFormatException e) {
LOGGER.log(Level.SEVERE, "Failed to parse file size from " + fileSize, e);
}
}
Date fileDate = new Date();
if (date != null) {
try {
fileDate = XmppDateTime.parseDate(date);
} catch (ParseException e) {
// couldn't parse date, use current date-time
}
}
File file = new File(name, fileSize);
file.setHash(hash);
file.setDate(fileDate);
file.setDesc(desc);
file.setRanged(isRanged);
initiation.setFile(file);
}
}
}
initiation.setSessionID(id);
initiation.setMimeType(mimeType);
initiation.setFeatureNegotiationForm(form);
return initiation;
}
use of org.jivesoftware.smackx.xdata.provider.DataFormProvider in project Smack by igniterealtime.
the class DataLayoutTest method testLayoutFromFile.
@Test
public void testLayoutFromFile() throws Exception {
DataFormProvider pr = new DataFormProvider();
InputStreamReader inputStreamReader = new InputStreamReader(this.getClass().getResourceAsStream(TEST_INPUT_1), "UTF-8");
XmlPullParser parser = PacketParserUtils.getParserFor(inputStreamReader);
DataForm form = pr.parse(parser);
assertNotNull(form);
assertEquals(1, form.getExtensionElements().size());
DataLayout layout = (DataLayout) form.getExtensionElements().get(0);
assertEquals(5, layout.getPageLayout().size());
assertEquals("Label - & \u00E9 \u00E1 ", layout.getLabel());
Section section = (Section) layout.getPageLayout().get(1);
assertEquals("section Label - & \u00E9 \u00E1 ", section.getLabel());
Text text = (Text) layout.getPageLayout().get(2);
assertEquals("PageText - & \u00E9 \u00E1 ", text.getText());
section = (Section) layout.getPageLayout().get(3);
assertEquals("<html>Number of Persons by<br/> Nationality and Status</html>", section.getLabel());
text = (Text) layout.getPageLayout().get(4);
assertEquals("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>", text.getText());
assertNotNull(layout.toXML());
String output = layout.toXML().toString();
assertEquals(TEST_OUTPUT_SPECIAL, output);
}
use of org.jivesoftware.smackx.xdata.provider.DataFormProvider in project Smack by igniterealtime.
the class StreamInitiationProvider method parse.
@Override
public StreamInitiation parse(XmlPullParser parser, int initialDepth) throws Exception {
boolean done = false;
// si
String id = parser.getAttributeValue("", "id");
String mimeType = parser.getAttributeValue("", "mime-type");
StreamInitiation initiation = new StreamInitiation();
// file
String name = null;
String size = null;
String hash = null;
String date = null;
String desc = null;
boolean isRanged = false;
// feature
DataForm form = null;
DataFormProvider dataFormProvider = new DataFormProvider();
int eventType;
String elementName;
String namespace;
while (!done) {
eventType = parser.next();
elementName = parser.getName();
namespace = parser.getNamespace();
if (eventType == XmlPullParser.START_TAG) {
if (elementName.equals("file")) {
name = parser.getAttributeValue("", "name");
size = parser.getAttributeValue("", "size");
hash = parser.getAttributeValue("", "hash");
date = parser.getAttributeValue("", "date");
} else if (elementName.equals("desc")) {
desc = parser.nextText();
} else if (elementName.equals("range")) {
isRanged = true;
} else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
form = dataFormProvider.parse(parser);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (elementName.equals("si")) {
done = true;
} else if (elementName.equals("file")) {
long fileSize = 0;
if (size != null && size.trim().length() != 0) {
try {
fileSize = Long.parseLong(size);
} catch (NumberFormatException e) {
LOGGER.log(Level.SEVERE, "Failed to parse file size from " + fileSize, e);
}
}
Date fileDate = new Date();
if (date != null) {
try {
fileDate = XmppDateTime.parseDate(date);
} catch (ParseException e) {
// couldn't parse date, use current date-time
}
}
File file = new File(name, fileSize);
file.setHash(hash);
file.setDate(fileDate);
file.setDesc(desc);
file.setRanged(isRanged);
initiation.setFile(file);
}
}
}
initiation.setSessionID(id);
initiation.setMimeType(mimeType);
initiation.setFeatureNegotiationForm(form);
return initiation;
}
use of org.jivesoftware.smackx.xdata.provider.DataFormProvider 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;
}
Aggregations