[3102] | 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/IM me at jeti@jabber.org |
---|
| 21 | * |
---|
| 22 | * Created on 26-jul-2003 |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | package nu.fw.jeti.jabber.elements; |
---|
| 26 | |
---|
| 27 | import java.util.Iterator; |
---|
| 28 | import java.util.LinkedList; |
---|
| 29 | import java.util.List; |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * @author E.S. de Boer |
---|
| 33 | * X-data |
---|
| 34 | */ |
---|
| 35 | public class XData extends Extension implements XExtension |
---|
| 36 | { |
---|
| 37 | private String instructions; //multi add line end |
---|
| 38 | private String title; |
---|
| 39 | private String type; |
---|
| 40 | private List fields; |
---|
| 41 | private List reported; |
---|
| 42 | private List items; |
---|
| 43 | |
---|
| 44 | public XData(){} |
---|
| 45 | |
---|
| 46 | public XData(String type){this.type = type;} |
---|
| 47 | |
---|
| 48 | public XData(XDataBuilder builder) |
---|
| 49 | { |
---|
| 50 | instructions = builder.getInstructions(); |
---|
| 51 | title = builder.title; |
---|
| 52 | type = builder.type; |
---|
| 53 | fields = builder.getFields(); |
---|
| 54 | items = builder.getItems(); |
---|
| 55 | reported = builder.getReported(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | public String getType() |
---|
| 59 | { |
---|
| 60 | return type; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | public String getInstructions() |
---|
| 64 | { |
---|
| 65 | return instructions; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | public String getTitle() |
---|
| 69 | { |
---|
| 70 | return title; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | public boolean hasFields() |
---|
| 74 | { |
---|
| 75 | return fields != null; |
---|
| 76 | |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | public Iterator getFields() |
---|
| 80 | { |
---|
| 81 | return fields.iterator(); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | public XDataField getField(int index) |
---|
| 85 | { |
---|
| 86 | return (XDataField)fields.get(index); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public boolean hasItems() |
---|
| 90 | { |
---|
| 91 | return items!=null; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | public Iterator getReported() |
---|
| 95 | { |
---|
| 96 | return reported.iterator(); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | public List getItems() |
---|
| 100 | { |
---|
| 101 | return new LinkedList(items); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | public void appendToXML(StringBuffer xml) |
---|
| 106 | { |
---|
| 107 | xml.append("<x xmlns='jabber:x:data'"); |
---|
| 108 | appendAttribute(xml,"type",type); |
---|
| 109 | xml.append(">"); |
---|
| 110 | if(instructions !=null) xml.append("<instructions>"+ instructions + "</instructions>"); |
---|
| 111 | if(title != null)xml.append("<title>" + title + "</title>"); |
---|
| 112 | if(fields !=null) |
---|
| 113 | { |
---|
| 114 | for(Iterator i = fields.iterator();i.hasNext();) |
---|
| 115 | { |
---|
| 116 | ((XDataField)i.next()).appendToXML(xml); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | xml.append("</x>"); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /* |
---|
| 125 | * Overrides for emacs |
---|
| 126 | * Local variables: |
---|
| 127 | * tab-width: 4 |
---|
| 128 | * End: |
---|
| 129 | */ |
---|