1 | // Created on 27-jul-2003 |
---|
2 | package nu.fw.jeti.jabber.elements; |
---|
3 | |
---|
4 | import java.util.LinkedList; |
---|
5 | import java.util.List; |
---|
6 | |
---|
7 | /** |
---|
8 | * @author E.S. de Boer |
---|
9 | * |
---|
10 | */ |
---|
11 | public class XDataFieldBuilder |
---|
12 | { |
---|
13 | private String desc;//multi add line end |
---|
14 | public String label; |
---|
15 | public String var; |
---|
16 | public String type; |
---|
17 | private List options; |
---|
18 | public boolean required=false; |
---|
19 | private String value; //multi add line end |
---|
20 | |
---|
21 | public void reset() |
---|
22 | { |
---|
23 | desc = null; |
---|
24 | label = null; |
---|
25 | var=null; |
---|
26 | type=null; |
---|
27 | options = null; |
---|
28 | required=false; |
---|
29 | value=null; |
---|
30 | } |
---|
31 | |
---|
32 | /** |
---|
33 | * adds a description (multiple calls wil be added with an added end of line) |
---|
34 | * @param description |
---|
35 | */ |
---|
36 | public void addDescription(String description) |
---|
37 | { |
---|
38 | if(desc == null) desc = description; |
---|
39 | else |
---|
40 | { |
---|
41 | desc = desc + "\n" + description; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | public String getDescription() |
---|
46 | { |
---|
47 | return desc; |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * adds a value (multiple calls wil be added with an added end of line) |
---|
52 | * @param value |
---|
53 | */ |
---|
54 | public void addValue(String value) |
---|
55 | { |
---|
56 | if(this.value == null) this.value = value; |
---|
57 | else |
---|
58 | { |
---|
59 | this.value = this.value + "\n" + value; |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | public String getValue() |
---|
64 | { |
---|
65 | return value; |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * adds an option |
---|
70 | * @param value |
---|
71 | */ |
---|
72 | public void addOption(String value) |
---|
73 | { |
---|
74 | addOption(null,value); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * adds an option |
---|
79 | * @param label optional label |
---|
80 | * @param value |
---|
81 | */ |
---|
82 | public void addOption(String label, String value) |
---|
83 | { |
---|
84 | if(options == null) options = new LinkedList(); |
---|
85 | options.add(new String[]{label,value}); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * returns options as a List containing String[] |
---|
90 | * with on position 0 the label and on position 1 the value |
---|
91 | * @return List |
---|
92 | */ |
---|
93 | public List getOptions() |
---|
94 | { |
---|
95 | return options; |
---|
96 | } |
---|
97 | |
---|
98 | public XDataField build() |
---|
99 | { |
---|
100 | checkType(); |
---|
101 | return new XDataField(this); |
---|
102 | } |
---|
103 | |
---|
104 | private void checkType() |
---|
105 | { |
---|
106 | if(type == null) type = "text-single"; |
---|
107 | else if(type.equals("boolean") || type.equals("fixed") || type.equals("hidden") || type.equals("jid-multi")|| type.equals("jid-single")|| type.equals("list-multi")|| type.equals("list-single")|| type.equals("text-multi")|| type.equals("text-private")|| type.equals("text-single")); |
---|
108 | else type = "text-single"; |
---|
109 | } |
---|
110 | |
---|
111 | } |
---|
112 | /* |
---|
113 | * Overrides for emacs |
---|
114 | * Local variables: |
---|
115 | * tab-width: 4 |
---|
116 | * End: |
---|
117 | */ |
---|