blob: f1f7701f40fd2444b36043b0a756ccfe964352f2 (
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
|
/*
* Copyright (c) 2013-2015, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.parser.payloadparsers;
import com.isode.stroke.elements.PubSubEventPayload;
import com.isode.stroke.parser.AttributeMap;
import com.isode.stroke.parser.GenericPayloadParser;
import com.isode.stroke.parser.PayloadParser;
import com.isode.stroke.parser.PayloadParserFactoryCollection;
public class PubSubEventParser extends GenericPayloadParser<PubSubEvent> {
public PubSubEventParser(PayloadParserFactoryCollection parser) {
super(new PubSubEvent());
parsers_ = parser;
}
@Override
public void handleStartElement(String element, String ns, AttributeMap attributes) {
if (level_ == 1) {
if ("items".equals(element) && "http://jabber.org/protocol/pubsub#event".equals(ns)) {
currentPayloadParser_ = new PubSubEventItemsParser(parsers_);
}
if ("collection".equals(element) && "http://jabber.org/protocol/pubsub#event".equals(ns)) {
currentPayloadParser_ = new PubSubEventCollectionParser(parsers_);
}
if ("purge".equals(element) && "http://jabber.org/protocol/pubsub#event".equals(ns)) {
currentPayloadParser_ = new PubSubEventPurgeParser(parsers_);
}
if ("configuration".equals(element) && "http://jabber.org/protocol/pubsub#event".equals(ns)) {
currentPayloadParser_ = new PubSubEventConfigurationParser(parsers_);
}
if ("delete".equals(element) && "http://jabber.org/protocol/pubsub#event".equals(ns)) {
currentPayloadParser_ = new PubSubEventDeleteParser(parsers_);
}
if ("subscription".equals(element) && "http://jabber.org/protocol/pubsub#event".equals(ns)) {
currentPayloadParser_ = new PubSubEventSubscriptionParser(parsers_);
}
}
if (level_>=1 && currentPayloadParser_!=null) {
currentPayloadParser_.handleStartElement(element, ns, attributes);
}
++level_;
}
@Override
public void handleEndElement(String element, String ns) {
--level_;
if (currentPayloadParser_ != null) {
if (level_ >= 1) {
currentPayloadParser_.handleEndElement(element, ns);
}
if (level_ == 1) {
if (currentPayloadParser_ != null) {
getPayloadInternal().setPayload((PubSubEventPayload)currentPayloadParser_.getPayload());
}
currentPayloadParser_ = null;
}
}
}
@Override
public void handleCharacterData(String data) {
if (level_ > 1 && currentPayloadParser_!=null) {
currentPayloadParser_.handleCharacterData(data);
}
}
PayloadParserFactoryCollection parsers_;
int level_;
PayloadParser currentPayloadParser_;
}
|