1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.qedeq.kernel.xml.parser; |
19 |
| |
20 |
| import java.text.DateFormat; |
21 |
| import java.text.ParseException; |
22 |
| import java.text.SimpleDateFormat; |
23 |
| import java.util.Date; |
24 |
| import java.util.HashMap; |
25 |
| import java.util.Iterator; |
26 |
| import java.util.Map; |
27 |
| import java.util.SortedMap; |
28 |
| import java.util.TreeMap; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public class SimpleAttributes { |
43 |
| |
44 |
| |
45 |
| private Map map = new HashMap(); |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
23822
| public final void add(final String key, final String value) {
|
54 |
23822
| if (map.containsKey(key)) {
|
55 |
0
| throw new IllegalArgumentException(
|
56 |
| "Key " + key + " already known with value: " + map.get(key)); |
57 |
| } |
58 |
23822
| map.put(key, value);
|
59 |
| } |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
12163
| public final String getString(final String key) {
|
68 |
12163
| return (String) map.get(key);
|
69 |
| } |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
3840
| public final Integer getInteger(final String key) {
|
80 |
3840
| String value = (String) map.get(key);
|
81 |
3840
| if (value != null) {
|
82 |
3284
| value = value.trim();
|
83 |
| } |
84 |
3840
| if (value == null || value.length() == 0) {
|
85 |
556
| return null;
|
86 |
| } |
87 |
3284
| return new Integer(value);
|
88 |
| } |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
399
| public final Boolean getBoolean(final String key) {
|
99 |
399
| String value = ((String) map.get(key));
|
100 |
399
| if (value != null) {
|
101 |
45
| value = value.trim();
|
102 |
| } |
103 |
399
| if (value == null || value.length() == 0) {
|
104 |
354
| return null;
|
105 |
| } |
106 |
45
| return Boolean.valueOf(value);
|
107 |
| } |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
0
| public final Date getDate(final String key) {
|
119 |
0
| String value = (String) map.get(key);
|
120 |
0
| if (value != null) {
|
121 |
0
| value = value.trim();
|
122 |
| } |
123 |
0
| if (value == null || value.length() == 0) {
|
124 |
0
| return null;
|
125 |
| } |
126 |
0
| try {
|
127 |
0
| DateFormat formater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
128 |
0
| Date date = formater.parse(value);
|
129 |
0
| return date;
|
130 |
| } catch (ParseException e) { |
131 |
0
| throw new IllegalArgumentException(e.toString());
|
132 |
| } |
133 |
| } |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
12725
| public final String[] getKeySortedStringValues() {
|
141 |
12725
| SortedMap sorted = new TreeMap(map);
|
142 |
12725
| return (String[]) sorted.values().toArray(new String[0]);
|
143 |
| } |
144 |
| |
145 |
104
| public String toString() {
|
146 |
104
| final StringBuffer buffer = new StringBuffer();
|
147 |
104
| final Iterator iterator = map.entrySet().iterator();
|
148 |
104
| while (iterator.hasNext()) {
|
149 |
73
| Map.Entry entry = (Map.Entry) iterator.next();
|
150 |
73
| buffer.append(entry.getKey() + "=\"" + entry.getValue() + "\" ");
|
151 |
| } |
152 |
104
| return buffer.toString();
|
153 |
| } |
154 |
| |
155 |
| } |