diff --git a/documentation/providers.md b/documentation/providers.md index 954fc64e3..e2c5149d2 100644 --- a/documentation/providers.md +++ b/documentation/providers.md @@ -13,9 +13,11 @@ There are two types of providers: * `IQProvider` -- parses IQ requests into Java objects. * `Extension Provider` -- parses XML sub-documents attached to packets into PacketExtension instances. By default, Smack only knows how to process a few standard packets and sub-packets that are in a few namespaces such as: - * jabber:iq:auth - * jabber:iq:roster - * jabber:iq:register There are many more IQ types and extensions that are part of XMPP standards, and of course an endless number that can be added as custom extensions. To support this, an extensible parsing mechanism is provided via Smack and user build providers. + * jabber:iq:auth + * jabber:iq:roster + * jabber:iq:register + +There are many more IQ types and extensions that are part of XMPP standards, and of course an endless number that can be added as custom extensions. To support this, an extensible parsing mechanism is provided via Smack and user build providers. Whenever a packet extension is found in a packet, parsing will be passed to the correct provider. Each provider must implement the @@ -140,7 +142,7 @@ _Custom IQ_ John Doe - New York + New York ``` @@ -154,36 +156,36 @@ public class MyIQProvider extends IQProvider { public MyIQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { // Define the data we are trying to collect with sane defaults int age = -1; - String user = null; - String location = null; + String user = null; + String location = null; // Start parsing loop - outerloop: while(true) { - int eventType = parser.next(); - switch(eventType) { - case XmlPullParser.START_TAG: - String elementName = parser.getName(); - switch (elementName) { - case "user": - age = ParserUtils.getIntegerAttribute(parser, "age"); - user = parser.nextText(); - break; - case "location" - location = parser.nextText(); - break; - } - break; - case XmlPullParser.END_TAG: - // Abort condition: if the are on a end tag (closing element) of the same depth - if (parser.getDepth() == initialDepth) { - break outerloop; - } - break; - } - } + outerloop: while(true) { + int eventType = parser.next(); + switch(eventType) { + case XmlPullParser.START_TAG: + String elementName = parser.getName(); + switch (elementName) { + case "user": + age = ParserUtils.getIntegerAttribute(parser, "age"); + user = parser.nextText(); + break; + case "location" + location = parser.nextText(); + break; + } + break; + case XmlPullParser.END_TAG: + // Abort condition: if the are on a end tag (closing element) of the same depth + if (parser.getDepth() == initialDepth) { + break outerloop; + } + break; + } + } // Construct the IQ instance at the end of parsing, when all data has been collected - return new MyIQ(user, age, location); + return new MyIQ(user, age, location); } } ```