blob: abf7c2948a6b571ee31a3048d217d5e3e724b47f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/*
* Copyright (c) 2012, Isode Limited, London, England.
* All rights reserved.
*/
/*
* Copyright (c) 2010, Kevin Smith.
* All rights reserved.
*/
package com.isode.stroke.parser.payloadparsers;
import com.isode.stroke.elements.DiscoItems;
import com.isode.stroke.elements.DiscoItems.Item;
import com.isode.stroke.jid.JID;
import com.isode.stroke.parser.AttributeMap;
import com.isode.stroke.parser.GenericPayloadParser;
public class DiscoItemsParser extends GenericPayloadParser<DiscoItems> {
public DiscoItemsParser() {
super(new DiscoItems());
}
public void handleStartElement(String element, String ns, AttributeMap attributes) {
if (level_ == PayloadLevel) {
if (element.equals("item")) {
Item item = new Item(attributes.getAttribute("name"), new JID(attributes.getAttribute("jid")), attributes.getAttribute("node"));
getPayloadInternal().addItem(item);
}
}
else if (level_ == TopLevel) {
if (element.equals("query")) {
getPayloadInternal().setNode(attributes.getAttribute("node"));
}
}
++level_;
}
public void handleEndElement(String element, String ns) {
--level_;
}
public void handleCharacterData(String data) {
}
private static final int TopLevel = 0;
private static final int PayloadLevel = 1;
private int level_ = TopLevel;
}
|