Clover coverage report - dom4j - 1.6.1
Coverage timestamp: ma mei 16 2005 14:23:01 GMT+01:00

file stats: | LOC: | 322 |  | Methods: | 28
| NCLOC: | 193 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

ProxyXmlStartTag.java

0%

0%

0%

0%

1 |  | /*
2 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3 |  | *
4 |  | * This software is open source.
5 |  | * See the bottom of this file for the licence.
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 |  | * <code>ProxyXmlStartTag</code> implements the XPP <code>XmlSmartTag</code>
24 |  | * interface while creating a dom4j <code>Element</code> underneath.
25 |  | *
26 |  | * @author James Strachan
27 |  | * @author Maarten Coene
28 |  | * @author Wolfgang Baer
29 |  | */
30 |  | public class ProxyXmlStartTag implements XmlStartTag {
31 |  | /** The element being constructed */
32 |  | private Element element;
33 |  |
34 |  | /** The factory used to create new elements */
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 |  | // XmlStartTag interface
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 |  | * parameters modeled after SAX2 attribute approach
162 |  | *
163 |  | * @param namespaceURI DOCUMENT ME!
164 |  | * @param localName DOCUMENT ME!
165 |  | * @param rawName DOCUMENT ME!
166 |  | * @param value DOCUMENT ME!
167 |  | *
168 |  | * @throws XmlPullParserException DOCUMENT ME!
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 |  | * Remove all atributes.
204 |  | *
205 |  | * @deprecated Use {@link #removeAttributes()} instead.
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 |  | // ##### FIXME
216 |  | // adding this method would be nice...
217 |  | // element.clearAttributes();
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 |  | // Properties
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 |  | * Redistribution and use of this software and associated documentation
289 |  | * ("Software"), with or without modification, are permitted provided that the
290 |  | * following conditions are met:
291 |  | *
292 |  | * 1. Redistributions of source code must retain copyright statements and
293 |  | * notices. Redistributions must also contain a copy of this document.
294 |  | *
295 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
296 |  | * this list of conditions and the following disclaimer in the documentation
297 |  | * and/or other materials provided with the distribution.
298 |  | *
299 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
300 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
301 |  | * written permission, please contact dom4j-info@metastuff.com.
302 |  | *
303 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
304 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
305 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
306 |  | *
307 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
308 |  | *
309 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
310 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
311 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
312 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
313 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
314 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
315 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
316 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
317 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
318 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
319 |  | * POSSIBILITY OF SUCH DAMAGE.
320 |  | *
321 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
322 |  | */