19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: SerializationHandler.java 471981 2006-11-07 04:28:00Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.serializer; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.IOException; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.Transformer; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Node; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.ContentHandler; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.ErrorHandler; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.SAXException; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.xml.sax.ext.DeclHandler; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This interface is the one that a serializer implements. It is a group of 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * other interfaces, such as ExtendedContentHandler, ExtendedLexicalHandler etc. 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * In addition there are other methods, such as reset(). 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This class is public only because it is used in another package, 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * it is not a public API. 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic interface SerializationHandler 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson extends 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ExtendedContentHandler, 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ExtendedLexicalHandler, 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson XSLOutputAttributes, 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DeclHandler, 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson org.xml.sax.DTDHandler, 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ErrorHandler, 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DOMSerializer, 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Serializer 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the SAX Content handler that the serializer sends its output to. This 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * method only applies to a ToSAXHandler, not to a ToStream serializer. 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see Serializer#asContentHandler() 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see ToSAXHandler 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setContentHandler(ContentHandler ch); 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void close(); 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Notify that the serializer should take this DOM node as input to be 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * serialized. 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param node the DOM node to be serialized. 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws IOException 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void serialize(Node node) throws IOException; 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Turns special character escaping on/off. 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Note that characters will 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * never, even if this option is set to 'true', be escaped within 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * CDATA sections in output XML documents. 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param escape true if escaping is to be set on. 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean setEscaping(boolean escape) throws SAXException; 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the number of spaces to indent for each indentation level. 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param spaces the number of spaces to indent for each indentation level. 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setIndentAmount(int spaces); 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the transformer associated with the serializer. 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param transformer the transformer associated with the serializer. 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setTransformer(Transformer transformer); 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the transformer associated with the serializer. 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Transformer the transformer associated with the serializer. 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Transformer getTransformer(); 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Used only by TransformerSnapshotImpl to restore the serialization 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to a previous state. 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param mappings NamespaceMappings 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setNamespaceMappings(NamespaceMappings mappings); 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * A SerializationHandler accepts SAX-like events, so 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * it can accumulate attributes or namespace nodes after 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a startElement(). 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p> 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If the SerializationHandler has a Writer or OutputStream, 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a call to this method will flush such accumulated 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * events as a closed start tag for an element. 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p> 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If the SerializationHandler wraps a ContentHandler, 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a call to this method will flush such accumulated 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * events as a SAX (not SAX-like) calls to 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * startPrefixMapping() and startElement(). 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p> 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If one calls endDocument() then one need not call 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * this method since a call to endDocument() will 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * do what this method does. However, in some 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * circumstances, such as with document fragments, 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * endDocument() is not called and it may be 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * necessary to call this method to flush 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * any pending events. 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p> 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * For performance reasons this method should not be called 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * very often. 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void flushPending() throws SAXException; 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Default behavior is to expand DTD entities, 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * that is the initall default value is true. 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param expand true if DTD entities are to be expanded, 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * false if they are to be left as DTD entity references. 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setDTDEntityExpansion(boolean expand); 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 146