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: XMLResult.java,v 1.2 2001/08/06 18:18:22 jstrachan Exp $ 008 */ 009 010package org.dom4j.io; 011 012import java.io.IOException; 013import java.io.OutputStream; 014import java.io.UnsupportedEncodingException; 015import java.io.Writer; 016 017import javax.xml.transform.Result; 018import javax.xml.transform.sax.SAXResult; 019 020import org.xml.sax.ContentHandler; 021import org.xml.sax.ext.LexicalHandler; 022 023/** <p><code>XMLResult</code> implements a JAXP {@link Result} 024 * for an output stream with support for pretty printing 025 * and control over how the XML is formatted.</p> 026 * 027 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 028 * @version $Revision: 1.2 $ 029 */ 030public class XMLResult extends SAXResult { 031 032 private XMLWriter xmlWriter; 033 034 035 public XMLResult() { 036 this( new XMLWriter() ); 037 } 038 039 public XMLResult(Writer writer) { 040 this( new XMLWriter( writer ) ); 041 } 042 043 public XMLResult(Writer writer, OutputFormat format) { 044 this( new XMLWriter( writer, format ) ); 045 } 046 047 public XMLResult(OutputStream out) throws UnsupportedEncodingException { 048 this( new XMLWriter( out ) ); 049 } 050 051 public XMLResult(OutputStream out, OutputFormat format) throws UnsupportedEncodingException { 052 this( new XMLWriter( out, format ) ); 053 } 054 055 public XMLResult(XMLWriter xmlWriter) { 056 super(xmlWriter); 057 this.xmlWriter = xmlWriter; 058 setLexicalHandler( xmlWriter ); 059 } 060 061 public XMLWriter getXMLWriter() { 062 return xmlWriter; 063 } 064 065 public void setXMLWriter(XMLWriter xmlWriter) { 066 this.xmlWriter = xmlWriter; 067 setHandler( xmlWriter ); 068 setLexicalHandler( xmlWriter ); 069 } 070 071 public ContentHandler getHandler() { 072 return xmlWriter; 073 } 074 075 public LexicalHandler getLexicalHandler() { 076 return xmlWriter; 077 } 078} 079 080 081 082 083 084 085 086/* 087 * Redistribution and use of this software and associated documentation 088 * ("Software"), with or without modification, are permitted provided 089 * that the following conditions are met: 090 * 091 * 1. Redistributions of source code must retain copyright 092 * statements and notices. Redistributions must also contain a 093 * copy of this document. 094 * 095 * 2. Redistributions in binary form must reproduce the 096 * above copyright notice, this list of conditions and the 097 * following disclaimer in the documentation and/or other 098 * materials provided with the distribution. 099 * 100 * 3. The name "DOM4J" must not be used to endorse or promote 101 * products derived from this Software without prior written 102 * permission of MetaStuff, Ltd. For written permission, 103 * please contact dom4j-info@metastuff.com. 104 * 105 * 4. Products derived from this Software may not be called "DOM4J" 106 * nor may "DOM4J" appear in their names without prior written 107 * permission of MetaStuff, Ltd. DOM4J is a registered 108 * trademark of MetaStuff, Ltd. 109 * 110 * 5. Due credit should be given to the DOM4J Project 111 * (http://dom4j.org/). 112 * 113 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 114 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 115 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 116 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 117 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 118 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 119 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 120 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 121 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 122 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 123 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 124 * OF THE POSSIBILITY OF SUCH DAMAGE. 125 * 126 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 127 * 128 * $Id: XMLResult.java,v 1.2 2001/08/06 18:18:22 jstrachan Exp $ 129 */