jaxp/src/com/sun/org/apache/xml/internal/serialize/Serializer.java
author joehw
Thu, 12 Apr 2012 08:38:26 -0700
changeset 12457 c348e06f0e82
parent 6 jaxp/src/share/classes/com/sun/org/apache/xml/internal/serialize/Serializer.java@7f561c08de6b
child 25834 aba3efbf4ec5
permissions -rw-r--r--
7160496: Rename JDK8 JAXP source directory Summary: moving src/share/classes to src Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2002,2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.serialize;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.io.OutputStream;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.io.Writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import org.xml.sax.DocumentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * Interface for a DOM serializer implementation, factory for DOM and SAX
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * serializers, and static methods for serializing DOM documents.
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * To serialize a document using SAX events, create a compatible serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * and pass it around as a {@link
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * org.xml.sax.DocumentHandler}. If an I/O error occurs while serializing, it will
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * be thrown by {@link DocumentHandler#endDocument}. The SAX serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * may also be used as {@link org.xml.sax.DTDHandler}, {@link org.xml.sax.ext.DeclHandler} and
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * {@link org.xml.sax.ext.LexicalHandler}.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * To serialize a DOM document or DOM element, create a compatible
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * serializer and call it's {@link
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * DOMSerializer#serialize(Document)} or {@link DOMSerializer#serialize(Element)} methods.
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * Both methods would produce a full XML document, to serizlie only
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * the portion of the document use {@link OutputFormat#setOmitXMLDeclaration}
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * and specify no document type.
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * The {@link OutputFormat} dictates what underlying serialized is used
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * to serialize the document based on the specified method. If the output
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * format or method are missing, the default is an XML serializer with
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * UTF-8 encoding and now indentation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * @author <a href="mailto:Scott_Boag/CAM/Lotus@lotus.com">Scott Boag</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * @see DocumentHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @see ContentHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * @see OutputFormat
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * @see DOMSerializer
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
public interface Serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * Specifies an output stream to which the document should be
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     * serialized. This method should not be called while the
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * serializer is in the process of serializing a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    public void setOutputByteStream(OutputStream output);
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     * Specifies a writer to which the document should be serialized.
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     * This method should not be called while the serializer is in
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * the process of serializing a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    public void setOutputCharStream( Writer output );
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     * Specifies an output format for this serializer. It the
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     * serializer has already been associated with an output format,
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     * it will switch to the new format. This method should not be
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     * called while the serializer is in the process of serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     * a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
     * @param format The output format to use
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    public void setOutputFormat( OutputFormat format );
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
     * Return a {@link DocumentHandler} interface into this serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     * If the serializer does not support the {@link DocumentHandler}
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
     * interface, it should return null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    public DocumentHandler asDocumentHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        throws IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
     * Return a {@link ContentHandler} interface into this serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
     * If the serializer does not support the {@link ContentHandler}
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
     * interface, it should return null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    public ContentHandler asContentHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        throws IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     * Return a {@link DOMSerializer} interface into this serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     * If the serializer does not support the {@link DOMSerializer}
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     * interface, it should return null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    public DOMSerializer asDOMSerializer()
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        throws IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
}