001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: SerializationHandler.java 471981 2006-11-07 04:28:00Z minchau $
020     */
021    package org.apache.xml.serializer;
022    
023    import java.io.IOException;
024    
025    import javax.xml.transform.Transformer;
026    
027    import org.w3c.dom.Node;
028    import org.xml.sax.ContentHandler;
029    import org.xml.sax.ErrorHandler;
030    import org.xml.sax.SAXException;
031    import org.xml.sax.ext.DeclHandler;
032    
033    /**
034     * This interface is the one that a serializer implements. It is a group of
035     * other interfaces, such as ExtendedContentHandler, ExtendedLexicalHandler etc.
036     * In addition there are other methods, such as reset().
037     * 
038     * This class is public only because it is used in another package,
039     * it is not a public API.
040     * 
041     * @xsl.usage internal
042     */
043    public interface SerializationHandler
044        extends
045            ExtendedContentHandler,
046            ExtendedLexicalHandler,
047            XSLOutputAttributes,
048            DeclHandler,
049            org.xml.sax.DTDHandler,
050            ErrorHandler,
051            DOMSerializer,
052            Serializer
053    {
054        /**
055         * Set the SAX Content handler that the serializer sends its output to. This
056         * method only applies to a ToSAXHandler, not to a ToStream serializer.
057         * 
058         * @see Serializer#asContentHandler()
059         * @see ToSAXHandler
060         */
061        public void setContentHandler(ContentHandler ch);
062        
063        public void close();
064    
065        /**
066         * Notify that the serializer should take this DOM node as input to be
067         * serialized.
068         * 
069         * @param node the DOM node to be serialized.
070         * @throws IOException
071         */
072        public void serialize(Node node) throws IOException;
073        /**
074         * Turns special character escaping on/off. 
075         * 
076         * Note that characters will
077         * never, even if this option is set to 'true', be escaped within
078         * CDATA sections in output XML documents.
079         * 
080         * @param escape true if escaping is to be set on.
081         */
082        public boolean setEscaping(boolean escape) throws SAXException;
083    
084        /**
085         * Set the number of spaces to indent for each indentation level.
086         * @param spaces the number of spaces to indent for each indentation level.
087         */
088        public void setIndentAmount(int spaces);
089    
090        /**
091         * Set the transformer associated with the serializer.
092         * @param transformer the transformer associated with the serializer.
093         */
094        public void setTransformer(Transformer transformer);
095        
096        /**
097         * Get the transformer associated with the serializer.
098         * @return Transformer the transformer associated with the serializer.
099         */
100        public Transformer getTransformer();
101    
102        /** 
103         * Used only by TransformerSnapshotImpl to restore the serialization 
104         * to a previous state. 
105         * 
106         * @param mappings NamespaceMappings
107         */
108        public void setNamespaceMappings(NamespaceMappings mappings);
109    
110        /**
111         * A SerializationHandler accepts SAX-like events, so
112         * it can accumulate attributes or namespace nodes after
113         * a startElement().
114         * <p>
115         * If the SerializationHandler has a Writer or OutputStream, 
116         * a call to this method will flush such accumulated 
117         * events as a closed start tag for an element.
118         * <p>
119         * If the SerializationHandler wraps a ContentHandler,
120         * a call to this method will flush such accumulated
121         * events as a SAX (not SAX-like) calls to
122         * startPrefixMapping() and startElement().
123         * <p>
124         * If one calls endDocument() then one need not call
125         * this method since a call to endDocument() will
126         * do what this method does. However, in some
127         * circumstances, such as with document fragments,
128         * endDocument() is not called and it may be
129         * necessary to call this method to flush
130         * any pending events.
131         * <p> 
132         * For performance reasons this method should not be called
133         * very often. 
134         */
135        public void flushPending() throws SAXException;
136        
137        /**
138         * Default behavior is to expand DTD entities,
139         * that is the initall default value is true.
140         * @param expand true if DTD entities are to be expanded,
141         * false if they are to be left as DTD entity references. 
142         */
143        public void setDTDEntityExpansion(boolean expand);
144        
145    }