Clover coverage report - dom4j - 1.6
Coverage timestamp: vr apr 15 2005 20:44:04 GMT+01:00
file stats: LOC: 298   Methods: 25
NCLOC: 165   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ProxyXmlStartTag.java 0% 0% 0% 0%
coverage
 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    * <p>
 24    * <code>ProxyXmlStartTag</code> implements the XPP XmlSmartTag interface
 25    * while creating a dom4j Element underneath.
 26    * </p>
 27    *
 28    * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
 29    * @version $Revision: 1.8 $
 30    */
 31    public class ProxyXmlStartTag implements XmlStartTag {
 32    /** The element being constructed */
 33    private Element element;
 34   
 35    /** The factory used to create new elements */
 36    private DocumentFactory factory = DocumentFactory.getInstance();
 37   
 38  0 public ProxyXmlStartTag() {
 39    }
 40   
 41  0 public ProxyXmlStartTag(Element element) {
 42  0 this.element = element;
 43    }
 44   
 45    // XmlStartTag interface
 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   
 59  0 if (attribute != null) {
 60  0 return attribute.getNamespaceURI();
 61    }
 62    }
 63   
 64  0 return null;
 65    }
 66   
 67  0 public String getAttributeLocalName(int index) {
 68  0 if (element != null) {
 69  0 Attribute attribute = element.attribute(index);
 70   
 71  0 if (attribute != null) {
 72  0 return attribute.getName();
 73    }
 74    }
 75   
 76  0 return null;
 77    }
 78   
 79  0 public String getAttributePrefix(int index) {
 80  0 if (element != null) {
 81  0 Attribute attribute = element.attribute(index);
 82   
 83  0 if (attribute != null) {
 84  0 String prefix = attribute.getNamespacePrefix();
 85   
 86  0 if ((prefix != null) && (prefix.length() > 0)) {
 87  0 return prefix;
 88    }
 89    }
 90    }
 91   
 92  0 return null;
 93    }
 94   
 95  0 public String getAttributeRawName(int index) {
 96  0 if (element != null) {
 97  0 Attribute attribute = element.attribute(index);
 98   
 99  0 if (attribute != null) {
 100  0 return attribute.getQualifiedName();
 101    }
 102    }
 103   
 104  0 return null;
 105    }
 106   
 107  0 public String getAttributeValue(int index) {
 108  0 if (element != null) {
 109  0 Attribute attribute = element.attribute(index);
 110   
 111  0 if (attribute != null) {
 112  0 return attribute.getValue();
 113    }
 114    }
 115   
 116  0 return null;
 117    }
 118   
 119  0 public String getAttributeValueFromRawName(String rawName) {
 120  0 if (element != null) {
 121  0 for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
 122  0 Attribute attribute = (Attribute) iter.next();
 123   
 124  0 if (rawName.equals(attribute.getQualifiedName())) {
 125  0 return attribute.getValue();
 126    }
 127    }
 128    }
 129   
 130  0 return null;
 131    }
 132   
 133  0 public String getAttributeValueFromName(String namespaceURI,
 134    String localName) {
 135  0 if (element != null) {
 136  0 for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
 137  0 Attribute attribute = (Attribute) iter.next();
 138   
 139  0 if (namespaceURI.equals(attribute.getNamespaceURI())
 140    && localName.equals(attribute.getName())) {
 141  0 return attribute.getValue();
 142    }
 143    }
 144    }
 145   
 146  0 return null;
 147    }
 148   
 149  0 public boolean isAttributeNamespaceDeclaration(int index) {
 150  0 if (element != null) {
 151  0 Attribute attribute = element.attribute(index);
 152   
 153  0 if (attribute != null) {
 154  0 return "xmlns".equals(attribute.getNamespacePrefix());
 155    }
 156    }
 157   
 158  0 return false;
 159    }
 160   
 161    /**
 162    * parameters modeled after SAX2 attribute approach
 163    *
 164    * @param namespaceURI
 165    * DOCUMENT ME!
 166    * @param localName
 167    * DOCUMENT ME!
 168    * @param rawName
 169    * DOCUMENT ME!
 170    * @param value
 171    * DOCUMENT ME!
 172    *
 173    * @throws XmlPullParserException
 174    * DOCUMENT ME!
 175    */
 176  0 public void addAttribute(String namespaceURI, String localName,
 177    String rawName, String value) throws XmlPullParserException {
 178  0 QName qname = QName.get(rawName, namespaceURI);
 179  0 element.addAttribute(qname, value);
 180    }
 181   
 182  0 public void addAttribute(String namespaceURI, String localName,
 183    String rawName, String value, boolean isNamespaceDeclaration)
 184    throws XmlPullParserException {
 185  0 if (isNamespaceDeclaration) {
 186  0 String prefix = "";
 187  0 int idx = rawName.indexOf(':');
 188   
 189  0 if (idx > 0) {
 190  0 prefix = rawName.substring(0, idx);
 191    }
 192   
 193  0 element.addNamespace(prefix, namespaceURI);
 194    } else {
 195  0 QName qname = QName.get(rawName, namespaceURI);
 196  0 element.addAttribute(qname, value);
 197    }
 198    }
 199   
 200  0 public void ensureAttributesCapacity(int minCapacity)
 201    throws XmlPullParserException {
 202  0 if (element instanceof AbstractElement) {
 203  0 AbstractElement elementImpl = (AbstractElement) element;
 204  0 elementImpl.ensureAttributesCapacity(minCapacity);
 205    }
 206    }
 207   
 208    /**
 209    * remove all atribute
 210    *
 211    * @throws XmlPullParserException
 212    * DOCUMENT ME!
 213    */
 214  0 public void removeAtttributes() throws XmlPullParserException {
 215  0 if (element != null) {
 216  0 element.setAttributes(new ArrayList());
 217   
 218    // ##### FIXME
 219    // adding this method would be nice...
 220    // element.clearAttributes();
 221    }
 222    }
 223   
 224  0 public String getLocalName() {
 225  0 return element.getName();
 226    }
 227   
 228  0 public String getNamespaceUri() {
 229  0 return element.getNamespaceURI();
 230    }
 231   
 232  0 public String getPrefix() {
 233  0 return element.getNamespacePrefix();
 234    }
 235   
 236  0 public String getRawName() {
 237  0 return element.getQualifiedName();
 238    }
 239   
 240  0 public void modifyTag(String namespaceURI, String lName, String rawName) {
 241  0 this.element = factory.createElement(rawName, namespaceURI);
 242    }
 243   
 244  0 public void resetTag() {
 245  0 this.element = null;
 246    }
 247   
 248    // Properties
 249    // -------------------------------------------------------------------------
 250  0 public DocumentFactory getDocumentFactory() {
 251  0 return factory;
 252    }
 253   
 254  0 public void setDocumentFactory(DocumentFactory documentFactory) {
 255  0 this.factory = documentFactory;
 256    }
 257   
 258  0 public Element getElement() {
 259  0 return element;
 260    }
 261    }
 262   
 263    /*
 264    * Redistribution and use of this software and associated documentation
 265    * ("Software"), with or without modification, are permitted provided that the
 266    * following conditions are met:
 267    *
 268    * 1. Redistributions of source code must retain copyright statements and
 269    * notices. Redistributions must also contain a copy of this document.
 270    *
 271    * 2. Redistributions in binary form must reproduce the above copyright notice,
 272    * this list of conditions and the following disclaimer in the documentation
 273    * and/or other materials provided with the distribution.
 274    *
 275    * 3. The name "DOM4J" must not be used to endorse or promote products derived
 276    * from this Software without prior written permission of MetaStuff, Ltd. For
 277    * written permission, please contact dom4j-info@metastuff.com.
 278    *
 279    * 4. Products derived from this Software may not be called "DOM4J" nor may
 280    * "DOM4J" appear in their names without prior written permission of MetaStuff,
 281    * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
 282    *
 283    * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
 284    *
 285    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
 286    * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 287    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 288    * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
 289    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 290    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 291    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 292    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 293    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 294    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 295    * POSSIBILITY OF SUCH DAMAGE.
 296    *
 297    * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
 298    */