jaxp/src/com/sun/org/apache/xml/internal/serialize/BaseMarkupSerializer.java
author joehw
Tue, 29 Jul 2014 20:52:36 -0700
changeset 25834 aba3efbf4ec5
parent 23777 ce87cedb71cf
permissions -rw-r--r--
8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer. Reviewed-by: lancea
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
/*
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
     8
 * this work for additional information regarding copyright ownership.
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
// Sep 14, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
//  Fixed comments to preserve whitespaces and add a line break
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
//  when indenting. Reported by Gervase Markham <gerv@gerv.net>
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
// Sep 14, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
//  Fixed serializer to report IO exception directly, instead at
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
//  the end of document processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
//  Reported by Patrick Higgins <phiggins@transzap.com>
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
// Sep 13, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
//   CR in character data will print as &#0D;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
// Aug 25, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
//   Fixed processing instruction printing inside element content
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
//   to not escape content. Reported by Mikael Staldal
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
//   <d96-mst@d.kth.se>
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
// Aug 25, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
//   Added ability to omit comments.
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
//   Contributed by Anupam Bagchi <abagchi@jtcsv.com>
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
// Aug 26, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
//   Fixed bug in newline handling when preserving spaces.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
//   Contributed by Mike Dusseault <mdusseault@home.com>
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
// Aug 29, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
//   Fixed state.unescaped not being set to false when
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
//   entering element state.
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
//   Reported by Lowell Vaughn <lvaughn@agillion.com>
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
package com.sun.org.apache.xml.internal.serialize;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
import java.io.OutputStream;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import java.io.Writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import java.util.Hashtable;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import java.util.Vector;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
import com.sun.org.apache.xerces.internal.dom.DOMLocatorImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
import com.sun.org.apache.xerces.internal.util.XMLChar;
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
    60
import org.w3c.dom.DOMError;
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
    61
import org.w3c.dom.DOMErrorHandler;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
import org.w3c.dom.DocumentFragment;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
import org.w3c.dom.DocumentType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
import org.w3c.dom.Element;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
import org.w3c.dom.ls.LSException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
import org.w3c.dom.ls.LSSerializerFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
import org.w3c.dom.traversal.NodeFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
import org.xml.sax.DTDHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
import org.xml.sax.DocumentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
import org.xml.sax.Locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
import org.xml.sax.ext.DeclHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
import org.xml.sax.ext.LexicalHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
 * Base class for a serializer supporting both DOM and SAX pretty
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
 * serializing of XML/HTML/XHTML documents. Derives classes perform
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
 * the method-specific serializing, this class provides the common
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
 * serializing mechanisms.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
 * The serializer must be initialized with the proper writer and
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
 * output format before it can be used by calling {@link #setOutputCharStream}
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
 * or {@link #setOutputByteStream} for the writer and {@link #setOutputFormat}
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
 * for the output format.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
 * The serializer can be reused any number of times, but cannot
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
 * be used concurrently by two threads.
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
 * If an output stream is used, the encoding is taken from the
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
 * output format (defaults to <tt>UTF-8</tt>). If a writer is
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
 * used, make sure the writer uses the same encoding (if applies)
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
 * as specified in the output format.
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
 * The serializer supports both DOM and SAX. DOM serializing is done
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
 * by calling {@link #serialize(Document)} and SAX serializing is done by firing
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
 * SAX events and using the serializer as a document handler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
 * This also applies to derived class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
 * If an I/O exception occurs while serializing, the serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
 * will not throw an exception directly, but only throw it
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
 * at the end of serializing (either DOM or SAX's {@link
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
 * org.xml.sax.DocumentHandler#endDocument}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
 * For elements that are not specified as whitespace preserving,
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
 * the serializer will potentially break long text lines at space
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
 * boundaries, indent lines, and serialize elements on separate
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
 * lines. Line terminators will be regarded as spaces, and
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
 * spaces at beginning of line will be stripped.
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
 * When indenting, the serializer is capable of detecting seemingly
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
 * element content, and serializing these elements indented on separate
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
 * lines. An element is serialized indented when it is the first or
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
 * last child of an element, or immediate following or preceding
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
 * another element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
 * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
 * @author <a href="mailto:rahul.srivastava@sun.com">Rahul Srivastava</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
 * @author Elena Litani, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
 * @author Sunitha Reddy, Sun Microsystems
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
 * @see Serializer
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   125
 * @see org.w3c.dom.ls.LSSerializer
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 23777
diff changeset
   126
 *
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 23777
diff changeset
   127
 * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 23777
diff changeset
   128
 * is replaced by that of Xalan. Main class
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 23777
diff changeset
   129
 * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 23777
diff changeset
   130
 * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
public abstract class BaseMarkupSerializer
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    implements ContentHandler, DocumentHandler, LexicalHandler,
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
               DTDHandler, DeclHandler, DOMSerializer, Serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
{
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    // DOM L3 implementation
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    protected short features = 0xFFFFFFFF;
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    protected DOMErrorHandler fDOMErrorHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    protected final DOMErrorImpl fDOMError = new DOMErrorImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    protected LSSerializerFilter fDOMFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    protected EncodingInfo _encodingInfo;
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * Holds array of all element states that have been entered.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     * The array is automatically resized. When leaving an element,
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     * it's state is not removed but reused when later returning
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     * to the same nesting level.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    private ElementState[]  _elementStates;
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     * The index of the next state to place in the array,
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     * or one plus the index of the current state. When zero,
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     * we are in no state.
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    private int             _elementStateCount;
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * Vector holding comments and PIs that come before the root
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     * element (even after it), see {@link #serializePreRoot}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    private Vector          _preRoot;
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
     * If the document has been started (header serialized), this
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     * flag is set to true so it's not started twice.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    protected boolean       _started;
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     * True if the serializer has been prepared. This flag is set
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
     * to false when the serializer is reset prior to using it,
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     * and to true after it has been prepared for usage.
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    private boolean         _prepared;
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     * Association between namespace URIs (keys) and prefixes (values).
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     * Accumulated here prior to starting an element and placing this
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     * list in the element state.
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    protected Hashtable     _prefixes;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     * The system identifier of the document type, if known.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    protected String        _docTypePublicId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     * The system identifier of the document type, if known.
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    protected String        _docTypeSystemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
     * The output format associated with this serializer. This will never
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
     * be a null reference. If no format was passed to the constructor,
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
     * the default one for this document type will be used. The format
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
     * object is never changed by the serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    protected OutputFormat   _format;
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
     * The printer used for printing text parts.
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    protected Printer       _printer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     * True if indenting printer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    protected boolean       _indenting;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    /** Temporary buffer to store character data */
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    protected final StringBuffer fStrBuffer = new StringBuffer(40);
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
     * The underlying writer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    private Writer          _writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
     * The output stream.
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    private OutputStream    _output;
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
    /** Current node that is being processed  */
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
    protected Node fCurrentNode = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
    //--------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
    // Constructor and initialization //
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    //--------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     * Protected constructor can only be used by derived class.
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
     * Must initialize the serializer before serializing any document,
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
     * by calling {@link #setOutputCharStream} or {@link #setOutputByteStream}
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
                 * first
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    protected BaseMarkupSerializer( OutputFormat format )
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        _elementStates = new ElementState[ 10 ];
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        for ( i = 0 ; i < _elementStates.length ; ++i )
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            _elementStates[ i ] = new ElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        _format = format;
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    public DocumentHandler asDocumentHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
        return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    public ContentHandler asContentHandler()
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    public DOMSerializer asDOMSerializer()
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
        prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    public void setOutputByteStream( OutputStream output )
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        if ( output == null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                                                           "ArgumentIsNull", new Object[]{"output"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            throw new NullPointerException(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
        _output = output;
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
        _writer = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
    public void setOutputCharStream( Writer writer )
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        if ( writer == null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
                                                           "ArgumentIsNull", new Object[]{"writer"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            throw new NullPointerException(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
        _writer = writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        _output = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
    public void setOutputFormat( OutputFormat format )
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        if ( format == null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                                                           "ArgumentIsNull", new Object[]{"format"});
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
            throw new NullPointerException(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
        _format = format;
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    public boolean reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        if ( _elementStateCount > 1 ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
                                                           "ResetInMiddle", null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
            throw new IllegalStateException(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        _prepared = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
        fCurrentNode = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
        fStrBuffer.setLength(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   341
    protected void cleanup() {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   342
        fCurrentNode = null;
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   343
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
    protected void prepare()
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        if ( _prepared )
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
        if ( _writer == null && _output == null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
                                                           "NoWriterSupplied", null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
            throw new IOException(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        // If the output stream has been set, use it to construct
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        // the writer. It is possible that the serializer has been
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
        // reused with the same output stream and different encoding.
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
        _encodingInfo = _format.getEncodingInfo();
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        if ( _output != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
            _writer = _encodingInfo.getWriter(_output);
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
        if ( _format.getIndenting() ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
            _indenting = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
            _printer = new IndentPrinter( _writer, _format );
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
            _indenting = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
            _printer = new Printer( _writer, _format );
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        _elementStateCount = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
        state = _elementStates[ 0 ];
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
        state.namespaceURI = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
        state.localName = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
        state.rawName = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
        state.preserveSpace = _format.getPreserveSpace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
        state.empty = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        state.afterElement = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
        state.afterComment = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        state.doCData = state.inCData = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
        state.prefixes = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
        _docTypePublicId = _format.getDoctypePublic();
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
        _docTypeSystemId = _format.getDoctypeSystem();
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
        _started = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
        _prepared = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
    //----------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
    // DOM document serializing methods //
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
    //----------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
     * Serializes the DOM element using the previously specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
     * writer and output format. Throws an exception only if
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
     * an I/O exception occured while serializing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
     * @param elem The element to serialize
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
     * @throws IOException An I/O exception occured while
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
    public void serialize( Element elem )
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
        serializeNode( elem );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   416
        cleanup();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
        _printer.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
        if ( _printer.getException() != null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
            throw _printer.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
     * Serializes a node using the previously specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
     * writer and output format. Throws an exception only if
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
     * an I/O exception occured while serializing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
     * @param node Node to serialize
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
     * @throws IOException An I/O exception occured while serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    public void serialize( Node node ) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
        prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
        serializeNode( node );
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
        //Print any PIs and Comments which appeared in 'node'
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        serializePreRoot();
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
        _printer.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
        if ( _printer.getException() != null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
            throw _printer.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
     * Serializes the DOM document fragmnt using the previously specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
     * writer and output format. Throws an exception only if
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
     * an I/O exception occured while serializing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
     *
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   446
     * @param frag The document fragment to serialize
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
     * @throws IOException An I/O exception occured while
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
    public void serialize( DocumentFragment frag )
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
        prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        serializeNode( frag );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   456
        cleanup();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        _printer.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
        if ( _printer.getException() != null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
            throw _printer.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
     * Serializes the DOM document using the previously specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
     * writer and output format. Throws an exception only if
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
     * an I/O exception occured while serializing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
     * @param doc The document to serialize
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
     * @throws IOException An I/O exception occured while
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
    public void serialize( Document doc )
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
        prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
        serializeNode( doc );
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
        serializePreRoot();
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   479
        cleanup();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
        _printer.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
        if ( _printer.getException() != null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
            throw _printer.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
    //------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
    // SAX document handler serializing methods //
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
    //------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
    public void startDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
            prepare();
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
            throw new SAXException( except.toString() );
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
        // Nothing to do here. All the magic happens in startDocument(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
    public void characters( char[] chars, int start, int length )
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
        state = content();
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
        // Check if text should be print as CDATA section or unescaped
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
        // based on elements listed in the output format (the element
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
        // state) or whether we are inside a CDATA section or entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
        if ( state.inCData || state.doCData ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
            int          saveIndent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
            // Print a CDATA section. The text is not escaped, but ']]>'
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
            // appearing in the code must be identified and dealt with.
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
            // The contents of a text node is considered space preserving.
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
            if ( ! state.inCData ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
                _printer.printText( "<![CDATA[" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
                state.inCData = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
            saveIndent = _printer.getNextIndent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
            _printer.setNextIndent( 0 );
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
            char ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
            final int end = start + length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
            for ( int index = start ; index < end; ++index ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
                ch = chars[index];
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
                if ( ch == ']' && index + 2 < end &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
                     chars[ index + 1 ] == ']' && chars[ index + 2 ] == '>' ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
                    _printer.printText("]]]]><![CDATA[>");
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
                    index +=2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
                    continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
                if (!XMLChar.isValid(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
                    // check if it is surrogate
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
                    if (++index < end) {
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   540
                        surrogates(ch, chars[index],true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                    else {
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   543
                        fatalError("The character '"+ch+"' is an invalid XML character");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                    continue;
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   546
                }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   547
                if ( ( ch >= ' ' && _encodingInfo.isPrintable(ch) && ch != 0x7F ) ||
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   548
                    ch == '\n' || ch == '\r' || ch == '\t' ) {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   549
                    _printer.printText(ch);
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   550
                }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   551
                else {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   552
                    // The character is not printable -- split CDATA section
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   553
                    _printer.printText("]]>&#x");
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   554
                    _printer.printText(Integer.toHexString(ch));
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
   555
                    _printer.printText(";<![CDATA[");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
            _printer.setNextIndent( saveIndent );
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
            int saveIndent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
            if ( state.preserveSpace ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
                // If preserving space then hold of indentation so no
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
                // excessive spaces are printed at line breaks, escape
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
                // the text content without replacing spaces and print
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
                // the text breaking only at line breaks.
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
                saveIndent = _printer.getNextIndent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                _printer.setNextIndent( 0 );
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                printText( chars, start, length, true, state.unescaped );
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
                _printer.setNextIndent( saveIndent );
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
                printText( chars, start, length, false, state.unescaped );
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
    public void ignorableWhitespace( char[] chars, int start, int length )
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
        int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
        content();
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
        // Print ignorable whitespaces only when indenting, after
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
        // all they are indentation. Cancel the indentation to
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
        // not indent twice.
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
        if ( _indenting ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
            _printer.setThisIndent( 0 );
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
            for ( i = start ; length-- > 0 ; ++i )
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
                _printer.printText( chars[ i ] );
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
    public final void processingInstruction( String target, String code )
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
            processingInstructionIO( target, code );
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
        throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
    public void processingInstructionIO( String target, String code )
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
        int          index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
        state = content();
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
        // Create the processing instruction textual representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
        // Make sure we don't have '?>' inside either target or code.
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
        index = target.indexOf( "?>" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
        if ( index >= 0 )
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
            fStrBuffer.append( "<?" ).append( target.substring( 0, index ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
            fStrBuffer.append( "<?" ).append( target );
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
        if ( code != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
            fStrBuffer.append( ' ' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
            index = code.indexOf( "?>" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
            if ( index >= 0 )
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
                fStrBuffer.append( code.substring( 0, index ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
                fStrBuffer.append( code );
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
        fStrBuffer.append( "?>" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
        // If before the root element (or after it), do not print
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
        // the PI directly but place it in the pre-root vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
        if ( isDocumentState() ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
            if ( _preRoot == null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
                _preRoot = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
            _preRoot.addElement( fStrBuffer.toString() );
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
            _printer.indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
            printText( fStrBuffer.toString(), true, true );
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
            _printer.unindent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
            if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
            state.afterElement = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        fStrBuffer.setLength(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
    public void comment( char[] chars, int start, int length )
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
        comment( new String( chars, start, length ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
    public void comment( String text )
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
        int          index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
        if ( _format.getOmitComments() )
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
        state  = content();
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
        // Create the processing comment textual representation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
        // Make sure we don't have '-->' inside the comment.
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
        index = text.indexOf( "-->" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        if ( index >= 0 )
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
            fStrBuffer.append( "<!--" ).append( text.substring( 0, index ) ).append( "-->" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
            fStrBuffer.append( "<!--" ).append( text ).append( "-->" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
        // If before the root element (or after it), do not print
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
        // the comment directly but place it in the pre-root vector.
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
        if ( isDocumentState() ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
            if ( _preRoot == null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
                _preRoot = new Vector();
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
            _preRoot.addElement( fStrBuffer.toString() );
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
            // Indent this element on a new line if the first
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
            // content of the parent element or immediately
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
            // following an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
            if ( _indenting && ! state.preserveSpace)
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
                _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
                                                _printer.indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
            printText( fStrBuffer.toString(), true, true );
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
                                                _printer.unindent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
            if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
                state.afterElement = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
        fStrBuffer.setLength(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
        state.afterComment = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
        state.afterElement = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
    public void startCDATA()
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
        state = getElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
        state.doCData = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
    public void endCDATA()
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
        state = getElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
        state.doCData = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
    public void startNonEscaping()
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
        state = getElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
        state.unescaped = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
    public void endNonEscaping()
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
        state = getElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
        state.unescaped = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
    public void startPreserving()
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
        state = getElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
        state.preserveSpace = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
    public void endPreserving()
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
        state = getElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
        state.preserveSpace = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
     * Called at the end of the document to wrap it up.
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
     * Will flush the output stream and throw an exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
     * if any I/O error occured while serializing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
     * @throws SAXException An I/O exception occured during
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
     *  serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
    public void endDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
        // Print all the elements accumulated outside of
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
        // the root element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
        serializePreRoot();
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
        // Flush the output, this is necessary for fStrBuffered output.
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
        _printer.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
    public void startEntity( String name )
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
        // ???
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
    public void endEntity( String name )
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
        // ???
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
    public void setDocumentLocator( Locator locator )
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
        // Nothing to do
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
    //-----------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
    // SAX content handler serializing methods //
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
    //-----------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
    public void skippedEntity ( String name )
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
        endCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
        content();
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
        _printer.printText( '&' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
        _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
        _printer.printText( ';' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
    public void startPrefixMapping( String prefix, String uri )
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
        if ( _prefixes == null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
            _prefixes = new Hashtable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
        _prefixes.put( uri, prefix == null ? "" : prefix );
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
    public void endPrefixMapping( String prefix )
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
    //------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
    // SAX DTD/Decl handler serializing methods //
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
    //------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
    public final void startDTD( String name, String publicId, String systemId )
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
        _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
        _docTypePublicId = publicId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
        _docTypeSystemId = systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
    public void endDTD()
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
        // Nothing to do here, all the magic occurs in startDocument(String).
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
    public void elementDecl( String name, String model )
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
        _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
        _printer.printText( "<!ELEMENT " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
        _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
        _printer.printText( ' ' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
        _printer.printText( model );
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
        _printer.printText( '>' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
        if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
            _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
    public void attributeDecl( String eName, String aName, String type,
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
                               String valueDefault, String value )
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
        _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
        _printer.printText( "<!ATTLIST " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
        _printer.printText( eName );
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
        _printer.printText( ' ' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
        _printer.printText( aName );
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
        _printer.printText( ' ' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
        _printer.printText( type );
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
        if ( valueDefault != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
            _printer.printText( ' ' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
            _printer.printText( valueDefault );
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
        if ( value != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
            _printer.printText( " \"" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
            printEscaped( value );
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
            _printer.printText( '"' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
        _printer.printText( '>' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
        if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
            _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
    public void internalEntityDecl( String name, String value )
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
        _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
        _printer.printText( "<!ENTITY " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
        _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
        _printer.printText( " \"" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
        printEscaped( value );
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
        _printer.printText( "\">" );
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
        if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
            _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
    public void externalEntityDecl( String name, String publicId, String systemId )
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
        _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
        unparsedEntityDecl( name, publicId, systemId, null );
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
    public void unparsedEntityDecl( String name, String publicId,
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
                                    String systemId, String notationName )
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
        _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
        if ( publicId == null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
            _printer.printText( "<!ENTITY " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
            _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
            _printer.printText( " SYSTEM " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
            printDoctypeURL( systemId );
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
            _printer.printText( "<!ENTITY " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
            _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
            _printer.printText( " PUBLIC " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
            printDoctypeURL( publicId );
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
            _printer.printText( ' ' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
            printDoctypeURL( systemId );
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
        if ( notationName != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
            _printer.printText( " NDATA " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
            _printer.printText( notationName );
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
        _printer.printText( '>' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
        if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
            _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
    public void notationDecl( String name, String publicId, String systemId )
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
        _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
        if ( publicId != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
            _printer.printText( "<!NOTATION " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
            _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
            _printer.printText( " PUBLIC " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
            printDoctypeURL( publicId );
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
            if ( systemId != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
                _printer.printText( ' ' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
                printDoctypeURL( systemId );
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
            _printer.printText( "<!NOTATION " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
            _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
            _printer.printText( " SYSTEM " );
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
            printDoctypeURL( systemId );
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
        _printer.printText( '>' );
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
        if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
            _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
        } catch ( IOException except ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
            throw new SAXException( except );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
    //------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
    // Generic node serializing methods methods //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
    //------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
     * Serialize the DOM node. This method is shared across XML, HTML and XHTML
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
     * serializers and the differences are masked out in a separate {@link
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
     * #serializeElement}.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
     * @param node The node to serialize
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
     * @see #serializeElement
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
     * @throws IOException An I/O exception occured while
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
    protected void serializeNode( Node node )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
        fCurrentNode = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
        // Based on the node type call the suitable SAX handler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
        // Only comments entities and documents which are not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
        // handled by SAX are serialized directly.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
        switch ( node.getNodeType() ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
        case Node.TEXT_NODE : {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
            String text;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
            text = node.getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
            if ( text != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
                if (fDOMFilter !=null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
                    (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_TEXT)!= 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
                    short code = fDOMFilter.acceptNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
                    switch (code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
                        case NodeFilter.FILTER_REJECT:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
                        case NodeFilter.FILTER_SKIP: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
                            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
                        default: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
                            characters(text);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
                else if ( !_indenting || getElementState().preserveSpace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
                     || (text.replace('\n',' ').trim().length() != 0))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
                    characters( text );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
        case Node.CDATA_SECTION_NODE : {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
            String text = node.getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
            if ((features & DOMSerializerImpl.CDATA) != 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
                if (text != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
                    if (fDOMFilter != null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
                        && (fDOMFilter.getWhatToShow()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
                            & NodeFilter.SHOW_CDATA_SECTION)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
                            != 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
                        short code = fDOMFilter.acceptNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
                        switch (code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
                            case NodeFilter.FILTER_REJECT :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
                            case NodeFilter.FILTER_SKIP :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
                                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
                                    // skip the CDATA node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
                                    return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
                                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
                            default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
                                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
                                    //fall through..
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
                                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
                    startCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
                    characters(text);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
                    endCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
                // transform into a text node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
                characters(text);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
        case Node.COMMENT_NODE : {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
            String text;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
            if ( ! _format.getOmitComments() ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
                text = node.getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
                if ( text != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
                    if (fDOMFilter !=null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
                          (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_COMMENT)!= 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
                          short code = fDOMFilter.acceptNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
                          switch (code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
                              case NodeFilter.FILTER_REJECT:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
                              case NodeFilter.FILTER_SKIP: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
                                  // skip the comment node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
                                  return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
                              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
                              default: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
                                   // fall through
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
                              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
                          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
                    comment( text );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
        case Node.ENTITY_REFERENCE_NODE : {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
            Node         child;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
            endCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
            content();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
            if (((features & DOMSerializerImpl.ENTITIES) != 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
                || (node.getFirstChild() == null)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
                if (fDOMFilter !=null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
                      (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ENTITY_REFERENCE)!= 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
                      short code = fDOMFilter.acceptNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
                      switch (code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
                        case NodeFilter.FILTER_REJECT:{
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
                            return; // remove the node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
                          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
                          case NodeFilter.FILTER_SKIP: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
                              child = node.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
                              while ( child != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
                                  serializeNode( child );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
                                  child = child.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
                              }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
                              return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
                          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
                          default: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
                               // fall through
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
                          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
                      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
                checkUnboundNamespacePrefixedNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
                _printer.printText("&");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
                _printer.printText(node.getNodeName());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
                _printer.printText(";");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
                child = node.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
                while ( child != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
                    serializeNode( child );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
                    child = child.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
        case Node.PROCESSING_INSTRUCTION_NODE : {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
            if (fDOMFilter !=null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
                  (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_PROCESSING_INSTRUCTION)!= 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
                  short code = fDOMFilter.acceptNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
                  switch (code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
                    case NodeFilter.FILTER_REJECT:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
                    case NodeFilter.FILTER_SKIP: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
                          return;  // skip this node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
                    default: { // fall through
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
            processingInstructionIO( node.getNodeName(), node.getNodeValue() );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
        case Node.ELEMENT_NODE :  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
            if (fDOMFilter !=null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
                  (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ELEMENT)!= 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
                  short code = fDOMFilter.acceptNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
                  switch (code) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
                    case NodeFilter.FILTER_REJECT: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
                        return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
                    case NodeFilter.FILTER_SKIP: {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
                        Node child = node.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
                        while ( child != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
                            serializeNode( child );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
                            child = child.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
                        return;  // skip this node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
                    default: { // fall through
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
                  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
            serializeElement( (Element) node );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
        case Node.DOCUMENT_NODE : {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
            DocumentType      docType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
            serializeDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
            // If there is a document type, use the SAX events to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
            // serialize it.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
            docType = ( (Document) node ).getDoctype();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
            if (docType != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
                // DOM Level 2 (or higher)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
                try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
                    String internal;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
                    _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
                    _docTypePublicId = docType.getPublicId();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
                    _docTypeSystemId = docType.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
                    internal = docType.getInternalSubset();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
                    if ( internal != null && internal.length() > 0 )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
                        _printer.printText( internal );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
                    endDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
                // DOM Level 1 -- does implementation have methods?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
                catch (NoSuchMethodError nsme) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
                    Class docTypeClass = docType.getClass();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
                    String docTypePublicId = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
                    String docTypeSystemId = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
                    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
                        java.lang.reflect.Method getPublicId = docTypeClass.getMethod("getPublicId", (Class[]) null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
                        if (getPublicId.getReturnType().equals(String.class)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
                            docTypePublicId = (String)getPublicId.invoke(docType, (Object[]) null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
                    catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
                        // ignore
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
                    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
                        java.lang.reflect.Method getSystemId = docTypeClass.getMethod("getSystemId", (Class[]) null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
                        if (getSystemId.getReturnType().equals(String.class)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
                            docTypeSystemId = (String)getSystemId.invoke(docType, (Object[]) null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
                    catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
                        // ignore
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
                    _printer.enterDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
                    _docTypePublicId = docTypePublicId;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
                    _docTypeSystemId = docTypeSystemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
                    endDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
                serializeDTD(docType.getName());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
            _started = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
            // !! Fall through
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
        case Node.DOCUMENT_FRAGMENT_NODE : {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
            Node         child;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
            // By definition this will happen if the node is a document,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
            // document fragment, etc. Just serialize its contents. It will
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
            // work well for other nodes that we do not know how to serialize.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
            child = node.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
            while ( child != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
                serializeNode( child );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
                child = child.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
        default:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
    /* Serializes XML Declaration, according to 'xml-declaration' property.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
    protected void serializeDocument()throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
        int    i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
        String dtd = _printer.leaveDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
        if (! _started) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
            if (! _format.getOmitXMLDeclaration()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
                StringBuffer    buffer;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
                // Serialize the document declaration appreaing at the head
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
                // of very XML document (unless asked not to).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
                buffer = new StringBuffer( "<?xml version=\"" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
                if (_format.getVersion() != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
                    buffer.append( _format.getVersion() );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
                    buffer.append( "1.0" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
                buffer.append( '"' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
                String format_encoding =  _format.getEncoding();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
                if (format_encoding != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
                    buffer.append( " encoding=\"" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
                    buffer.append( format_encoding );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
                    buffer.append( '"' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
                if (_format.getStandalone() && _docTypeSystemId == null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
                    _docTypePublicId == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
                    buffer.append( " standalone=\"yes\"" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
                buffer.append( "?>" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
                _printer.printText( buffer );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
                _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
        // Always serialize these, even if not te first root element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
        serializePreRoot();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
    /* Serializes DTD, if present.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
    protected void serializeDTD(String name) throws IOException{
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
        String dtd = _printer.leaveDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
        if (! _format.getOmitDocumentType()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
            if (_docTypeSystemId != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
                // System identifier must be specified to print DOCTYPE.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
                // If public identifier is specified print 'PUBLIC
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
                // <public> <system>', if not, print 'SYSTEM <system>'.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
                _printer.printText( "<!DOCTYPE " );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
                _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
                if (_docTypePublicId != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
                    _printer.printText( " PUBLIC " );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
                    printDoctypeURL( _docTypePublicId );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
                    if (_indenting) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
                        _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
                        for (int i = 0 ; i < 18 + name.length() ; ++i)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
                            _printer.printText( " " );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
                    } else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
                        _printer.printText( " " );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
                    printDoctypeURL( _docTypeSystemId );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
                } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
                    _printer.printText( " SYSTEM " );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
                    printDoctypeURL( _docTypeSystemId );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
                // If we accumulated any DTD contents while printing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
                // this would be the place to print it.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
                if (dtd != null && dtd.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
                    _printer.printText( " [" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
                    printText( dtd, true, true );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
                    _printer.printText( ']' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
                _printer.printText( ">" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
                _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
            } else if (dtd != null && dtd.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
                _printer.printText( "<!DOCTYPE " );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
                _printer.printText( name );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
                _printer.printText( " [" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
                printText( dtd, true, true );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
                _printer.printText( "]>" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
                _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
     * Must be called by a method about to print any type of content.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
     * If the element was just opened, the opening tag is closed and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
     * will be matched to a closing tag. Returns the current element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
     * state with <tt>empty</tt> and <tt>afterElement</tt> set to false.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
     * @return The current element state
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1376
     * @throws IOException An I/O exception occurred while
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
    protected ElementState content()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
        state = getElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
        if ( ! isDocumentState() ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
            // Need to close CData section first
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
            if ( state.inCData && ! state.doCData ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
                _printer.printText( "]]>" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
                state.inCData = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
            // If this is the first content in the element,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
            // change the state to not-empty and close the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
            // opening element tag.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
            if ( state.empty ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
                _printer.printText( '>' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
                state.empty = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
            // Except for one content type, all of them
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
            // are not last element. That one content
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
            // type will take care of itself.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
            state.afterElement = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
            // Except for one content type, all of them
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
            // are not last comment. That one content
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
            // type will take care of itself.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
            state.afterComment = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
        return state;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
     * Called to print the text contents in the prevailing element format.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
     * Since this method is capable of printing text as CDATA, it is used
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
     * for that purpose as well. White space handling is determined by the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
     * current element state. In addition, the output format can dictate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
     * whether the text is printed as CDATA or unescaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
     * @param text The text to print
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
     * @throws IOException An I/O exception occured while
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
    protected void characters( String text )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
7f561c08de6b Initial load
duke
parents:
diff changeset
  1427
        state = content();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
        // Check if text should be print as CDATA section or unescaped
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
        // based on elements listed in the output format (the element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
        // state) or whether we are inside a CDATA section or entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
        if ( state.inCData || state.doCData ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1433
            // Print a CDATA section. The text is not escaped, but ']]>'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1434
            // appearing in the code must be identified and dealt with.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1435
            // The contents of a text node is considered space preserving.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1436
            if ( ! state.inCData ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1437
                _printer.printText("<![CDATA[");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1438
                state.inCData = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1439
            }
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1440
            int saveIndent = _printer.getNextIndent();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1441
            _printer.setNextIndent( 0 );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1442
            printCDATAText( text);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1443
            _printer.setNextIndent( saveIndent );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1444
7f561c08de6b Initial load
duke
parents:
diff changeset
  1445
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1446
7f561c08de6b Initial load
duke
parents:
diff changeset
  1447
            int saveIndent;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1448
7f561c08de6b Initial load
duke
parents:
diff changeset
  1449
            if ( state.preserveSpace ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1450
                // If preserving space then hold of indentation so no
7f561c08de6b Initial load
duke
parents:
diff changeset
  1451
                // excessive spaces are printed at line breaks, escape
7f561c08de6b Initial load
duke
parents:
diff changeset
  1452
                // the text content without replacing spaces and print
7f561c08de6b Initial load
duke
parents:
diff changeset
  1453
                // the text breaking only at line breaks.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1454
                saveIndent = _printer.getNextIndent();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1455
                _printer.setNextIndent( 0 );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1456
                printText( text, true, state.unescaped );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1457
                _printer.setNextIndent( saveIndent );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1458
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1459
                printText( text, false, state.unescaped );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1460
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1461
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1462
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1463
7f561c08de6b Initial load
duke
parents:
diff changeset
  1464
7f561c08de6b Initial load
duke
parents:
diff changeset
  1465
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1466
     * Returns the suitable entity reference for this character value,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1467
     * or null if no such entity exists. Calling this method with <tt>'&amp;'</tt>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1468
     * will return <tt>"&amp;amp;"</tt>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
     * @param ch Character value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
     * @return Character entity name, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1472
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
    protected abstract String getEntityRef( int ch );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
     * Called to serializee the DOM element. The element is serialized based on
7f561c08de6b Initial load
duke
parents:
diff changeset
  1478
     * the serializer's method (XML, HTML, XHTML).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1479
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1480
     * @param elem The element to serialize
7f561c08de6b Initial load
duke
parents:
diff changeset
  1481
     * @throws IOException An I/O exception occured while
7f561c08de6b Initial load
duke
parents:
diff changeset
  1482
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1483
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1484
    protected abstract void serializeElement( Element elem )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1485
        throws IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1486
7f561c08de6b Initial load
duke
parents:
diff changeset
  1487
7f561c08de6b Initial load
duke
parents:
diff changeset
  1488
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1489
     * Comments and PIs cannot be serialized before the root element,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1490
     * because the root element serializes the document type, which
7f561c08de6b Initial load
duke
parents:
diff changeset
  1491
     * generally comes first. Instead such PIs and comments are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1492
     * accumulated inside a vector and serialized by calling this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1493
     * method. Will be called when the root element is serialized
7f561c08de6b Initial load
duke
parents:
diff changeset
  1494
     * and when the document finished serializing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1495
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1496
     * @throws IOException An I/O exception occured while
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
     *   serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1499
    protected void serializePreRoot()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1500
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1501
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1502
        int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1503
7f561c08de6b Initial load
duke
parents:
diff changeset
  1504
        if ( _preRoot != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
            for ( i = 0 ; i < _preRoot.size() ; ++i ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
                printText( (String) _preRoot.elementAt( i ), true, true );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1507
                if ( _indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1508
                _printer.breakLine();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1509
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1510
            _preRoot.removeAllElements();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1511
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1512
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1513
7f561c08de6b Initial load
duke
parents:
diff changeset
  1514
7f561c08de6b Initial load
duke
parents:
diff changeset
  1515
    //---------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
  1516
    // Text pretty printing and formatting methods //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1517
    //---------------------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
  1518
7f561c08de6b Initial load
duke
parents:
diff changeset
  1519
    protected void printCDATAText( String text ) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1520
        int length = text.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1521
        char ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1522
7f561c08de6b Initial load
duke
parents:
diff changeset
  1523
        for ( int index = 0 ; index <  length; ++index ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1524
            ch = text.charAt( index );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1525
            if (ch == ']'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1526
                && index + 2 < length
7f561c08de6b Initial load
duke
parents:
diff changeset
  1527
                && text.charAt(index + 1) == ']'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1528
                && text.charAt(index + 2) == '>') { // check for ']]>'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1529
                if (fDOMErrorHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1530
                    // REVISIT: this means that if DOM Error handler is not registered we don't report any
7f561c08de6b Initial load
duke
parents:
diff changeset
  1531
                    // fatal errors and might serialize not wellformed document
7f561c08de6b Initial load
duke
parents:
diff changeset
  1532
                    if ((features & DOMSerializerImpl.SPLITCDATA) == 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1533
                        String msg = DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1534
                            DOMMessageFormatter.SERIALIZER_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1535
                            "EndingCDATA",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
                            null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
                        if ((features & DOMSerializerImpl.WELLFORMED) != 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
                            // issue fatal error
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
                            modifyDOMError(msg, DOMError.SEVERITY_FATAL_ERROR, "wf-invalid-character", fCurrentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1540
                            fDOMErrorHandler.handleError(fDOMError);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1541
                            throw new LSException(LSException.SERIALIZE_ERR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1542
                        }
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1543
                        // issue error
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1544
                        modifyDOMError(msg, DOMError.SEVERITY_ERROR, "cdata-section-not-splitted", fCurrentNode);
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1545
                        if (!fDOMErrorHandler.handleError(fDOMError)) {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1546
                            throw new LSException(LSException.SERIALIZE_ERR, msg);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1547
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1548
                    } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1549
                        // issue warning
7f561c08de6b Initial load
duke
parents:
diff changeset
  1550
                        String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1551
                            DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1552
                                DOMMessageFormatter.SERIALIZER_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1553
                                "SplittingCDATA",
7f561c08de6b Initial load
duke
parents:
diff changeset
  1554
                                null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1555
                        modifyDOMError(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1556
                            msg,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1557
                            DOMError.SEVERITY_WARNING,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1558
                            null, fCurrentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1559
                        fDOMErrorHandler.handleError(fDOMError);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1560
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1561
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1562
                // split CDATA section
7f561c08de6b Initial load
duke
parents:
diff changeset
  1563
                _printer.printText("]]]]><![CDATA[>");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1564
                index += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1565
                continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1566
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1567
7f561c08de6b Initial load
duke
parents:
diff changeset
  1568
            if (!XMLChar.isValid(ch)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1569
                // check if it is surrogate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1570
                if (++index <length) {
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1571
                    surrogates(ch, text.charAt(index),true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1572
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1573
                else {
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1574
                    fatalError("The character '"+ch+"' is an invalid XML character");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1575
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1576
                continue;
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1577
            }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1578
            if ( ( ch >= ' ' && _encodingInfo.isPrintable(ch) && ch != 0x7F ) ||
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1579
                 ch == '\n' || ch == '\r' || ch == '\t' ) {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1580
                _printer.printText(ch);
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1581
            }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1582
            else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1583
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1584
                // The character is not printable -- split CDATA section
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1585
                _printer.printText("]]>&#x");
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1586
                _printer.printText(Integer.toHexString(ch));
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1587
                _printer.printText(";<![CDATA[");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1588
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1589
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1590
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1591
7f561c08de6b Initial load
duke
parents:
diff changeset
  1592
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1593
    protected void surrogates(int high, int low, boolean inContent) throws IOException{
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1594
        if (XMLChar.isHighSurrogate(high)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1595
            if (!XMLChar.isLowSurrogate(low)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1596
                //Invalid XML
7f561c08de6b Initial load
duke
parents:
diff changeset
  1597
                fatalError("The character '"+(char)low+"' is an invalid XML character");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1598
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1599
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1600
                int supplemental = XMLChar.supplemental((char)high, (char)low);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1601
                if (!XMLChar.isValid(supplemental)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1602
                    //Invalid XML
7f561c08de6b Initial load
duke
parents:
diff changeset
  1603
                    fatalError("The character '"+(char)supplemental+"' is an invalid XML character");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1604
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1605
                else {
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1606
                    if (inContent && content().inCData) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1607
                        _printer.printText("]]>&#x");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1608
                        _printer.printText(Integer.toHexString(supplemental));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1609
                        _printer.printText(";<![CDATA[");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1610
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1611
                    else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1612
                        printHex(supplemental);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1613
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1614
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1615
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1616
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1617
            fatalError("The character '"+(char)high+"' is an invalid XML character");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1618
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1619
7f561c08de6b Initial load
duke
parents:
diff changeset
  1620
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1621
7f561c08de6b Initial load
duke
parents:
diff changeset
  1622
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1623
     * Called to print additional text with whitespace handling.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1624
     * If spaces are preserved, the text is printed as if by calling
7f561c08de6b Initial load
duke
parents:
diff changeset
  1625
     * {@link #printText(String,boolean,boolean)} with a call to {@link Printer#breakLine}
7f561c08de6b Initial load
duke
parents:
diff changeset
  1626
     * for each new line. If spaces are not preserved, the text is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1627
     * broken at space boundaries if longer than the line width;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1628
     * Multiple spaces are printed as such, but spaces at beginning
7f561c08de6b Initial load
duke
parents:
diff changeset
  1629
     * of line are removed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1630
     *
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1631
     * @param chars The text to print
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1632
     * @param start The start offset
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1633
     * @param length The number of characters
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1634
     * @param preserveSpace Space preserving flag
7f561c08de6b Initial load
duke
parents:
diff changeset
  1635
     * @param unescaped Print unescaped
7f561c08de6b Initial load
duke
parents:
diff changeset
  1636
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1637
    protected void printText( char[] chars, int start, int length,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1638
                                    boolean preserveSpace, boolean unescaped )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1639
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1640
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1641
7f561c08de6b Initial load
duke
parents:
diff changeset
  1642
        if ( preserveSpace ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1643
            // Preserving spaces: the text must print exactly as it is,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1644
            // without breaking when spaces appear in the text and without
7f561c08de6b Initial load
duke
parents:
diff changeset
  1645
            // consolidating spaces. If a line terminator is used, a line
7f561c08de6b Initial load
duke
parents:
diff changeset
  1646
            // break will occur.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1647
            while ( length-- > 0 ) {
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1648
                char ch = chars[ start ];
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1649
                ++start;
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1650
                if ( ch == '\n' || ch == '\r' || unescaped ) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1651
                    _printer.printText( ch );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1652
                }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1653
                else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1654
                    printEscaped( ch );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1655
                }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1656
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1657
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1658
            // Not preserving spaces: print one part at a time, and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1659
            // use spaces between parts to break them into different
7f561c08de6b Initial load
duke
parents:
diff changeset
  1660
            // lines. Spaces at beginning of line will be stripped
7f561c08de6b Initial load
duke
parents:
diff changeset
  1661
            // by printing mechanism. Line terminator is treated
7f561c08de6b Initial load
duke
parents:
diff changeset
  1662
            // no different than other text part.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1663
            while ( length-- > 0 ) {
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1664
                char ch = chars[ start ];
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1665
                ++start;
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1666
                if ( ch == ' ' || ch == '\f' || ch == '\t' || ch == '\n' || ch == '\r' ) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1667
                    _printer.printSpace();
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1668
                }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1669
                else if ( unescaped ) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1670
                    _printer.printText( ch );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1671
                }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1672
                else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1673
                    printEscaped( ch );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1674
                }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1675
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1676
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1677
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1678
7f561c08de6b Initial load
duke
parents:
diff changeset
  1679
7f561c08de6b Initial load
duke
parents:
diff changeset
  1680
    protected void printText( String text, boolean preserveSpace, boolean unescaped )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1681
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1682
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1683
        int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1684
        char ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1685
7f561c08de6b Initial load
duke
parents:
diff changeset
  1686
        if ( preserveSpace ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1687
            // Preserving spaces: the text must print exactly as it is,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1688
            // without breaking when spaces appear in the text and without
7f561c08de6b Initial load
duke
parents:
diff changeset
  1689
            // consolidating spaces. If a line terminator is used, a line
7f561c08de6b Initial load
duke
parents:
diff changeset
  1690
            // break will occur.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1691
            for ( index = 0 ; index < text.length() ; ++index ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1692
                ch = text.charAt( index );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1693
                if ( ch == '\n' || ch == '\r' || unescaped )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1694
                    _printer.printText( ch );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1695
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1696
                    printEscaped( ch );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1697
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1698
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1699
            // Not preserving spaces: print one part at a time, and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1700
            // use spaces between parts to break them into different
7f561c08de6b Initial load
duke
parents:
diff changeset
  1701
            // lines. Spaces at beginning of line will be stripped
7f561c08de6b Initial load
duke
parents:
diff changeset
  1702
            // by printing mechanism. Line terminator is treated
7f561c08de6b Initial load
duke
parents:
diff changeset
  1703
            // no different than other text part.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1704
            for ( index = 0 ; index < text.length() ; ++index ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1705
                ch = text.charAt( index );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1706
                if ( ch == ' ' || ch == '\f' || ch == '\t' || ch == '\n' || ch == '\r' ) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1707
                    _printer.printSpace();
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1708
                }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1709
                else if ( unescaped ) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1710
                    _printer.printText( ch );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1711
                }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1712
                else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1713
                    printEscaped( ch );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1714
                }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1715
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1716
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1717
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1718
7f561c08de6b Initial load
duke
parents:
diff changeset
  1719
7f561c08de6b Initial load
duke
parents:
diff changeset
  1720
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1721
     * Print a document type public or system identifier URL.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1722
     * Encapsulates the URL in double quotes, escapes non-printing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1723
     * characters and print it equivalent to {@link #printText}.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1724
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1725
     * @param url The document type url to print
7f561c08de6b Initial load
duke
parents:
diff changeset
  1726
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1727
    protected void printDoctypeURL( String url )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1728
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1729
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1730
        int                i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1731
7f561c08de6b Initial load
duke
parents:
diff changeset
  1732
        _printer.printText( '"' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1733
        for( i = 0 ; i < url.length() ; ++i ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1734
            if ( url.charAt( i ) == '"' ||  url.charAt( i ) < 0x20 || url.charAt( i ) > 0x7F ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1735
                _printer.printText( '%' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1736
                _printer.printText( Integer.toHexString( url.charAt( i ) ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1737
            } else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1738
                _printer.printText( url.charAt( i ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1739
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1740
        _printer.printText( '"' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1741
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1742
7f561c08de6b Initial load
duke
parents:
diff changeset
  1743
7f561c08de6b Initial load
duke
parents:
diff changeset
  1744
    protected void printEscaped( int ch )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1745
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1746
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1747
        String charRef;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1748
        // If there is a suitable entity reference for this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1749
        // character, print it. The list of available entity
7f561c08de6b Initial load
duke
parents:
diff changeset
  1750
        // references is almost but not identical between
7f561c08de6b Initial load
duke
parents:
diff changeset
  1751
        // XML and HTML.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1752
        charRef = getEntityRef( ch );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1753
        if ( charRef != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1754
            _printer.printText( '&' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1755
            _printer.printText( charRef );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1756
            _printer.printText( ';' );
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1757
        } else if ( ( ch >= ' ' && _encodingInfo.isPrintable((char)ch) && ch != 0x7F ) ||
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1758
                    ch == '\n' || ch == '\r' || ch == '\t' ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1759
            // Non printables are below ASCII space but not tab or line
7f561c08de6b Initial load
duke
parents:
diff changeset
  1760
            // terminator, ASCII delete, or above a certain Unicode threshold.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1761
            if (ch < 0x10000) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1762
                _printer.printText((char)ch );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1763
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1764
                _printer.printText((char)(((ch-0x10000)>>10)+0xd800));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1765
                _printer.printText((char)(((ch-0x10000)&0x3ff)+0xdc00));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1766
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1767
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1768
                        printHex(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1769
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1770
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1771
7f561c08de6b Initial load
duke
parents:
diff changeset
  1772
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1773
         * Escapes chars
7f561c08de6b Initial load
duke
parents:
diff changeset
  1774
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1775
         final void printHex( int ch) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1776
                 _printer.printText( "&#x" );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1777
                 _printer.printText(Integer.toHexString(ch));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1778
                 _printer.printText( ';' );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1779
7f561c08de6b Initial load
duke
parents:
diff changeset
  1780
         }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1781
7f561c08de6b Initial load
duke
parents:
diff changeset
  1782
7f561c08de6b Initial load
duke
parents:
diff changeset
  1783
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1784
     * Escapes a string so it may be printed as text content or attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
  1785
     * value. Non printable characters are escaped using character references.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1786
     * Where the format specifies a deault entity reference, that reference
7f561c08de6b Initial load
duke
parents:
diff changeset
  1787
     * is used (e.g. <tt>&amp;lt;</tt>).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1788
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1789
     * @param source The string to escape
7f561c08de6b Initial load
duke
parents:
diff changeset
  1790
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1791
    protected void printEscaped( String source )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1792
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1793
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1794
        for ( int i = 0 ; i < source.length() ; ++i ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1795
            int ch = source.charAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1796
            if ((ch & 0xfc00) == 0xd800 && i+1 < source.length()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1797
                int lowch = source.charAt(i+1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1798
                if ((lowch & 0xfc00) == 0xdc00) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1799
                    ch = 0x10000 + ((ch-0xd800)<<10) + lowch-0xdc00;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1800
                    i++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1801
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1802
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1803
            printEscaped(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1804
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1805
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1806
7f561c08de6b Initial load
duke
parents:
diff changeset
  1807
7f561c08de6b Initial load
duke
parents:
diff changeset
  1808
    //--------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
  1809
    // Element state handling methods //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1810
    //--------------------------------//
7f561c08de6b Initial load
duke
parents:
diff changeset
  1811
7f561c08de6b Initial load
duke
parents:
diff changeset
  1812
7f561c08de6b Initial load
duke
parents:
diff changeset
  1813
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1814
     * Return the state of the current element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1815
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1816
     * @return Current element state
7f561c08de6b Initial load
duke
parents:
diff changeset
  1817
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1818
    protected ElementState getElementState()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1819
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1820
        return _elementStates[ _elementStateCount ];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1821
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1822
7f561c08de6b Initial load
duke
parents:
diff changeset
  1823
7f561c08de6b Initial load
duke
parents:
diff changeset
  1824
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1825
     * Enter a new element state for the specified element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1826
     * Tag name and space preserving is specified, element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1827
     * state is initially empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1828
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1829
     * @return Current element state, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1830
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1831
    protected ElementState enterElementState( String namespaceURI, String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1832
                                              String rawName, boolean preserveSpace )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1833
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1834
        ElementState state;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1835
7f561c08de6b Initial load
duke
parents:
diff changeset
  1836
        if ( _elementStateCount + 1 == _elementStates.length ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1837
            ElementState[] newStates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1838
7f561c08de6b Initial load
duke
parents:
diff changeset
  1839
            // Need to create a larger array of states. This does not happen
7f561c08de6b Initial load
duke
parents:
diff changeset
  1840
            // often, unless the document is really deep.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1841
            newStates = new ElementState[ _elementStates.length + 10 ];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1842
            for ( int i = 0 ; i < _elementStates.length ; ++i )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1843
                newStates[ i ] = _elementStates[ i ];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1844
            for ( int i = _elementStates.length ; i < newStates.length ; ++i )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1845
                newStates[ i ] = new ElementState();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1846
            _elementStates = newStates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1847
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1848
7f561c08de6b Initial load
duke
parents:
diff changeset
  1849
        ++_elementStateCount;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1850
        state = _elementStates[ _elementStateCount ];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1851
        state.namespaceURI = namespaceURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1852
        state.localName = localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1853
        state.rawName = rawName;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1854
        state.preserveSpace = preserveSpace;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1855
        state.empty = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1856
        state.afterElement = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1857
        state.afterComment = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1858
        state.doCData = state.inCData = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1859
        state.unescaped = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1860
        state.prefixes = _prefixes;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1861
7f561c08de6b Initial load
duke
parents:
diff changeset
  1862
        _prefixes = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1863
        return state;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1864
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1865
7f561c08de6b Initial load
duke
parents:
diff changeset
  1866
7f561c08de6b Initial load
duke
parents:
diff changeset
  1867
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1868
     * Leave the current element state and return to the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1869
     * state of the parent element. If this was the root
7f561c08de6b Initial load
duke
parents:
diff changeset
  1870
     * element, return to the state of the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1871
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1872
     * @return Previous element state
7f561c08de6b Initial load
duke
parents:
diff changeset
  1873
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1874
    protected ElementState leaveElementState()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1875
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1876
        if ( _elementStateCount > 0 ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1877
            /*Corrected by David Blondeau (blondeau@intalio.com)*/
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1878
            _prefixes = null;
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1879
            //_prefixes = _elementStates[ _elementStateCount ].prefixes;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1880
            -- _elementStateCount;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1881
            return _elementStates[ _elementStateCount ];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1882
        }
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1883
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "Internal", null);
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1884
        throw new IllegalStateException(msg);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1885
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1886
7f561c08de6b Initial load
duke
parents:
diff changeset
  1887
7f561c08de6b Initial load
duke
parents:
diff changeset
  1888
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1889
     * Returns true if in the state of the document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1890
     * Returns true before entering any element and after
7f561c08de6b Initial load
duke
parents:
diff changeset
  1891
     * leaving the root element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1892
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1893
     * @return True if in the state of the document
7f561c08de6b Initial load
duke
parents:
diff changeset
  1894
     */
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1895
    protected boolean isDocumentState() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1896
        return _elementStateCount == 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1897
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1898
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1899
    /** Clears document state. **/
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1900
    final void clearDocumentState() {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1901
        _elementStateCount = 0;
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1902
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1903
7f561c08de6b Initial load
duke
parents:
diff changeset
  1904
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1905
     * Returns the namespace prefix for the specified URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1906
     * If the URI has been mapped to a prefix, returns the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1907
     * prefix, otherwise returns null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1908
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1909
     * @param namespaceURI The namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1910
     * @return The namespace prefix if known, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1911
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1912
    protected String getPrefix( String namespaceURI )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1913
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1914
        String    prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1915
7f561c08de6b Initial load
duke
parents:
diff changeset
  1916
        if ( _prefixes != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1917
            prefix = (String) _prefixes.get( namespaceURI );
7f561c08de6b Initial load
duke
parents:
diff changeset
  1918
            if ( prefix != null )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1919
                return prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1920
        }
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1921
        if ( _elementStateCount == 0 ) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1922
            return null;
23777
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1923
        }
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1924
        for ( int i = _elementStateCount ; i > 0 ; --i ) {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1925
            if ( _elementStates[ i ].prefixes != null ) {
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1926
                prefix = (String) _elementStates[ i ].prefixes.get( namespaceURI );
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1927
                if ( prefix != null )
ce87cedb71cf 8035437: Xerces Update: xml/serialize/DOMSerializerImpl
aefimov
parents: 12457
diff changeset
  1928
                    return prefix;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1929
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1930
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1931
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1932
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1933
7f561c08de6b Initial load
duke
parents:
diff changeset
  1934
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1935
     * The method modifies global DOM error object
7f561c08de6b Initial load
duke
parents:
diff changeset
  1936
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1937
     * @param message
7f561c08de6b Initial load
duke
parents:
diff changeset
  1938
     * @param severity
7f561c08de6b Initial load
duke
parents:
diff changeset
  1939
     * @param type
7f561c08de6b Initial load
duke
parents:
diff changeset
  1940
     * @return a DOMError
7f561c08de6b Initial load
duke
parents:
diff changeset
  1941
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1942
    protected DOMError modifyDOMError(String message, short severity, String type, Node node){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1943
            fDOMError.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1944
            fDOMError.fMessage = message;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1945
            fDOMError.fType = type;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1946
            fDOMError.fSeverity = severity;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1947
            fDOMError.fLocator = new DOMLocatorImpl(-1, -1, -1, node, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1948
            return fDOMError;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1949
7f561c08de6b Initial load
duke
parents:
diff changeset
  1950
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1951
7f561c08de6b Initial load
duke
parents:
diff changeset
  1952
7f561c08de6b Initial load
duke
parents:
diff changeset
  1953
    protected void fatalError(String message) throws IOException{
7f561c08de6b Initial load
duke
parents:
diff changeset
  1954
        if (fDOMErrorHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1955
            modifyDOMError(message, DOMError.SEVERITY_FATAL_ERROR, null, fCurrentNode);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1956
            fDOMErrorHandler.handleError(fDOMError);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1957
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1958
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1959
            throw new IOException(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1960
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1961
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1962
7f561c08de6b Initial load
duke
parents:
diff changeset
  1963
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1964
         * DOM level 3:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1965
         * Check a node to determine if it contains unbound namespace prefixes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1966
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1967
         * @param node The node to check for unbound namespace prefices
7f561c08de6b Initial load
duke
parents:
diff changeset
  1968
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1969
         protected void checkUnboundNamespacePrefixedNode (Node node) throws IOException{
7f561c08de6b Initial load
duke
parents:
diff changeset
  1970
7f561c08de6b Initial load
duke
parents:
diff changeset
  1971
         }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1972
}