001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xml.serialize;
059:
060: import java.io.Writer;
061: import java.io.OutputStream;
062: import java.io.IOException;
063: import java.io.UnsupportedEncodingException;
064:
065: import org.w3c.dom.Element;
066: import org.w3c.dom.Document;
067: import org.xml.sax.DocumentHandler;
068: import org.xml.sax.ContentHandler;
069:
070: /**
071: * Interface for a DOM serializer implementation, factory for DOM and SAX
072: * serializers, and static methods for serializing DOM documents.
073: * <p>
074: * To serialize a document using SAX events, create a compatible serializer
075: * using {@link #makeSAXSerializer} and pass it around as a {@link
076: * DocumentHandler}. If an I/O error occurs while serializing, it will
077: * be thrown by {@link DocumentHandler#endDocument}. The SAX serializer
078: * may also be used as {@link DTDHandler}, {@link DeclHandler} and
079: * {@link LexicalHandler}.
080: * <p>
081: * To serialize a DOM document or DOM element, create a compatible
082: * serializer using {@link #makeSerializer} and call it's {@link
083: * #serialize(Document)} or {@link #serialize(Element)} methods.
084: * Both methods would produce a full XML document, to serizlie only
085: * the portion of the document use {@link OutputFormat#setOmitXMLDeclaration}
086: * and specify no document type.
087: * <p>
088: * The convenience method {@link #serialize(Document,Writer,OutputFormat)}
089: * creates a serializer and calls {@link #serizlie(Document)} on that
090: * serialized.
091: * <p>
092: * The {@link OutputFormat} dictates what underlying serialized is used
093: * to serialize the document based on the specified method. If the output
094: * format or method are missing, the default is an XML serializer with
095: * UTF-8 encoding and now indentation.
096: *
097: *
098: * @version $Revision: 1.9 $ $Date: 2000/08/30 18:59:21 $
099: * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
100: * @author <a href="mailto:Scott_Boag/CAM/Lotus@lotus.com">Scott Boag</a>
101: * @see DocumentHandler
102: * @see ContentHandler
103: * @see OutputFormat
104: * @see DOMSerializer
105: */
106: public interface Serializer {
107:
108: /**
109: * Specifies an output stream to which the document should be
110: * serialized. This method should not be called while the
111: * serializer is in the process of serializing a document.
112: */
113: public void setOutputByteStream(OutputStream output);
114:
115: /**
116: * Specifies a writer to which the document should be serialized.
117: * This method should not be called while the serializer is in
118: * the process of serializing a document.
119: */
120: public void setOutputCharStream(Writer output);
121:
122: /**
123: * Specifies an output format for this serializer. It the
124: * serializer has already been associated with an output format,
125: * it will switch to the new format. This method should not be
126: * called while the serializer is in the process of serializing
127: * a document.
128: *
129: * @param format The output format to use
130: */
131: public void setOutputFormat(OutputFormat format);
132:
133: /**
134: * Return a {@link DocumentHandler} interface into this serializer.
135: * If the serializer does not support the {@link DocumentHandler}
136: * interface, it should return null.
137: */
138: public DocumentHandler asDocumentHandler() throws IOException;
139:
140: /**
141: * Return a {@link ContentHandler} interface into this serializer.
142: * If the serializer does not support the {@link ContentHandler}
143: * interface, it should return null.
144: */
145: public ContentHandler asContentHandler() throws IOException;
146:
147: /**
148: * Return a {@link DOMSerializer} interface into this serializer.
149: * If the serializer does not support the {@link DOMSerializer}
150: * interface, it should return null.
151: */
152: public DOMSerializer asDOMSerializer() throws IOException;
153:
154: }
|