1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.rewriter.html;
18
19 import java.util.Enumeration;
20
21 import javax.swing.text.MutableAttributeSet;
22 import javax.swing.text.html.HTML;
23 import javax.swing.text.html.HTML.Attribute;
24
25 import org.apache.jetspeed.rewriter.MutableAttributes;
26
27
28 /***
29 * SwingAttributes
30 *
31 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
32 * @version $Id: SwingAttributes.java 516448 2007-03-09 16:25:47Z ate $
33 */
34 public class SwingAttributes implements MutableAttributes
35 {
36 MutableAttributeSet swingset;
37
38 public SwingAttributes(MutableAttributeSet swingset)
39 {
40 this.swingset = swingset;
41 }
42
43
44
45
46 public int getLength()
47 {
48 return swingset.getAttributeCount();
49 }
50
51
52
53
54 public String getURI(int index)
55 {
56 return "";
57 }
58
59
60
61
62 public String getLocalName(int index)
63 {
64 Enumeration e = swingset.getAttributeNames();
65 int ix = 0;
66 while (e.hasMoreElements())
67 {
68 Object object = e.nextElement();
69 if (ix == index)
70 {
71 return object.toString();
72 }
73 }
74 return null;
75 }
76
77
78
79
80 public String getQName(int index)
81 {
82 return getLocalName(index);
83 }
84
85
86
87
88 public String getType(int index)
89 {
90 return "CDATA";
91 }
92
93
94
95
96 public String getValue(int index)
97 {
98 Enumeration e = swingset.getAttributeNames();
99 int ix = 0;
100 while (e.hasMoreElements())
101 {
102 Object object = e.nextElement();
103 if (ix == index)
104 {
105 return (String)swingset.getAttribute(object);
106 }
107 }
108 return null;
109 }
110
111
112
113
114 public int getIndex(String uri, String localPart)
115 {
116 return getIndex(localPart);
117 }
118
119
120
121
122 public int getIndex(String qName)
123 {
124 Enumeration e = swingset.getAttributeNames();
125 int ix = 0;
126 while (e.hasMoreElements())
127 {
128 String name = (String)e.nextElement();
129 if (name.equalsIgnoreCase(qName))
130 {
131 return ix;
132 }
133 }
134 return -1;
135 }
136
137
138
139
140 public String getType(String uri, String localName)
141 {
142 return "CDATA";
143 }
144
145
146
147
148 public String getType(String qName)
149 {
150 return "CDATA";
151 }
152
153
154
155
156 public String getValue(String uri, String localName)
157 {
158 return getValue(localName);
159 }
160
161
162
163
164 public String getValue(String qName)
165 {
166 Attribute att = HTML.getAttributeKey(qName.toLowerCase());
167 return (String)swingset.getAttribute(att);
168 }
169
170
171
172
173 public void addAttribute(String name, Object value)
174 {
175 Attribute att = HTML.getAttributeKey(name.toLowerCase());
176 swingset.addAttribute(att, value);
177 }
178
179 }