blob: 90d1f3b9fecc1b57ef66674fcf243d0d28e97097 (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* Copyright (c) 2014, Isode Limited, London, England.
* All rights reserved.
*/
/*
* Copyright (c) 2014, Remko Tronçon.
* All rights reserved.
*/
package com.isode.stroke.parser.payloadparsers;
import com.isode.stroke.parser.AttributeMap;
import com.isode.stroke.parser.GenericPayloadParser;
import com.isode.stroke.parser.PayloadParser;
import com.isode.stroke.parser.PayloadParserFactoryCollection;
import com.isode.stroke.jid.JID;
import com.isode.stroke.elements.PubSubOwnerSubscription;
public class PubSubOwnerSubscriptionParser extends GenericPayloadParser<PubSubOwnerSubscription> {
public PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection parsers) {
super(new PubSubOwnerSubscription());
parsers_ = parsers;
level_ = 0;
}
public void handleStartElement(String element, String ns, AttributeMap attributes) {
if (level_ == 0) {
String attributeValue;
attributeValue = attributes.getAttribute("subscription");
if (!attributeValue.isEmpty()) {
getPayloadInternal().setSubscription(parseSubscriptionType(attributeValue));
}
attributeValue = attributes.getAttribute("jid");
if (!attributeValue.isEmpty()) {
getPayloadInternal().setJID(JID.fromString(attributeValue));
}
}
if (level_ >= 1 && currentPayloadParser_ != null) {
currentPayloadParser_.handleStartElement(element, ns, attributes);
}
++level_;
}
public void handleEndElement(String element, String ns) {
--level_;
if (currentPayloadParser_ != null) {
if (level_ >= 1) {
currentPayloadParser_.handleEndElement(element, ns);
}
if (level_ != 1) {
return;
}
currentPayloadParser_ = null;
}
}
public void handleCharacterData(String data) {
if (level_ > 1 && currentPayloadParser_ != null) {
currentPayloadParser_.handleCharacterData(data);
}
}
private static PubSubOwnerSubscription.SubscriptionType parseSubscriptionType(String value) {
if (value.equals("none")) {
return PubSubOwnerSubscription.SubscriptionType.None;
} else if (value.equals("pending")) {
return PubSubOwnerSubscription.SubscriptionType.Pending;
} else if (value.equals("subscribed")) {
return PubSubOwnerSubscription.SubscriptionType.Subscribed;
} else if (value.equals("unconfigured")) {
return PubSubOwnerSubscription.SubscriptionType.Unconfigured;
} else {
return null;
}
}
PayloadParserFactoryCollection parsers_;
int level_;
PayloadParser currentPayloadParser_;
}
|