Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 226   Methods: 17
NCLOC: 120   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractProcessingInstruction.java 60% 48,2% 29,4% 47,3%
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: AbstractProcessingInstruction.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.HashMap;
 15    import java.util.Iterator;
 16    import java.util.Map;
 17    import java.util.StringTokenizer;
 18   
 19    import org.dom4j.Element;
 20    import org.dom4j.ProcessingInstruction;
 21    import org.dom4j.Visitor;
 22   
 23    /** <p><code>AbstractProcessingInstruction</code> is an abstract base class for
 24    * tree implementors to use for implementation inheritence.</p>
 25    *
 26    * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
 27    * @version $Revision: 1.15 $
 28    */
 29    public abstract class AbstractProcessingInstruction extends AbstractNode implements ProcessingInstruction {
 30   
 31  48 public AbstractProcessingInstruction() {
 32    }
 33   
 34  42 public short getNodeType() {
 35  42 return PROCESSING_INSTRUCTION_NODE;
 36    }
 37   
 38  0 public String getPath(Element context) {
 39  0 Element parent = getParent();
 40  0 return ( parent != null && parent != context )
 41    ? parent.getPath( context ) + "/processing-instruction()"
 42    : "processing-instruction()";
 43    }
 44   
 45  0 public String getUniquePath(Element context) {
 46  0 Element parent = getParent();
 47  0 return ( parent != null && parent != context )
 48    ? parent.getUniquePath( context ) + "/processing-instruction()"
 49    : "processing-instruction()";
 50    }
 51   
 52  0 public String toString() {
 53  0 return super.toString() + " [ProcessingInstruction: &" + getName() + ";]";
 54    }
 55   
 56  0 public String asXML() {
 57  0 return "<?" + getName() + " " + getText() + "?>";
 58    }
 59   
 60  0 public void write(Writer writer) throws IOException {
 61  0 writer.write( "<?" );
 62  0 writer.write( getName() );
 63  0 writer.write( " " );
 64  0 writer.write( getText() );
 65  0 writer.write( "?>" );
 66    }
 67   
 68  0 public void accept(Visitor visitor) {
 69  0 visitor.visit(this);
 70    }
 71   
 72  0 public void setValue(String name, String value) {
 73  0 throw new UnsupportedOperationException(
 74    "This PI is read-only and cannot be modified"
 75    );
 76    }
 77   
 78  0 public void setValues(Map data) {
 79  0 throw new UnsupportedOperationException(
 80    "This PI is read-only and cannot be modified"
 81    );
 82    }
 83   
 84  0 public String getName() {
 85  0 return getTarget();
 86    }
 87   
 88  0 public void setName(String name) {
 89  0 setTarget(name);
 90    }
 91   
 92  0 public boolean removeValue(String name) {
 93  0 return false;
 94    }
 95   
 96   
 97    // Helper methods
 98   
 99    /** <p>This will convert the Map to a string representation.</p>
 100    *
 101    * @param values is a <code>Map</code> of PI data to convert
 102    */
 103  0 protected String toString(Map values) {
 104  0 StringBuffer buffer = new StringBuffer();
 105   
 106  0 for ( Iterator iter = values.entrySet().iterator(); iter.hasNext(); ) {
 107  0 Map.Entry entry = (Map.Entry) iter.next();
 108  0 String name = (String) entry.getKey();
 109  0 String value = (String) entry.getValue();
 110   
 111  0 buffer.append(name);
 112  0 buffer.append("=\"");
 113  0 buffer.append(value);
 114  0 buffer.append("\" ");
 115    }
 116    // remove the last space
 117  0 buffer.setLength(buffer.length() - 1);
 118  0 return buffer.toString();
 119    }
 120   
 121    /**<p>Parses the raw data of PI as a <code>Map</code>.</p>
 122    *
 123    * @param text <code>String</code> PI data to parse
 124    */
 125  48 protected Map parseValues(String text) {
 126  48 Map data = new HashMap();
 127   
 128  48 StringTokenizer s = new StringTokenizer(text, " =\'\"", true);
 129  48 while (s.hasMoreTokens()) {
 130  82 String name = getName(s);
 131  82 if (s.hasMoreTokens()) {
 132  70 String value = getValue(s);
 133  70 data.put(name, value);
 134    }
 135    }
 136   
 137  48 return data;
 138    }
 139   
 140  82 private String getName(StringTokenizer tokenizer) {
 141  82 String token = tokenizer.nextToken();
 142  82 StringBuffer name = new StringBuffer(token);
 143  82 while (tokenizer.hasMoreTokens()) {
 144  278 token = tokenizer.nextToken();
 145  278 if (!token.equals("=")) {
 146  208 name.append(token);
 147    } else {
 148  70 break;
 149    }
 150    }
 151   
 152  82 return name.toString().trim();
 153    }
 154   
 155  70 private String getValue(StringTokenizer tokenizer) {
 156  70 String token = tokenizer.nextToken();
 157  70 StringBuffer value = new StringBuffer();
 158   
 159    /* get the quote */
 160  70 while (tokenizer.hasMoreTokens() && !token.equals("\'") && !token.equals("\"")) {
 161  0 token = tokenizer.nextToken();
 162    }
 163   
 164  70 String quote = token;
 165  162 while (tokenizer.hasMoreTokens()) {
 166  162 token = tokenizer.nextToken();
 167  162 if (!quote.equals(token)) {
 168  92 value.append(token);
 169    } else {
 170  70 break;
 171    }
 172    }
 173   
 174  70 return value.toString();
 175    }
 176    }
 177   
 178   
 179   
 180   
 181   
 182   
 183    /*
 184    * Redistribution and use of this software and associated documentation
 185    * ("Software"), with or without modification, are permitted provided
 186    * that the following conditions are met:
 187    *
 188    * 1. Redistributions of source code must retain copyright
 189    * statements and notices. Redistributions must also contain a
 190    * copy of this document.
 191    *
 192    * 2. Redistributions in binary form must reproduce the
 193    * above copyright notice, this list of conditions and the
 194    * following disclaimer in the documentation and/or other
 195    * materials provided with the distribution.
 196    *
 197    * 3. The name "DOM4J" must not be used to endorse or promote
 198    * products derived from this Software without prior written
 199    * permission of MetaStuff, Ltd. For written permission,
 200    * please contact dom4j-info@metastuff.com.
 201    *
 202    * 4. Products derived from this Software may not be called "DOM4J"
 203    * nor may "DOM4J" appear in their names without prior written
 204    * permission of MetaStuff, Ltd. DOM4J is a registered
 205    * trademark of MetaStuff, Ltd.
 206    *
 207    * 5. Due credit should be given to the DOM4J Project -
 208    * http://www.dom4j.org
 209    *
 210    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 211    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 212    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 213    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 214    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 215    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 216    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 217    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 218    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 219    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 220    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 221    * OF THE POSSIBILITY OF SUCH DAMAGE.
 222    *
 223    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 224    *
 225    * $Id: AbstractProcessingInstruction.java,v 1.15 2004/06/25 08:03:41 maartenc Exp $
 226    */