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