Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 193   Methods: 11
NCLOC: 106   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractDocumentType.java 40,9% 52,4% 54,5% 50%
coverage 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: AbstractDocumentType.java,v 1.15 2004/06/25 08:03:41 maartenc Exp $
 8    */
 9   
 10    package org.dom4j.tree;
 11   
 12    import java.io.IOException;
 13    import java.io.Writer;
 14    import java.util.Iterator;
 15    import java.util.List;
 16   
 17    import org.dom4j.DocumentType;
 18    import org.dom4j.Element;
 19    import org.dom4j.Visitor;
 20   
 21    /** <p><code>AbstractDocumentType</code> is an abstract base class for
 22    * tree implementors to use for implementation inheritence.</p>
 23    *
 24    * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
 25    * @version $Revision: 1.15 $
 26    */
 27    public abstract class AbstractDocumentType extends AbstractNode implements DocumentType {
 28   
 29  28 public AbstractDocumentType() {
 30    }
 31   
 32  2 public short getNodeType() {
 33  2 return DOCUMENT_TYPE_NODE;
 34    }
 35   
 36  4 public String getName() {
 37  4 return getElementName();
 38    }
 39   
 40  0 public void setName(String name) {
 41  0 setElementName(name);
 42    }
 43   
 44  0 public String getPath(Element context) {
 45    // not available in XPath
 46  0 return "";
 47    }
 48   
 49  0 public String getUniquePath(Element context) {
 50    // not available in XPath
 51  0 return "";
 52    }
 53   
 54    /** Returns the text format of the declarations if applicable, or the empty String */
 55  0 public String getText() {
 56  0 List list = getInternalDeclarations();
 57  0 if ( list != null && list.size() > 0 ) {
 58  0 StringBuffer buffer = new StringBuffer();
 59  0 Iterator iter = list.iterator();
 60  0 if ( iter.hasNext() ) {
 61  0 Object decl = iter.next();
 62  0 buffer.append( decl.toString() );
 63  0 while ( iter.hasNext() ) {
 64  0 decl = iter.next();
 65  0 buffer.append( "\n" );
 66  0 buffer.append( decl.toString() );
 67    }
 68    }
 69  0 return buffer.toString();
 70    }
 71  0 return "";
 72    }
 73  12 public String toString() {
 74  12 return super.toString() + " [DocumentType: " + asXML() + "]";
 75    }
 76   
 77  12 public String asXML() {
 78  12 StringBuffer buffer = new StringBuffer( "<!DOCTYPE " );
 79  12 buffer.append( getElementName() );
 80   
 81  12 boolean hasPublicID = false;
 82  12 String publicID = getPublicID();
 83   
 84  12 if ( publicID != null && publicID.length() > 0 ) {
 85  0 buffer.append( " PUBLIC \"" );
 86  0 buffer.append( publicID );
 87  0 buffer.append( "\"" );
 88  0 hasPublicID = true;
 89    }
 90   
 91  12 String systemID = getSystemID();
 92  12 if ( systemID != null && systemID.length() > 0 ) {
 93  8 if (!hasPublicID) {
 94  8 buffer.append(" SYSTEM");
 95    }
 96  8 buffer.append( " \"" );
 97  8 buffer.append( systemID );
 98  8 buffer.append( "\"" );
 99    }
 100  12 buffer.append(">");
 101  12 return buffer.toString();
 102    }
 103   
 104  2 public void write(Writer writer) throws IOException {
 105  2 writer.write( "<!DOCTYPE " );
 106  2 writer.write( getElementName() );
 107   
 108  2 boolean hasPublicID = false;
 109  2 String publicID = getPublicID();
 110   
 111  2 if ( publicID != null && publicID.length() > 0 ) {
 112  0 writer.write( " PUBLIC \"" );
 113  0 writer.write( publicID );
 114  0 writer.write( "\"" );
 115  0 hasPublicID = true;
 116    }
 117   
 118  2 String systemID = getSystemID();
 119  2 if ( systemID != null && systemID.length() > 0 ) {
 120  0 if (!hasPublicID) {
 121  0 writer.write(" SYSTEM");
 122    }
 123  0 writer.write( " \"" );
 124  0 writer.write( systemID );
 125  0 writer.write( "\"" );
 126    }
 127  2 List list = getInternalDeclarations();
 128  2 if ( list != null && list.size() > 0 ) {
 129  2 writer.write( " [" );
 130  2 for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
 131  20 Object decl = iter.next();
 132  20 writer.write( "\n " );
 133  20 writer.write( decl.toString() );
 134    }
 135  2 writer.write( "\n]" );
 136    }
 137  2 writer.write(">");
 138    }
 139   
 140  0 public void accept(Visitor visitor) {
 141  0 visitor.visit(this);
 142    }
 143    }
 144   
 145   
 146   
 147   
 148   
 149   
 150    /*
 151    * Redistribution and use of this software and associated documentation
 152    * ("Software"), with or without modification, are permitted provided
 153    * that the following conditions are met:
 154    *
 155    * 1. Redistributions of source code must retain copyright
 156    * statements and notices. Redistributions must also contain a
 157    * copy of this document.
 158    *
 159    * 2. Redistributions in binary form must reproduce the
 160    * above copyright notice, this list of conditions and the
 161    * following disclaimer in the documentation and/or other
 162    * materials provided with the distribution.
 163    *
 164    * 3. The name "DOM4J" must not be used to endorse or promote
 165    * products derived from this Software without prior written
 166    * permission of MetaStuff, Ltd. For written permission,
 167    * please contact dom4j-info@metastuff.com.
 168    *
 169    * 4. Products derived from this Software may not be called "DOM4J"
 170    * nor may "DOM4J" appear in their names without prior written
 171    * permission of MetaStuff, Ltd. DOM4J is a registered
 172    * trademark of MetaStuff, Ltd.
 173    *
 174    * 5. Due credit should be given to the DOM4J Project -
 175    * http://www.dom4j.org
 176    *
 177    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 178    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 179    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 180    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 181    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 182    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 183    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 184    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 185    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 186    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 187    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 188    * OF THE POSSIBILITY OF SUCH DAMAGE.
 189    *
 190    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 191    *
 192    * $Id: AbstractDocumentType.java,v 1.15 2004/06/25 08:03:41 maartenc Exp $
 193    */