001/* 002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 003 * 004 * This software is open source. 005 * See the bottom of this file for the licence. 006 * 007 * $Id: DocumentResult.java,v 1.1 2001/04/09 07:47:58 jstrachan Exp $ 008 */ 009 010package org.dom4j.io; 011 012import javax.xml.transform.Result; 013import javax.xml.transform.sax.SAXResult; 014 015import org.dom4j.Document; 016import org.dom4j.Node; 017 018import org.xml.sax.ContentHandler; 019import org.xml.sax.ext.LexicalHandler; 020 021/** <p><code>DocumentResult</code> implements a JAXP {@link Result} 022 * for a {@link Document}.</p> 023 * 024 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> 025 * @version $Revision: 1.1 $ 026 */ 027public class DocumentResult extends SAXResult { 028 029 private SAXContentHandler contentHandler; 030 031 032 public DocumentResult() { 033 this( new SAXContentHandler() ); 034 } 035 036 public DocumentResult(SAXContentHandler contentHandler) { 037 this.contentHandler = contentHandler; 038 super.setHandler( this.contentHandler ); 039 super.setLexicalHandler( this.contentHandler ); 040 } 041 042 /** @return the Document created by the transformation 043 */ 044 public Document getDocument() { 045 return contentHandler.getDocument(); 046 } 047 048 049 // Overloaded methods 050 //------------------------------------------------------------------------- 051 052 public void setHandler(ContentHandler handler) { 053 if ( handler instanceof SAXContentHandler ) { 054 this.contentHandler = (SAXContentHandler) handler; 055 super.setHandler( this.contentHandler ); 056 } 057 } 058 059 public void setLexicalHandler(LexicalHandler handler) { 060 if ( handler instanceof SAXContentHandler ) { 061 this.contentHandler = (SAXContentHandler) handler; 062 super.setLexicalHandler( this.contentHandler ); 063 } 064 } 065} 066 067 068 069 070 071 072 073/* 074 * Redistribution and use of this software and associated documentation 075 * ("Software"), with or without modification, are permitted provided 076 * that the following conditions are met: 077 * 078 * 1. Redistributions of source code must retain copyright 079 * statements and notices. Redistributions must also contain a 080 * copy of this document. 081 * 082 * 2. Redistributions in binary form must reproduce the 083 * above copyright notice, this list of conditions and the 084 * following disclaimer in the documentation and/or other 085 * materials provided with the distribution. 086 * 087 * 3. The name "DOM4J" must not be used to endorse or promote 088 * products derived from this Software without prior written 089 * permission of MetaStuff, Ltd. For written permission, 090 * please contact dom4j-info@metastuff.com. 091 * 092 * 4. Products derived from this Software may not be called "DOM4J" 093 * nor may "DOM4J" appear in their names without prior written 094 * permission of MetaStuff, Ltd. DOM4J is a registered 095 * trademark of MetaStuff, Ltd. 096 * 097 * 5. Due credit should be given to the DOM4J Project 098 * (http://dom4j.org/). 099 * 100 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 101 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 102 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 103 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 104 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 105 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 106 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 107 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 108 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 109 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 110 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 111 * OF THE POSSIBILITY OF SUCH DAMAGE. 112 * 113 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 114 * 115 * $Id: DocumentResult.java,v 1.1 2001/04/09 07:47:58 jstrachan Exp $ 116 */