[3952] | 1 | package nu.fw.jeti.jabber.elements; |
---|
| 2 | |
---|
| 3 | import java.util.Collections; |
---|
| 4 | import java.util.Iterator; |
---|
| 5 | import java.util.List; |
---|
| 6 | |
---|
| 7 | import nu.fw.jeti.jabber.Backend; |
---|
| 8 | import nu.fw.jeti.jabber.JID; |
---|
| 9 | /** |
---|
| 10 | * @author E.S. de Boer |
---|
| 11 | * @version 1.0 |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | public class IQBrowse extends Extension implements IQExtension, DiscoveryItem, DiscoveryInfo |
---|
| 15 | { |
---|
| 16 | private List namespaces; |
---|
| 17 | private String name; |
---|
| 18 | private String type; |
---|
| 19 | private String category; |
---|
| 20 | private String version; |
---|
| 21 | private JID jid; |
---|
| 22 | private List childItems; |
---|
| 23 | |
---|
| 24 | public IQBrowse() |
---|
| 25 | { |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | public IQBrowse(JID jid) |
---|
| 29 | { |
---|
| 30 | this.jid = jid; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | public IQBrowse(IQBrowseBuilder ib) |
---|
| 35 | { |
---|
| 36 | name = ib.getName(); |
---|
| 37 | jid = ib.getJID(); |
---|
| 38 | category = ib.getCategory(); |
---|
| 39 | type = ib.getType(); |
---|
| 40 | version = ib.getVersion(); |
---|
| 41 | namespaces = ib.getNamespaces(); |
---|
| 42 | childItems = ib.getItems(); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | public String getName(){return name;} |
---|
| 47 | |
---|
| 48 | public String getType(){return type;} |
---|
| 49 | |
---|
| 50 | public String getCategory(){return category;} |
---|
| 51 | |
---|
| 52 | public JID getJID(){return jid;} |
---|
| 53 | |
---|
| 54 | public Iterator getItems() |
---|
| 55 | { |
---|
| 56 | if(childItems == null) return null; |
---|
| 57 | return childItems.iterator(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | public int getSize() |
---|
| 61 | { |
---|
| 62 | if(childItems == null) return 0; |
---|
| 63 | return childItems.size(); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | public boolean hasItems(){return childItems != null;} |
---|
| 67 | |
---|
| 68 | public List getFeatures() |
---|
| 69 | { |
---|
| 70 | return Collections.unmodifiableList(namespaces); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | // public StringArray getNamespaces() |
---|
| 74 | // { |
---|
| 75 | // return namespaces; |
---|
| 76 | // } |
---|
| 77 | |
---|
| 78 | public boolean hasFeatures(){return namespaces != null;} |
---|
| 79 | |
---|
| 80 | public void appendToXMLNoIQ(StringBuffer xml) |
---|
| 81 | { |
---|
| 82 | xml.append("<item"); |
---|
| 83 | toXML(xml); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | public void execute(InfoQuery iq,Backend backend) |
---|
| 87 | { |
---|
| 88 | |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | public void appendToXML(StringBuffer xml) |
---|
| 92 | { |
---|
| 93 | xml.append("<item xmlns='jabber:iq:browse'"); |
---|
| 94 | toXML(xml); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | private void toXML(StringBuffer xml) |
---|
| 98 | { |
---|
| 99 | appendAttribute(xml,"jid",jid); |
---|
| 100 | appendAttribute(xml,"category",category); |
---|
| 101 | appendAttribute(xml,"type",type); |
---|
| 102 | appendAttribute(xml,"name",name); |
---|
| 103 | appendAttribute(xml,"version",version); |
---|
| 104 | if(namespaces == null && childItems == null) |
---|
| 105 | { //short cut |
---|
| 106 | xml.append("/>"); |
---|
| 107 | return; |
---|
| 108 | } |
---|
| 109 | xml.append('>'); |
---|
| 110 | if(namespaces !=null) |
---|
| 111 | { |
---|
| 112 | for(Iterator i = namespaces.iterator();i.hasNext();) |
---|
| 113 | { |
---|
| 114 | appendElement(xml,"ns",i.next()); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | if(childItems != null) |
---|
| 118 | { |
---|
| 119 | for(Iterator i = childItems.iterator();i.hasNext();) |
---|
| 120 | { |
---|
| 121 | ((IQBrowse)i.next()).appendToXMLNoIQ(xml); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | xml.append("</item>"); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | /* |
---|
| 128 | * Overrides for emacs |
---|
| 129 | * Local variables: |
---|
| 130 | * tab-width: 4 |
---|
| 131 | * End: |
---|
| 132 | */ |
---|