blob: d4f765f1142de0a6edff347287061aa269203018 (
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright (c) 2014, Isode Limited, London, England.
* All rights reserved.
*/
/*
* Copyright (c) 2014, Remko Tronçon.
* All rights reserved.
*/
package com.isode.stroke.serializer.payloadserializers;
import com.isode.stroke.elements.PubSubError;
import com.isode.stroke.serializer.GenericPayloadSerializer;
import com.isode.stroke.serializer.xml.XMLElement;
public class PubSubErrorSerializer extends GenericPayloadSerializer<PubSubError> {
public PubSubErrorSerializer() {
super(PubSubError.class);
}
@Override
public String serializePayload(PubSubError payload) {
if (payload.getType().equals(PubSubError.Type.UnknownType)) {
return "";
}
XMLElement element = new XMLElement(serializeType(payload.getType()), "http://jabber.org/protocol/pubsub#errors");
if (payload.getType().equals(PubSubError.Type.Unsupported)) {
if (!payload.getUnsupportedFeatureType().equals(PubSubError.UnsupportedFeatureType.UnknownUnsupportedFeatureType)) {
element.setAttribute("feature", serializeUnsupportedFeatureType(payload.getUnsupportedFeatureType()));
}
}
return element.serialize();
}
static String serializeType(PubSubError.Type value) {
switch (value) {
case UnknownType: return "";
case ClosedNode: return "closed-node";
case ConfigurationRequired: return "configuration-required";
case InvalidJID: return "invalid-jid";
case InvalidOptions: return "invalid-options";
case InvalidPayload: return "invalid-payload";
case InvalidSubscriptionID: return "invalid-subid";
case ItemForbidden: return "item-forbidden";
case ItemRequired: return "item-required";
case JIDRequired: return "jid-required";
case MaximumItemsExceeded: return "max-items-exceeded";
case MaximumNodesExceeded: return "max-nodes-exceeded";
case NodeIDRequired: return "nodeid-required";
case NotInRosterGroup: return "not-in-roster-group";
case NotSubscribed: return "not-subscribed";
case PayloadTooBig: return "payload-too-big";
case PayloadRequired: return "payload-required";
case PendingSubscription: return "pending-subscription";
case PresenceSubscriptionRequired: return "presence-subscription-required";
case SubscriptionIDRequired: return "subid-required";
case TooManySubscriptions: return "too-many-subscriptions";
case Unsupported: return "unsupported";
case UnsupportedAccessModel: return "unsupported-access-model";
default: return null;
}
}
static String serializeUnsupportedFeatureType(PubSubError.UnsupportedFeatureType value) {
switch (value) {
case UnknownUnsupportedFeatureType: assert(false); return "";
case AccessAuthorize: return "access-authorize";
case AccessOpen: return "access-open";
case AccessPresence: return "access-presence";
case AccessRoster: return "access-roster";
case AccessWhitelist: return "access-whitelist";
case AutoCreate: return "auto-create";
case AutoSubscribe: return "auto-subscribe";
case Collections: return "collections";
case ConfigNode: return "config-node";
case CreateAndConfigure: return "create-and-configure";
case CreateNodes: return "create-nodes";
case DeleteItems: return "delete-items";
case DeleteNodes: return "delete-nodes";
case FilteredNotifications: return "filtered-notifications";
case GetPending: return "get-pending";
case InstantNodes: return "instant-nodes";
case ItemIDs: return "item-ids";
case LastPublished: return "last-published";
case LeasedSubscription: return "leased-subscription";
case ManageSubscriptions: return "manage-subscriptions";
case MemberAffiliation: return "member-affiliation";
case MetaData: return "meta-data";
case ModifyAffiliations: return "modify-affiliations";
case MultiCollection: return "multi-collection";
case MultiSubscribe: return "multi-subscribe";
case OutcastAffiliation: return "outcast-affiliation";
case PersistentItems: return "persistent-items";
case PresenceNotifications: return "presence-notifications";
case PresenceSubscribe: return "presence-subscribe";
case Publish: return "publish";
case PublishOptions: return "publish-options";
case PublishOnlyAffiliation: return "publish-only-affiliation";
case PublisherAffiliation: return "publisher-affiliation";
case PurgeNodes: return "purge-nodes";
case RetractItems: return "retract-items";
case RetrieveAffiliations: return "retrieve-affiliations";
case RetrieveDefault: return "retrieve-default";
case RetrieveItems: return "retrieve-items";
case RetrieveSubscriptions: return "retrieve-subscriptions";
case Subscribe: return "subscribe";
case SubscriptionOptions: return "subscription-options";
case SubscriptionNotifications: return "subscription-notifications";
default: return null;
}
}
}
|