1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2003 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail me at eric@jeti.tk |
---|
21 | */ |
---|
22 | |
---|
23 | |
---|
24 | //Created on 6-aug-2004 |
---|
25 | package nu.fw.jeti.jabber.elements; |
---|
26 | |
---|
27 | import java.util.Collections; |
---|
28 | import java.util.Iterator; |
---|
29 | import java.util.LinkedList; |
---|
30 | import java.util.List; |
---|
31 | |
---|
32 | import nu.fw.jeti.jabber.Backend; |
---|
33 | |
---|
34 | /** |
---|
35 | * @author E.S. de Boer |
---|
36 | * implements the http://jabber.org/protocol/disco#info'/ spec |
---|
37 | */ |
---|
38 | public class IQDiscoInfo extends Extension implements IQExtension, DiscoveryInfo |
---|
39 | { |
---|
40 | private String node; |
---|
41 | private List identities; |
---|
42 | private List features; |
---|
43 | |
---|
44 | |
---|
45 | public IQDiscoInfo() |
---|
46 | {} |
---|
47 | |
---|
48 | public IQDiscoInfo(String node) |
---|
49 | { |
---|
50 | this.node = node; |
---|
51 | } |
---|
52 | |
---|
53 | public IQDiscoInfo(String node,List identities,List features) |
---|
54 | { |
---|
55 | this.node = node; |
---|
56 | this.identities = identities; |
---|
57 | this.features = features; |
---|
58 | } |
---|
59 | |
---|
60 | public String getNode() |
---|
61 | { |
---|
62 | return node; |
---|
63 | } |
---|
64 | |
---|
65 | public Iterator getIdentities() |
---|
66 | { |
---|
67 | if (identities == null)return null; |
---|
68 | return identities.iterator(); |
---|
69 | } |
---|
70 | |
---|
71 | public List getFeatures() |
---|
72 | { |
---|
73 | return Collections.unmodifiableList(features); |
---|
74 | } |
---|
75 | |
---|
76 | public boolean hasFeatures() |
---|
77 | { |
---|
78 | return features!=null; |
---|
79 | } |
---|
80 | |
---|
81 | //discovery implementations |
---|
82 | //use the first identity, browse can not have more identities |
---|
83 | public String getName() |
---|
84 | { |
---|
85 | if (identities == null)return null; |
---|
86 | return ((DiscoIdentity)identities.get(0)).getName(); |
---|
87 | } |
---|
88 | |
---|
89 | //discovery implementations |
---|
90 | //use the first identity, browse can not have more identities |
---|
91 | public String getCategory() |
---|
92 | { |
---|
93 | if (identities == null)return null; |
---|
94 | return ((DiscoIdentity)identities.get(0)).getCategory(); |
---|
95 | } |
---|
96 | |
---|
97 | //discovery implementations |
---|
98 | //use the first identity, browse can not have more identities |
---|
99 | public String getType() |
---|
100 | { |
---|
101 | if (identities == null)return null; |
---|
102 | return ((DiscoIdentity)identities.get(0)).getType(); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | // public boolean hasChildItems() |
---|
107 | // { |
---|
108 | // return identities != null; |
---|
109 | // } |
---|
110 | |
---|
111 | public void execute(InfoQuery iq,Backend backend){} |
---|
112 | |
---|
113 | public void appendToXML(StringBuffer xml) |
---|
114 | { |
---|
115 | xml.append("<query xmlns= 'http://jabber.org/protocol/disco#info'"); |
---|
116 | appendAttribute(xml, "node", node); |
---|
117 | if (identities == null && features==null) |
---|
118 | { //short cut |
---|
119 | xml.append("/>"); |
---|
120 | return; |
---|
121 | } |
---|
122 | xml.append('>'); |
---|
123 | if (identities != null) |
---|
124 | { |
---|
125 | for (Iterator i = identities.iterator(); i.hasNext();) |
---|
126 | { |
---|
127 | ((DiscoIdentity) i.next()).appendToXML(xml); |
---|
128 | } |
---|
129 | } |
---|
130 | if(features!=null) |
---|
131 | { |
---|
132 | for (Iterator i = features.iterator(); i.hasNext();) |
---|
133 | { |
---|
134 | xml.append("<feature var='" + i.next() +"'/>"); |
---|
135 | } |
---|
136 | } |
---|
137 | xml.append("</query>"); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | /* |
---|
142 | * Overrides for emacs |
---|
143 | * Local variables: |
---|
144 | * tab-width: 4 |
---|
145 | * End: |
---|
146 | */ |
---|