1 | |
|
2 | |
|
3 | |
|
4 | |
package net.sf.jolene.html; |
5 | |
|
6 | |
import java.util.*; |
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
public class Attributes implements IAttributes { |
15 | |
|
16 | |
private SortedMap<String, String> attributes; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | 2618 | public Attributes() { |
22 | 2618 | attributes = new TreeMap<String, String>(); |
23 | 2618 | } |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public String setAttribute(String key, String value) { |
33 | |
|
34 | 5567 | if (value == null) { |
35 | 1 | value = ""; |
36 | |
} |
37 | 5567 | return attributes.put(key.toLowerCase(), value); |
38 | |
} |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public String getAttribute(String key) { |
47 | 6767 | if (key == null) { |
48 | 0 | return null; |
49 | |
} |
50 | 6767 | return attributes.get(key.toLowerCase()); |
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public String removeAttribute(String key) { |
60 | 2 | return attributes.remove(key.toLowerCase()); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public boolean hasAttribute(String key) { |
70 | 2165 | if (key == null) { |
71 | 2 | return false; |
72 | |
} |
73 | 2163 | return getAttribute(key.toLowerCase()) != null; |
74 | |
} |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public Set<String> keySet() { |
82 | 1227 | return attributes.keySet(); |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public Collection<String> values() { |
91 | 0 | return attributes.values(); |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void clear() { |
99 | 0 | attributes.clear(); |
100 | 0 | } |
101 | |
|
102 | |
@Override |
103 | |
public String toString() { |
104 | 1 | Iterator<String> it = keySet().iterator(); |
105 | 1 | StringBuilder s = new StringBuilder(""); |
106 | 4 | while (it.hasNext()) { |
107 | 3 | String key = it.next(); |
108 | 3 | s.append(key).append('=').append(getAttribute(key)).append(' '); |
109 | 3 | } |
110 | 1 | return s.toString(); |
111 | |
} |
112 | |
} |