summaryrefslogtreecommitdiffstats
blob: f30a682fbb52d36f34d55b5beaa2e04f1112c4ed (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * Copyright (c) 2010, Remko Tron�on.
 * All rights reserved.
 */
/*
 * Copyright (c) 2012, Isode Limited, London, England.
 * All rights reserved.
 */
package com.isode.stroke.elements;

import com.isode.stroke.base.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * disco#info from XEP-0030.
 */
public class DiscoInfo extends Payload {

    public static final String ChatStatesFeature = "http://jabber.org/protocol/chatstates";
    public static final String SecurityLabelsFeature = "urn:xmpp:sec-label:0";
    public static final String SecurityLabelsCatalogFeature = "urn:xmpp:sec-label:catalog:2";
    public static final String JabberSearchFeature = "jabber:iq:search";
    public static final String CommandsFeature = "http://jabber.org/protocol/commands";
    public static final String MessageCorrectionFeature = "urn:xmpp:message-correct:0";
    public static final String JingleFeature = "urn:xmpp:jingle:1";
    public static final String JingleFTFeature = "urn:xmpp:jingle:apps:file-transfer:3";
    public static final String JingleTransportsIBBFeature = "urn:xmpp:jingle:transports:ibb:1";
    public static final String JingleTransportsS5BFeature = "urn:xmpp:jingle:transports:s5b:1";
    public static final String Bytestream = "http://jabber.org/protocol/bytestreams";
    public static final String MessageDeliveryReceiptsFeature = "urn:xmpp:receipts";

    public static class Identity implements Comparable<Identity> {

        /**
         * Identity(name, "client", "pc", "");
         */
        public Identity(String name) {
            this(name, "client");
        }

        /**
         * Identity(name, category, "pc, "");
         */
        public Identity(String name, String category) {
            this(name, category, "pc");
        }

        /**
         * Identity(name, category, type, "");
         */
        public Identity(String name, String category, String type) {
            this(name, category, type, "");
        }

        /**
         *
         * @param name Identity name, notnull.
         * @param category Identity category, notnull.
         * @param type Identity type, notnull.
         * @param lang Identity language, notnull.
         */
        public Identity(String name, String category, String type, String lang) {
            NotNull.exceptIfNull(name, "name");
            NotNull.exceptIfNull(category, "category");
            NotNull.exceptIfNull(type, "type");
            NotNull.exceptIfNull(lang, "lang");
            name_ = name;
            category_ = category;
            type_ = type;
            lang_ = lang;
        }

        /**
         *
         * @return Not null.
         */
        public String getCategory() {
            return category_;
        }

        /**
         *
         * @return Not null.
         */
        public String getType() {
            return type_;
        }

        /**
         *
         * @return Not null.
         */
        public String getLanguage() {
            return lang_;
        }

        /**
         *
         * @return Not null.
         */
        public String getName() {
            return name_;
        }

        // Sorted according to XEP-115 rules
        public int compareTo(Identity other) {
            if (other == null) {
                return -1;
            }
            if (category_.equals(other.category_)) {
                if (type_.equals(other.type_)) {
                    if (lang_.equals(other.lang_)) {
                        return name_.compareTo(other.name_);
                    } else {
                        return lang_.compareTo(other.lang_);
                    }
                } else {
                    return type_.compareTo(other.type_);
                }
            } else {
                return category_.compareTo(other.category_);
            }
        }
            
        private final String name_;
        private final String category_;
        private final String type_;
        private final String lang_;


    }

    public DiscoInfo() {
    }

    /**
     *
     * @return Node, notnull.
     */
    public String getNode() {
        return node_;
    }

    /**
     *
     * @param node Notnull.
     */
    public void setNode(String node) {
        NotNull.exceptIfNull(node, "node");
        node_ = node;
    }

    /**
     *
     * @return Copy of the list of identities. Non-null.
     */
    public List<Identity> getIdentities() {
        return new ArrayList(identities_);
    }

    /**
     *
     * @param identity Non-null.
     */
    public void addIdentity(Identity identity) {
        NotNull.exceptIfNull(identity, "identity");
        identities_.add(identity);
    }

    /**
     *
     * @return Copy of the list of features. Nonnull.
     */
    public List<String> getFeatures() {
        return new ArrayList(features_);
    }

    /**
     *
     * @param feature Non-null.
     */
    public void addFeature(String feature) {
        NotNull.exceptIfNull(feature, "feature");
        features_.add(feature);
    }

    public boolean hasFeature(String feature) {
        return features_.contains(feature);
    }

    /**
     *
     * @param form Non-null.
     */
    public void addExtension(Form form) {
        NotNull.exceptIfNull(form, "form");
        extensions_.add(form);
    }

    /**
     *
     * @return A copy of the list, where the contents are references to the same objects.
     */
    public List<Form> getExtensions() {
        return new ArrayList(extensions_);
    }
    private String node_ = "";
    private final List<Identity> identities_ = new ArrayList<Identity>();
    private final List<String> features_ = new ArrayList<String>();
    private final List<Form> extensions_ = new ArrayList<Form>();
}