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