Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 268   Methods: 27
NCLOC: 168   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SAXModifyContentHandler.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: SAXModifyContentHandler.java,v 1.1 2004/08/02 18:44:07 maartenc Exp $
 8    */
 9   
 10    package org.dom4j.io;
 11   
 12    import java.io.IOException;
 13   
 14    import org.dom4j.DocumentFactory;
 15    import org.dom4j.Element;
 16    import org.dom4j.ElementHandler;
 17    import org.xml.sax.Attributes;
 18    import org.xml.sax.Locator;
 19    import org.xml.sax.SAXException;
 20   
 21    /**
 22    * This extension of the SAXContentHandler writes SAX events immediately to the provided XMLWriter,
 23    * unless some {@link org.dom4.ElementHandler} is still handling the current Element.
 24    *
 25    * @see org.dom4j.io.SAXContentHandler
 26    *
 27    * @author Wonne Keysers (Realsoftware.be)
 28    */
 29    class SAXModifyContentHandler extends SAXContentHandler {
 30   
 31    private XMLWriter xmlWriter;
 32   
 33  0 public SAXModifyContentHandler() {
 34    }
 35   
 36  0 public SAXModifyContentHandler(DocumentFactory documentFactory) {
 37  0 super(documentFactory);
 38    }
 39   
 40  0 public SAXModifyContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler) {
 41  0 super(documentFactory, elementHandler);
 42    }
 43   
 44  0 public SAXModifyContentHandler(DocumentFactory documentFactory, ElementHandler elementHandler,
 45    ElementStack elementStack) {
 46  0 super(documentFactory, elementHandler, elementStack);
 47    }
 48   
 49  0 public void setXMLWriter(XMLWriter xmlWriter) {
 50  0 this.xmlWriter = xmlWriter;
 51    }
 52   
 53  0 public void startCDATA() throws SAXException {
 54  0 super.startCDATA();
 55  0 if (!activeHandlers() && xmlWriter != null) {
 56  0 xmlWriter.startCDATA();
 57    }
 58    }
 59   
 60  0 public void startDTD(String name, String publicId, String systemId) throws SAXException {
 61  0 super.startDTD(name, publicId, systemId);
 62  0 if (xmlWriter != null) {
 63  0 xmlWriter.startDTD(name, publicId, systemId);
 64    }
 65    }
 66   
 67  0 public void endDTD() throws org.xml.sax.SAXException {
 68  0 super.endDTD();
 69  0 if (xmlWriter != null) {
 70  0 xmlWriter.endDTD();
 71    }
 72    }
 73   
 74  0 public void comment(char[] parm1, int parm2, int parm3) throws SAXException {
 75  0 super.comment(parm1, parm2, parm3);
 76  0 if (!activeHandlers() && xmlWriter != null) {
 77  0 xmlWriter.comment(parm1, parm2, parm3);
 78    }
 79    }
 80   
 81  0 public void startEntity(String name) throws SAXException {
 82  0 super.startEntity(name);
 83  0 if (xmlWriter != null) {
 84  0 xmlWriter.startEntity(name);
 85    }
 86    }
 87   
 88  0 public void endCDATA() throws org.xml.sax.SAXException {
 89  0 super.endCDATA();
 90  0 if (!activeHandlers() && xmlWriter != null) {
 91  0 xmlWriter.endCDATA();
 92    }
 93    }
 94   
 95  0 public void endEntity(String name) throws SAXException {
 96  0 super.endEntity(name);
 97  0 if (xmlWriter != null) {
 98  0 xmlWriter.endEntity(name);
 99    }
 100    }
 101   
 102  0 public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
 103    throws SAXException {
 104  0 super.unparsedEntityDecl(name, publicId, systemId, notationName);
 105  0 if (!activeHandlers() && xmlWriter != null) {
 106  0 xmlWriter.unparsedEntityDecl(name, publicId, systemId, notationName);
 107    }
 108    }
 109   
 110  0 public void notationDecl(String name, String publicId, String systemId) throws SAXException {
 111  0 super.notationDecl(name, publicId, systemId);
 112  0 if (xmlWriter != null) {
 113  0 xmlWriter.notationDecl(name, publicId, systemId);
 114    }
 115    }
 116   
 117  0 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
 118  0 super.startElement(uri, localName, qName, atts);
 119   
 120  0 if (!activeHandlers() && xmlWriter != null) {
 121  0 xmlWriter.startElement(uri, localName, qName, atts);
 122    }
 123    }
 124   
 125  0 public void startDocument() throws SAXException {
 126  0 super.startDocument();
 127  0 if (xmlWriter != null) {
 128  0 xmlWriter.startDocument();
 129    }
 130    }
 131   
 132  0 public void ignorableWhitespace(char[] parm1, int parm2, int parm3) throws SAXException {
 133  0 super.ignorableWhitespace(parm1, parm2, parm3);
 134  0 if (!activeHandlers() && xmlWriter != null) {
 135  0 xmlWriter.ignorableWhitespace(parm1, parm2, parm3);
 136    }
 137    }
 138   
 139  0 public void processingInstruction(String target, String data) throws SAXException {
 140  0 super.processingInstruction(target, data);
 141  0 if (!activeHandlers() && xmlWriter != null) {
 142  0 xmlWriter.processingInstruction(target, data);
 143    }
 144    }
 145   
 146  0 public void setDocumentLocator(Locator locator) {
 147  0 super.setDocumentLocator(locator);
 148  0 if (xmlWriter != null) {
 149  0 xmlWriter.setDocumentLocator(locator);
 150    }
 151    }
 152   
 153  0 public void skippedEntity(String name) throws SAXException {
 154  0 super.skippedEntity(name);
 155  0 if (!activeHandlers() && xmlWriter != null) {
 156  0 xmlWriter.skippedEntity(name);
 157    }
 158    }
 159   
 160  0 public void endDocument() throws SAXException {
 161  0 super.endDocument();
 162  0 if (xmlWriter != null) {
 163  0 xmlWriter.endDocument();
 164    }
 165    }
 166   
 167  0 public void startPrefixMapping(String prefix, String uri) throws SAXException {
 168  0 super.startPrefixMapping(prefix, uri);
 169  0 if (xmlWriter != null) {
 170  0 xmlWriter.startPrefixMapping(prefix, uri);
 171    }
 172    }
 173   
 174  0 public void endElement(String uri, String localName, String qName) throws SAXException {
 175  0 ElementHandler currentHandler = getElementStack().getDispatchHandler().getHandler(getElementStack().getPath());
 176   
 177  0 super.endElement(uri, localName, qName);
 178   
 179  0 if (!activeHandlers()) {
 180  0 if (xmlWriter != null) {
 181  0 if (currentHandler == null) {
 182  0 xmlWriter.endElement(uri, localName, qName);
 183    }
 184  0 else if (currentHandler instanceof SAXModifyElementHandler) {
 185  0 SAXModifyElementHandler modifyHandler = (SAXModifyElementHandler) currentHandler;
 186  0 Element modifiedElement = modifyHandler.getModifiedElement();
 187  0 try {
 188  0 xmlWriter.write(modifiedElement);
 189    }
 190    catch (IOException ex) {
 191  0 throw new SAXModifyException(ex);
 192    }
 193    }
 194    }
 195    }
 196    }
 197   
 198  0 public void endPrefixMapping(String prefix) throws SAXException {
 199  0 super.endPrefixMapping(prefix);
 200  0 if (xmlWriter != null) {
 201  0 xmlWriter.endPrefixMapping(prefix);
 202    }
 203    }
 204   
 205  0 public void characters(char[] parm1, int parm2, int parm3) throws SAXException {
 206  0 super.characters(parm1, parm2, parm3);
 207  0 if (!activeHandlers() && xmlWriter != null) {
 208  0 xmlWriter.characters(parm1, parm2, parm3);
 209    }
 210    }
 211   
 212  0 protected XMLWriter getXMLWriter() {
 213  0 return this.xmlWriter;
 214    }
 215   
 216  0 private boolean activeHandlers() {
 217  0 return getElementStack().getDispatchHandler().getActiveHandlerCount() > 0;
 218    }
 219   
 220    }
 221   
 222   
 223   
 224   
 225    /*
 226    * Redistribution and use of this software and associated documentation
 227    * ("Software"), with or without modification, are permitted provided
 228    * that the following conditions are met:
 229    *
 230    * 1. Redistributions of source code must retain copyright
 231    * statements and notices. Redistributions must also contain a
 232    * copy of this document.
 233    *
 234    * 2. Redistributions in binary form must reproduce the
 235    * above copyright notice, this list of conditions and the
 236    * following disclaimer in the documentation and/or other
 237    * materials provided with the distribution.
 238    *
 239    * 3. The name "DOM4J" must not be used to endorse or promote
 240    * products derived from this Software without prior written
 241    * permission of MetaStuff, Ltd. For written permission,
 242    * please contact dom4j-info@metastuff.com.
 243    *
 244    * 4. Products derived from this Software may not be called "DOM4J"
 245    * nor may "DOM4J" appear in their names without prior written
 246    * permission of MetaStuff, Ltd. DOM4J is a registered
 247    * trademark of MetaStuff, Ltd.
 248    *
 249    * 5. Due credit should be given to the DOM4J Project -
 250    * http://www.dom4j.org
 251    *
 252    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 253    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 254    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 255    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 256    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 257    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 258    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 259    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 260    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 261    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 262    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 263    * OF THE POSSIBILITY OF SUCH DAMAGE.
 264    *
 265    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 266    *
 267    * $Id: SAXModifyContentHandler.java,v 1.1 2004/08/02 18:44:07 maartenc Exp $
 268    */