source: branches/2.2/jabberit_messenger/java_source/src/nu/fw/jeti/jabber/elements/XDataField.java @ 3102

Revision 3102, 3.0 KB checked in by amuller, 14 years ago (diff)

Ticket #986 - Efetuado merge para o Branch 2.2( atualizacao do modulo)

  • Property svn:executable set to *
Line 
1// Created on 28-jul-2003
2package nu.fw.jeti.jabber.elements;
3
4import java.util.Iterator;
5import java.util.List;
6
7/**
8 * @author E.S. de Boer
9 *
10 */
11public class XDataField extends Extension
12{
13
14                private String desc;//multi add line end
15                private List options; //more 2 each
16                private boolean required=false;
17                private String value; //multi add line end
18                private String label;
19                private String var;
20                private String type;
21         
22//               <xs:enumeration value='boolean'/>
23//               <xs:enumeration value='fixed'/>
24//               <xs:enumeration value='hidden'/>
25//               <xs:enumeration value='jid-multi'/>
26//               <xs:enumeration value='jid-single'/>
27//               <xs:enumeration value='list-multi'/>
28//               <xs:enumeration value='list-single'/>
29//               <xs:enumeration value='text-multi'/>
30//               <xs:enumeration value='text-private'/>
31//               <xs:enumeration value='text-single'/>
32                       
33                public XDataField(String var, String value)
34                {
35                         this.var = var;
36                         this.value = value;
37                }
38               
39                public XDataField(String var, String value,String type)
40                {
41                         this.var = var;
42                         this.value = value;
43                         this.type = type;
44                }
45                                 
46                public XDataField(XDataFieldBuilder builder)
47                {
48                        desc = builder.getDescription();
49                        required =builder.required;
50                        label = builder.label;
51                        var = builder.var;
52                        type = builder.type;
53                        options = builder.getOptions();
54                        value = builder.getValue();
55                }
56               
57                public String getDescription()
58                {
59                        return desc;
60                }
61               
62                public boolean hasOptions()
63                {
64                        return options!=null;
65                }
66               
67                public int getOptionsSize()
68                {
69                        return options.size(); 
70                }
71               
72                /**
73                 * returns options as array of Object[] the label is the first element
74                 * the value the second 
75                 * @return Object[]
76                 */
77                public Object[] getOptions()
78                {
79                        return options.toArray();
80                }
81               
82                /**
83                 * returns options as Object[] the label is the first element
84                 * the value the second 
85                 * @return Iterator
86                 */
87                public Iterator getOptionsIterator()
88                {
89                        return options.iterator();
90                }
91               
92                public boolean getRequired()
93                {
94                        return required;
95                }
96               
97                public String getValue()
98                {
99                        return value;
100                }
101               
102                public String getLabel()
103                {
104                        return label;
105                }
106               
107                public String getVar()
108                {
109                        return var;
110                }
111               
112                public String getType()
113                {
114                        return type;
115                }
116
117                public void appendToXML(StringBuffer xml)
118                {
119                        xml.append("<field");
120                        appendAttribute(xml,"label",label);
121                        appendAttribute(xml,"var",var);
122                        appendAttribute(xml,"type",type);
123                        xml.append(">");
124                        if(desc !=null) xml.append("<desc>" +desc+ "</desc>"); //addmultiline
125                        if(value !=null) xml.append("<value>"+ value + "</value>");//addmultiline
126                        if(required == true) xml.append("<required/>");
127                        if(options !=null)
128                        {
129                                for(Iterator i=options.iterator();i.hasNext();)
130                                {
131                                        xml.append("<option");
132                                        String[] option = (String[])i.next();
133                                        if(option[0] != null) appendAttribute(xml,"label",option[0]);
134                                        xml.append(">");
135                                        if(option[1] != null) xml.append("<value>" + option[1] + "</value>");
136                                        xml.append("</option>");
137                                }
138                        }
139                        xml.append("</field>");
140                }
141        }
142
143/*
144 * Overrides for emacs
145 * Local variables:
146 * tab-width: 4
147 * End:
148 */
Note: See TracBrowser for help on using the repository browser.