Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 232   Methods: 7
NCLOC: 142   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NonVerifyingHandler.java 100% 100% 100% 100%
coverage
 1    /* Copyright 2002-2006 Elliotte Rusty Harold
 2   
 3    This library is free software; you can redistribute it and/or modify
 4    it under the terms of version 2.1 of the GNU Lesser General Public
 5    License as published by the Free Software Foundation.
 6   
 7    This library is distributed in the hope that it will be useful,
 8    but WITHOUT ANY WARRANTY; without even the implied warranty of
 9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 10    GNU Lesser General Public License for more details.
 11   
 12    You should have received a copy of the GNU Lesser General Public
 13    License along with this library; if not, write to the
 14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 15    Boston, MA 02111-1307 USA
 16   
 17    You can contact Elliotte Rusty Harold by sending e-mail to
 18    elharo@metalab.unc.edu. Please include the word "XOM" in the
 19    subject line. The XOM home page is located at http://www.xom.nu/
 20    */
 21   
 22   
 23    package nu.xom;
 24   
 25    /**
 26    * @author Elliotte Rusty Harold
 27    * @version 1.2d1
 28    *
 29    */
 30    class NonVerifyingHandler extends XOMHandler {
 31   
 32  1079 NonVerifyingHandler(NodeFactory factory) {
 33  1079 super(factory);
 34    }
 35   
 36   
 37  2164210 public void startElement(String namespaceURI, String localName,
 38    String qualifiedName, org.xml.sax.Attributes attributes) {
 39   
 40  2164210 flushText();
 41  2164210 Element element = Element.build(qualifiedName, namespaceURI, localName);
 42  2164200 if (parent == document) { // root
 43  22015 document.setRootElement(element);
 44  22015 inProlog = false;
 45    }
 46   
 47  2164200 current = element;
 48    // Need to push this, even if it's null
 49  2164200 parents.add(element);
 50   
 51  2164200 if (parent != document) {
 52    // a.k.a. parent not instanceof Document
 53  2142185 parent.fastInsertChild(element, parent.getChildCount());
 54    }
 55    // This is optimized for the very common case where
 56    // everything in the document has the same actual base URI.
 57    // It may add redundant base URIs in cases like XInclude
 58    // where different parts of the document have different
 59    // base URIs.
 60  2164200 String baseURI = locator.getSystemId();
 61  2164200 if (baseURI != null && !baseURI.equals(documentBaseURI)) {
 62  6086 element.setActualBaseURI(baseURI);
 63    }
 64   
 65    // Attach the attributes; this must be done before the
 66    // namespaces are attached.
 67  2164200 int length = attributes.getLength();
 68   
 69    // We've got a pretty good guess at how many attributes there
 70    // will be here; we could ensureCapacity up to that length.
 71    // However, that might waste memory because we wouldn't use
 72    // the ones for namespace declarations. We could always
 73    // trimToSize when we're done, but it's probably not worth
 74    // the effort.
 75  2164200 for (int i = 0; i < length; i++) {
 76  2152782 String qName = attributes.getQName(i);
 77  2152782 if (qName.startsWith("xmlns:") || qName.equals("xmlns")) {
 78  2490 continue;
 79    }
 80    else {
 81  2150292 String namespace = attributes.getURI(i);
 82  2150292 String value = attributes.getValue(i);
 83  2150292 Attribute attribute = Attribute.build(
 84    qName,
 85    namespace,
 86    value,
 87    convertStringToType(attributes.getType(i)),
 88    attributes.getLocalName(i)
 89    );
 90  2150292 element.fastAddAttribute(attribute);
 91    }
 92    }
 93   
 94    // Attach the namespaces
 95  2164200 for (int i = 0; i < length; i++) {
 96  2152771 String qName = attributes.getQName(i);
 97  2152771 if (qName.startsWith("xmlns:")) {
 98  2274 String namespaceName = attributes.getValue(i);
 99  2274 String namespacePrefix = qName.substring(6);
 100  2274 String currentValue
 101    = element.getNamespaceURI(namespacePrefix);
 102  2274 if (!namespaceName.equals(currentValue)) {
 103  1156 element.addNamespaceDeclaration(
 104    namespacePrefix, namespaceName);
 105    }
 106    }
 107  2150497 else if (qName.equals("xmlns")) {
 108  213 String namespaceName = attributes.getValue(i);
 109  213 String namespacePrefix = "";
 110  213 String currentValue
 111    = element.getNamespaceURI(namespacePrefix);
 112  213 if (!namespaceName.equals(currentValue)) {
 113  26 element.addNamespaceDeclaration(namespacePrefix,
 114    namespaceName);
 115    }
 116    }
 117    }
 118   
 119    // this is the new parent
 120  2163972 parent = element;
 121    }
 122   
 123   
 124  2163928 public void endElement(
 125    String namespaceURI, String localName, String qualifiedName) {
 126   
 127    // If we're immediately inside a skipped element
 128    // we need to reset current to null, not to the parent
 129  2163928 current = (ParentNode) parents.remove(parents.size()-1);
 130  2163928 flushText();
 131   
 132  2163928 parent = current.getParent();
 133   
 134  2163928 if (parent.isDocument()) { // root element
 135  21769 Document doc = (Document) parent;
 136  21769 doc.setRootElement((Element) current);
 137    }
 138   
 139    }
 140   
 141   
 142    // accumulate all text that's in the buffer into a text node
 143  4335025 private void flushText() {
 144   
 145  4335025 if (buffer != null) {
 146  52291 textString = buffer.toString();
 147  52291 buffer = null;
 148    }
 149   
 150  4335025 if (textString != null) {
 151  2389553 Text result;
 152  2389553 if (!inCDATA) {
 153  2389078 result = Text.build(textString);
 154    }
 155    else {
 156  475 result = CDATASection.build(textString);
 157    }
 158  2389553 parent.fastInsertChild(result, parent.getChildCount());
 159  2389553 textString = null;
 160    }
 161  4335025 inCDATA = false;
 162  4335025 finishedCDATA = false;
 163   
 164    }
 165   
 166   
 167  545 public void processingInstruction(String target, String data) {
 168   
 169    // simplify logic???? into two cases in and not in DTD
 170    // ditto for comment() method and superclass
 171  377 if (!inDTD) flushText();
 172  6 else if (!inInternalSubset()) return;
 173   
 174  539 ProcessingInstruction result = ProcessingInstruction.build(target, data);
 175   
 176  539 if (!inDTD) {
 177  377 if (inProlog) {
 178  269 parent.fastInsertChild(result, position);
 179  269 position++;
 180    }
 181    else {
 182  108 parent.fastInsertChild(result, parent.getChildCount());
 183    }
 184    }
 185    else {
 186  162 internalDTDSubset.append(" ");
 187  162 internalDTDSubset.append(result.toXML());
 188  162 internalDTDSubset.append("\n");
 189    }
 190   
 191    }
 192   
 193   
 194    // LexicalHandler events
 195  2505 public void startDTD(String rootName, String publicID,
 196    String systemID) {
 197   
 198  2505 inDTD = true;
 199  2505 DocType doctype = DocType.build(rootName, publicID, systemID);
 200  2505 document.fastInsertChild(doctype, position);
 201  2505 position++;
 202  2505 internalDTDSubset = new StringBuffer();
 203  2505 this.doctype = doctype;
 204   
 205    }
 206   
 207   
 208  13291 public void comment(char[] text, int start, int length) {
 209   
 210  6510 if (!inDTD) flushText();
 211  5812 else if (!inInternalSubset()) return;
 212   
 213  7479 Comment result = Comment.build(new String(text, start, length));
 214   
 215  7479 if (!inDTD) {
 216  6510 if (inProlog) {
 217  1326 parent.insertChild(result, position);
 218  1326 position++;
 219    }
 220    else {
 221  5184 parent.fastInsertChild(result, parent.getChildCount());
 222    }
 223    }
 224    else {
 225  969 internalDTDSubset.append(" ");
 226  969 internalDTDSubset.append(result.toXML());
 227  969 internalDTDSubset.append("\n");
 228    }
 229   
 230    }
 231   
 232    }