|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| package org.dom4j.xpp; |
|
9 |
| |
|
10 |
| import java.util.ArrayList; |
|
11 |
| import java.util.Iterator; |
|
12 |
| |
|
13 |
| import org.dom4j.Attribute; |
|
14 |
| import org.dom4j.DocumentFactory; |
|
15 |
| import org.dom4j.Element; |
|
16 |
| import org.dom4j.QName; |
|
17 |
| import org.dom4j.tree.AbstractElement; |
|
18 |
| |
|
19 |
| import org.gjt.xpp.XmlPullParserException; |
|
20 |
| import org.gjt.xpp.XmlStartTag; |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| public class ProxyXmlStartTag implements XmlStartTag { |
|
31 |
| |
|
32 |
| private Element element; |
|
33 |
| |
|
34 |
| |
|
35 |
| private DocumentFactory factory = DocumentFactory.getInstance(); |
|
36 |
| |
|
37 |
0
| public ProxyXmlStartTag() {
|
|
38 |
| } |
|
39 |
| |
|
40 |
0
| public ProxyXmlStartTag(Element element) {
|
|
41 |
0
| this.element = element;
|
|
42 |
| } |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
0
| public void resetStartTag() {
|
|
47 |
0
| this.element = null;
|
|
48 |
| } |
|
49 |
| |
|
50 |
0
| public int getAttributeCount() {
|
|
51 |
0
| return (element != null) ? element.attributeCount() : 0;
|
|
52 |
| } |
|
53 |
| |
|
54 |
0
| public String getAttributeNamespaceUri(int index) {
|
|
55 |
0
| if (element != null) {
|
|
56 |
0
| Attribute attribute = element.attribute(index);
|
|
57 |
| |
|
58 |
0
| if (attribute != null) {
|
|
59 |
0
| return attribute.getNamespaceURI();
|
|
60 |
| } |
|
61 |
| } |
|
62 |
| |
|
63 |
0
| return null;
|
|
64 |
| } |
|
65 |
| |
|
66 |
0
| public String getAttributeLocalName(int index) {
|
|
67 |
0
| if (element != null) {
|
|
68 |
0
| Attribute attribute = element.attribute(index);
|
|
69 |
| |
|
70 |
0
| if (attribute != null) {
|
|
71 |
0
| return attribute.getName();
|
|
72 |
| } |
|
73 |
| } |
|
74 |
| |
|
75 |
0
| return null;
|
|
76 |
| } |
|
77 |
| |
|
78 |
0
| public String getAttributePrefix(int index) {
|
|
79 |
0
| if (element != null) {
|
|
80 |
0
| Attribute attribute = element.attribute(index);
|
|
81 |
| |
|
82 |
0
| if (attribute != null) {
|
|
83 |
0
| String prefix = attribute.getNamespacePrefix();
|
|
84 |
| |
|
85 |
0
| if ((prefix != null) && (prefix.length() > 0)) {
|
|
86 |
0
| return prefix;
|
|
87 |
| } |
|
88 |
| } |
|
89 |
| } |
|
90 |
| |
|
91 |
0
| return null;
|
|
92 |
| } |
|
93 |
| |
|
94 |
0
| public String getAttributeRawName(int index) {
|
|
95 |
0
| if (element != null) {
|
|
96 |
0
| Attribute attribute = element.attribute(index);
|
|
97 |
| |
|
98 |
0
| if (attribute != null) {
|
|
99 |
0
| return attribute.getQualifiedName();
|
|
100 |
| } |
|
101 |
| } |
|
102 |
| |
|
103 |
0
| return null;
|
|
104 |
| } |
|
105 |
| |
|
106 |
0
| public String getAttributeValue(int index) {
|
|
107 |
0
| if (element != null) {
|
|
108 |
0
| Attribute attribute = element.attribute(index);
|
|
109 |
| |
|
110 |
0
| if (attribute != null) {
|
|
111 |
0
| return attribute.getValue();
|
|
112 |
| } |
|
113 |
| } |
|
114 |
| |
|
115 |
0
| return null;
|
|
116 |
| } |
|
117 |
| |
|
118 |
0
| public String getAttributeValueFromRawName(String rawName) {
|
|
119 |
0
| if (element != null) {
|
|
120 |
0
| for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
|
|
121 |
0
| Attribute attribute = (Attribute) iter.next();
|
|
122 |
| |
|
123 |
0
| if (rawName.equals(attribute.getQualifiedName())) {
|
|
124 |
0
| return attribute.getValue();
|
|
125 |
| } |
|
126 |
| } |
|
127 |
| } |
|
128 |
| |
|
129 |
0
| return null;
|
|
130 |
| } |
|
131 |
| |
|
132 |
0
| public String getAttributeValueFromName(String namespaceURI,
|
|
133 |
| String localName) { |
|
134 |
0
| if (element != null) {
|
|
135 |
0
| for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
|
|
136 |
0
| Attribute attribute = (Attribute) iter.next();
|
|
137 |
| |
|
138 |
0
| if (namespaceURI.equals(attribute.getNamespaceURI())
|
|
139 |
| && localName.equals(attribute.getName())) { |
|
140 |
0
| return attribute.getValue();
|
|
141 |
| } |
|
142 |
| } |
|
143 |
| } |
|
144 |
| |
|
145 |
0
| return null;
|
|
146 |
| } |
|
147 |
| |
|
148 |
0
| public boolean isAttributeNamespaceDeclaration(int index) {
|
|
149 |
0
| if (element != null) {
|
|
150 |
0
| Attribute attribute = element.attribute(index);
|
|
151 |
| |
|
152 |
0
| if (attribute != null) {
|
|
153 |
0
| return "xmlns".equals(attribute.getNamespacePrefix());
|
|
154 |
| } |
|
155 |
| } |
|
156 |
| |
|
157 |
0
| return false;
|
|
158 |
| } |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
0
| public void addAttribute(String namespaceURI, String localName,
|
|
171 |
| String rawName, String value) throws XmlPullParserException { |
|
172 |
0
| QName qname = QName.get(rawName, namespaceURI);
|
|
173 |
0
| element.addAttribute(qname, value);
|
|
174 |
| } |
|
175 |
| |
|
176 |
0
| public void addAttribute(String namespaceURI, String localName,
|
|
177 |
| String rawName, String value, boolean isNamespaceDeclaration) |
|
178 |
| throws XmlPullParserException { |
|
179 |
0
| if (isNamespaceDeclaration) {
|
|
180 |
0
| String prefix = "";
|
|
181 |
0
| int idx = rawName.indexOf(':');
|
|
182 |
| |
|
183 |
0
| if (idx > 0) {
|
|
184 |
0
| prefix = rawName.substring(0, idx);
|
|
185 |
| } |
|
186 |
| |
|
187 |
0
| element.addNamespace(prefix, namespaceURI);
|
|
188 |
| } else { |
|
189 |
0
| QName qname = QName.get(rawName, namespaceURI);
|
|
190 |
0
| element.addAttribute(qname, value);
|
|
191 |
| } |
|
192 |
| } |
|
193 |
| |
|
194 |
0
| public void ensureAttributesCapacity(int minCapacity)
|
|
195 |
| throws XmlPullParserException { |
|
196 |
0
| if (element instanceof AbstractElement) {
|
|
197 |
0
| AbstractElement elementImpl = (AbstractElement) element;
|
|
198 |
0
| elementImpl.ensureAttributesCapacity(minCapacity);
|
|
199 |
| } |
|
200 |
| } |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
0
| public void removeAtttributes() throws XmlPullParserException {
|
|
208 |
0
| removeAttributes();
|
|
209 |
| } |
|
210 |
| |
|
211 |
0
| public void removeAttributes() throws XmlPullParserException {
|
|
212 |
0
| if (element != null) {
|
|
213 |
0
| element.setAttributes(new ArrayList());
|
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| } |
|
219 |
| } |
|
220 |
| |
|
221 |
0
| public String getLocalName() {
|
|
222 |
0
| return element.getName();
|
|
223 |
| } |
|
224 |
| |
|
225 |
0
| public String getNamespaceUri() {
|
|
226 |
0
| return element.getNamespaceURI();
|
|
227 |
| } |
|
228 |
| |
|
229 |
0
| public String getPrefix() {
|
|
230 |
0
| return element.getNamespacePrefix();
|
|
231 |
| } |
|
232 |
| |
|
233 |
0
| public String getRawName() {
|
|
234 |
0
| return element.getQualifiedName();
|
|
235 |
| } |
|
236 |
| |
|
237 |
0
| public void modifyTag(String namespaceURI, String lName, String rawName) {
|
|
238 |
0
| this.element = factory.createElement(rawName, namespaceURI);
|
|
239 |
| } |
|
240 |
| |
|
241 |
0
| public void resetTag() {
|
|
242 |
0
| this.element = null;
|
|
243 |
| } |
|
244 |
| |
|
245 |
0
| public boolean removeAttributeByName(String namespaceURI, String localName)
|
|
246 |
| throws XmlPullParserException { |
|
247 |
0
| if (element != null) {
|
|
248 |
0
| QName qname = QName.get(localName, namespaceURI);
|
|
249 |
0
| Attribute attribute = element.attribute(qname);
|
|
250 |
0
| return element.remove(attribute);
|
|
251 |
| } |
|
252 |
0
| return false;
|
|
253 |
| } |
|
254 |
| |
|
255 |
0
| public boolean removeAttributeByRawName(String rawName)
|
|
256 |
| throws XmlPullParserException { |
|
257 |
0
| if (element != null) {
|
|
258 |
0
| Attribute attribute = null;
|
|
259 |
0
| Iterator it = element.attributeIterator();
|
|
260 |
0
| while (it.hasNext()) {
|
|
261 |
0
| Attribute current = (Attribute) it.next();
|
|
262 |
0
| if (current.getQualifiedName().equals(rawName)) {
|
|
263 |
0
| attribute = current;
|
|
264 |
0
| break;
|
|
265 |
| } |
|
266 |
| } |
|
267 |
0
| return element.remove(attribute);
|
|
268 |
| } |
|
269 |
0
| return false;
|
|
270 |
| } |
|
271 |
| |
|
272 |
| |
|
273 |
| |
|
274 |
0
| public DocumentFactory getDocumentFactory() {
|
|
275 |
0
| return factory;
|
|
276 |
| } |
|
277 |
| |
|
278 |
0
| public void setDocumentFactory(DocumentFactory documentFactory) {
|
|
279 |
0
| this.factory = documentFactory;
|
|
280 |
| } |
|
281 |
| |
|
282 |
0
| public Element getElement() {
|
|
283 |
0
| return element;
|
|
284 |
| } |
|
285 |
| } |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
| |
|
315 |
| |
|
316 |
| |
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |