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