Christophe is right, the doc is rare, but they are getting better. However, there is a good, although difficult to find, set of documents on extensions. PubSub is located at http://www.igniterealtime.org/fisheye/browse/~raw,r=11613/svn-org/smack/trunk/documentation/extensions/pubsub.html .
After you sent an IQ Provider custom route from scratch with the extension, I found it was easier to do this using managers as much as possible. The developers who wrote the managers distracted a lot of pain points.
Example (the version of one rcollier modified for geolocation is written on the Smack forum):
ConfigureForm form = new ConfigureForm(FormType.submit); form.setPersistentItems(false); form.setDeliverPayloads(true); form.setAccessModel(AccessModel.open); PubSubManager manager = new PubSubManager(connection, "pubsub.communitivity.com"); Node myNode = manager.createNode("http://jabber.org/protocol/geoloc", form); StringBuilder body = new StringBuilder(); //ws for readability body.append("<geoloc xmlns='http://jabber.org/protocol/geoloc' xml:lang='en'>"); body.append(" <country>Italy</country>"); body.append(" <lat>45.44</lat>"); body.append(" <locality>Venice</locality>"); body.append(" <lon>12.33</lon>"); body.append(" <accuracy>20</accuracy>"); body.append("</geoloc>"); SimplePayload payload = new SimplePayload( "geoloc", "http://jabber.org/protocol/geoloc", body.toString()); String itemId = "zz234"; Item<SimplePayload> item = new Item<SimplePayload>(itemId, payload); // Required to recieve the events being published myNode.addItemEventListener(myEventHandler); // Publish item myNode.publish(item);
Or at least it's the hard way :). Just remembered that now PEPManager ...
PEPProvider pepProvider = new PEPProvider(); pepProvider.registerPEPParserExtension( "http://jabber.org/protocol/tune", new TuneProvider()); ProviderManager.getInstance().addExtensionProvider( "event", "http://jabber.org/protocol/pubsub#event", pepProvider); Tune tune = new Tune("jeff", "1", "CD", "My Title", "My Track"); pepManager.publish(tune);
You will need to write the GeoLocProvider and GeoLoc classes.
Bill barnhill
source share