Skip to content

Commit

Permalink
Merge 4ab7c20 into 62bb02a
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-starodubtsev committed Jan 18, 2016
2 parents 62bb02a + 4ab7c20 commit 2e82755
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions documentation/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -140,7 +142,7 @@ _Custom IQ_
<iq type='set' from='juliet@capulet.example/balcony' to='romeo@montage.example'>
<myiq xmlns='example:iq:foo' token='secret'>
<user age='42'>John Doe</user>
<location>New York</location>
<location>New York</location>
</myiq>
</iq>
```
Expand All @@ -154,36 +156,36 @@ public class MyIQProvider extends IQProvider<MyIQ> {
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);
}
}
```
Expand Down

0 comments on commit 2e82755

Please sign in to comment.