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