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: DocumentResult.java,v 1.6 2004/06/25 12:34:47 maartenc Exp $ 8 */ 9 10 package org.dom4j.io; 11 12 import javax.xml.transform.sax.SAXResult; 13 14 import org.dom4j.Document; 15 import org.xml.sax.ContentHandler; 16 import org.xml.sax.ext.LexicalHandler; 17 18 /*** 19 * <p><code>DocumentResult</code> implements a JAXP {@link SAXResult} 20 * for a {@link Document}.</p> 21 * 22 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> 23 * @version $Revision: 1.6 $ 24 */ 25 public class DocumentResult extends SAXResult { 26 27 private SAXContentHandler contentHandler; 28 29 public DocumentResult() { 30 this( new SAXContentHandler() ); 31 } 32 33 public DocumentResult(SAXContentHandler contentHandler) { 34 this.contentHandler = contentHandler; 35 super.setHandler( this.contentHandler ); 36 super.setLexicalHandler( this.contentHandler ); 37 } 38 39 /*** @return the Document created by the transformation 40 */ 41 public Document getDocument() { 42 return contentHandler.getDocument(); 43 } 44 45 46 // Overloaded methods 47 //------------------------------------------------------------------------- 48 49 public void setHandler(ContentHandler handler) { 50 if ( handler instanceof SAXContentHandler ) { 51 this.contentHandler = (SAXContentHandler) handler; 52 super.setHandler( this.contentHandler ); 53 } 54 } 55 56 public void setLexicalHandler(LexicalHandler handler) { 57 if ( handler instanceof SAXContentHandler ) { 58 this.contentHandler = (SAXContentHandler) handler; 59 super.setLexicalHandler( this.contentHandler ); 60 } 61 } 62 } 63 64 65 66 67 68 69 70 /* 71 * Redistribution and use of this software and associated documentation 72 * ("Software"), with or without modification, are permitted provided 73 * that the following conditions are met: 74 * 75 * 1. Redistributions of source code must retain copyright 76 * statements and notices. Redistributions must also contain a 77 * copy of this document. 78 * 79 * 2. Redistributions in binary form must reproduce the 80 * above copyright notice, this list of conditions and the 81 * following disclaimer in the documentation and/or other 82 * materials provided with the distribution. 83 * 84 * 3. The name "DOM4J" must not be used to endorse or promote 85 * products derived from this Software without prior written 86 * permission of MetaStuff, Ltd. For written permission, 87 * please contact dom4j-info@metastuff.com. 88 * 89 * 4. Products derived from this Software may not be called "DOM4J" 90 * nor may "DOM4J" appear in their names without prior written 91 * permission of MetaStuff, Ltd. DOM4J is a registered 92 * trademark of MetaStuff, Ltd. 93 * 94 * 5. Due credit should be given to the DOM4J Project - 95 * http://www.dom4j.org 96 * 97 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 98 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 99 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 100 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 101 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 102 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 103 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 104 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 106 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 107 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 108 * OF THE POSSIBILITY OF SUCH DAMAGE. 109 * 110 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 111 * 112 * $Id: DocumentResult.java,v 1.6 2004/06/25 12:34:47 maartenc Exp $ 113 */