Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 269   Methods: 25
NCLOC: 160   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ProxyXmlStartTag.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Copyright 2001-2004 (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    * $Id: ProxyXmlStartTag.java,v 1.6 2004/06/25 08:03:43 maartenc Exp $
 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    /** <p><code>ProxyXmlStartTag</code> implements the XPP XmlSmartTag
 24    * interface while creating a dom4j Element underneath.</p>
 25    *
 26    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 27    * @version $Revision: 1.6 $
 28    */
 29    public class ProxyXmlStartTag implements XmlStartTag {
 30   
 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   
 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  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    /** parameters modeled after SAX2 attribute approach */
 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    /** remove all atribute */
 173  0 public void removeAtttributes() throws XmlPullParserException {
 174  0 if ( element != null ) {
 175  0 element.setAttributes( new ArrayList() );
 176    // ##### FIXME
 177    // adding this method would be nice...
 178    // element.clearAttributes();
 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    // Properties
 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    * Redistribution and use of this software and associated documentation
 228    * ("Software"), with or without modification, are permitted provided
 229    * that the following conditions are met:
 230    *
 231    * 1. Redistributions of source code must retain copyright
 232    * statements and notices. Redistributions must also contain a
 233    * copy of this document.
 234    *
 235    * 2. Redistributions in binary form must reproduce the
 236    * above copyright notice, this list of conditions and the
 237    * following disclaimer in the documentation and/or other
 238    * materials provided with the distribution.
 239    *
 240    * 3. The name "DOM4J" must not be used to endorse or promote
 241    * products derived from this Software without prior written
 242    * permission of MetaStuff, Ltd. For written permission,
 243    * please contact dom4j-info@metastuff.com.
 244    *
 245    * 4. Products derived from this Software may not be called "DOM4J"
 246    * nor may "DOM4J" appear in their names without prior written
 247    * permission of MetaStuff, Ltd. DOM4J is a registered
 248    * trademark of MetaStuff, Ltd.
 249    *
 250    * 5. Due credit should be given to the DOM4J Project -
 251    * http://www.dom4j.org
 252    *
 253    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 254    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 255    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 256    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 257    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 258    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 259    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 260    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 261    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 262    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 263    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 264    * OF THE POSSIBILITY OF SUCH DAMAGE.
 265    *
 266    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 267    *
 268    * $Id: ProxyXmlStartTag.java,v 1.6 2004/06/25 08:03:43 maartenc Exp $
 269    */