jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java
author fyuan
Wed, 15 Feb 2017 11:43:23 +0800
changeset 43845 93896d0f44f3
parent 43744 5436902a27d7
permissions -rw-r--r--
8174025: Regression in XML Transform caused by JDK-8087303 Reviewed-by: joehw, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
/*
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
     5
 * Licensed to the Apache Software Foundation (ASF) under one or more
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
     6
 * contributor license agreements.  See the NOTICE file distributed with
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
     7
 * this work for additional information regarding copyright ownership.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
     8
 * The ASF licenses this file to You under the Apache License, Version 2.0
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
     9
 * (the "License"); you may not use this file except in compliance with
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
    10
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
    20
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.serializer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import java.io.OutputStream;
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
    25
import java.io.OutputStreamWriter;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.io.UnsupportedEncodingException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.io.Writer;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
    28
import java.util.ArrayList;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
    29
import java.util.Arrays;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
    30
import java.util.EmptyStackException;
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
    31
import java.util.Enumeration;
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    32
import java.util.Iterator;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    33
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import java.util.Properties;
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
    35
import java.util.Set;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import java.util.StringTokenizer;
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    37
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import javax.xml.transform.ErrorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import javax.xml.transform.OutputKeys;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import javax.xml.transform.Transformer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import javax.xml.transform.TransformerException;
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    42
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import org.xml.sax.Attributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    48
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    49
import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    50
import com.sun.org.apache.xml.internal.serializer.utils.Utils;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    51
import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
    52
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * This abstract class is a base class for other stream
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * serializers (xml, html, text ...) that write output to a stream.
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
    59
abstract public class ToStream extends SerializerBase {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    private static final String COMMENT_BEGIN = "<!--";
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    private static final String COMMENT_END = "-->";
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    /** Stack to keep track of disabling output escaping. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    protected BoolStack m_disableOutputEscapingStates = new BoolStack();
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
     * The encoding information associated with this serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * Although initially there is no encoding,
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     * there is a dummy EncodingInfo object that will say
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * that every character is in the encoding. This is useful
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     * for a serializer that is in temporary output state and has
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     * no associated encoding. A serializer in final output state
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     * will have an encoding, and will worry about whether
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     * single chars or surrogate pairs of high/low chars form
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
     * characters in the output encoding.
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    EncodingInfo m_encodingInfo = new EncodingInfo(null,null);
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     * Method reference to the sun.io.CharToByteConverter#canConvert method
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     * for this encoding.  Invalid if m_charToByteConverter is null.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    java.lang.reflect.Method m_canConvertMeth;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     * Boolean that tells if we already tried to get the converter.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    boolean m_triedToGetConverter = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     * Opaque reference to the sun.io.CharToByteConverter for this
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     * encoding.
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    Object m_charToByteConverter = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    /**
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
    98
     * Used to buffer the text nodes and the entity reference nodes if
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
    99
     * indentation is on.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   100
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   101
    protected CharacterBuffer m_charactersBuffer = new CharacterBuffer();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   102
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   103
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   104
     * Used to decide if a text node is pretty-printed with indentation.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   105
     * If m_childNodeNum > 1, the text node will be indented.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   106
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   107
     */
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   108
    protected List<Integer> m_childNodeNumStack = new ArrayList<>();
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   109
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   110
    protected int m_childNodeNum = 0;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   111
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   112
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   113
     * Used to handle xml:space attribute
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   114
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   115
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   116
    protected BoolStack m_preserveSpaces = new BoolStack();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   117
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   118
    protected boolean m_ispreserveSpace = false;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   119
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
     * State flag that tells if the previous node processed
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
     * was text, so we can tell if we should preserve whitespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
     * Used in endDocument() and shouldIndent() but
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
     * only if m_doIndent is true.
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     * If m_doIndent is false this flag has no impact.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    protected boolean m_isprevtext = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
     * The maximum character size before we have to resort
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
     * to escaping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    protected int m_maxCharacter = Encodings.getLastPrintable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     * The system line separator for writing out line breaks.
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * The default value is from the system property,
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     * but this value can be set through the xsl:output
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     * extension attribute xalan:line-separator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    protected char[] m_lineSep =
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12902
diff changeset
   144
        SecuritySupport.getSystemProperty("line.separator").toCharArray();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * True if the the system line separator is to be used.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    protected boolean m_lineSepUse = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     * The length of the line seperator, since the write is done
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     * one character at a time.
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    protected int m_lineSepLen = m_lineSep.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     * Map that tells which characters should have special treatment, and it
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     *  provides character to entity name lookup.
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    protected CharInfo m_charInfo;
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    /** True if we control the buffer, and we should flush the output on endDocument. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    boolean m_shouldFlush = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * Add space before '/>' for XHTML.
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    protected boolean m_spaceBeforeClose = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     * Flag to signal that a newline should be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
     * Used only in indent() which is called only if m_doIndent is true.
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
     * If m_doIndent is false this flag has no impact.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    boolean m_startNewLine;
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     * Tells if we're in an internal document type subset.
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    protected boolean m_inDoctype = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    /**
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   185
     * Flag to quickly tell if the encoding is UTF8.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   186
     */
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    boolean m_isUTF8 = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     * remembers if we are in between the startCDATA() and endCDATA() callbacks
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    protected boolean m_cdataStartCalled = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     * If this flag is true DTD entity references are not left as-is,
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
     * which is exiting older behavior.
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    private boolean m_expandDTDEntities = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     * Default constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   203
    public ToStream() { }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
     * This helper method to writes out "]]>" when closing a CDATA section.
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   210
    protected void closeCDATA() throws org.xml.sax.SAXException {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   211
        try {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
            m_writer.write(CDATA_DELIMITER_CLOSE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            // write out a CDATA section closing "]]>"
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            m_cdataTagOpen = false; // Remember that we have done so.
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        }
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   216
        catch (IOException e) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     * Serializes the DOM node. Throws an exception only if an I/O
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
     * exception occured while serializing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
     * @param node Node to serialize.
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     * @throws IOException An I/O exception occured while serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   228
    public void serialize(Node node) throws IOException {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   229
        try {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   230
            TreeWalker walker = new TreeWalker(this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
            walker.traverse(node);
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   232
        } catch (org.xml.sax.SAXException se) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            throw new WrappedRuntimeException(se);
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
     * Return true if the character is the high member of a surrogate pair.
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
     * NEEDSDOC @param c
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
     * NEEDSDOC ($objectName$) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   244
    static final boolean isUTF16Surrogate(char c) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
        return (c & 0xFC00) == 0xD800;
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     * Taken from XSLTC
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    private boolean m_escaping = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
     * Flush the formatter's result stream.
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   258
    protected final void flushWriter() throws org.xml.sax.SAXException {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   259
        final Writer writer = m_writer;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   260
        if (null != writer) {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   261
            try {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   262
                if (writer instanceof WriterToUTF8Buffered) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
                    if (m_shouldFlush)
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   264
                        ((WriterToUTF8Buffered)writer).flush();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
                    else
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   266
                        ((WriterToUTF8Buffered)writer).flushBuffer();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
                }
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   268
                if (writer instanceof WriterToASCI) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
                    if (m_shouldFlush)
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                        writer.flush();
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   271
                } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                    // Flush always.
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
                    // Not a great thing if the writer was created
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
                    // by this class, but don't have a choice.
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
                    writer.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
                }
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   277
            } catch (IOException ioe) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
                throw new org.xml.sax.SAXException(ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   283
    OutputStream m_outputStream;
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   284
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
     * Get the output stream where the events will be serialized to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
     * @return reference to the result stream, or null of only a writer was
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
     * set.
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   291
    public OutputStream getOutputStream() {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   292
        return m_outputStream;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    // Implement DeclHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
     *   Report an element type declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     *   <p>The content model will consist of the string "EMPTY", the
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     *   string "ANY", or a parenthesised group, optionally followed
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
     *   by an occurrence indicator.  The model will be normalized so
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
     *   that all whitespace is removed,and will include the enclosing
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
     *   parentheses.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
     *   @param name The element type name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
     *   @param model The content model as a normalized string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
     *   @exception SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
    public void elementDecl(String name, String model) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        // Do not inline external DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        if (m_inExternalDTD)
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
            return;
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   315
        try {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   316
            final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
            DTDprolog();
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
            writer.write("<!ELEMENT ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
            writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
            writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
            writer.write(model);
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
            writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
            writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     * Report an internal entity declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
     * <p>Only the effective (first) declaration for each entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
     * will be reported.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
     * @param name The name of the entity.  If it is a parameter
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
     *        entity, the name will begin with '%'.
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
     * @param value The replacement text of the entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
     * @exception SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
     * @see #externalEntityDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     * @see org.xml.sax.DTDHandler#unparsedEntityDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
    public void internalEntityDecl(String name, String value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
        // Do not inline external DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        if (m_inExternalDTD)
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
            return;
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   352
        try {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
            DTDprolog();
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
            outputEntityDecl(name, value);
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   355
        } catch (IOException e) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     * Output the doc type declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
     * @param name non-null reference to document type name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
     * NEEDSDOC @param value
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    void outputEntityDecl(String name, String value) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   371
        final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        writer.write("<!ENTITY ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        writer.write(" \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
        writer.write(value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        writer.write("\">");
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
        writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
     * Output a system-dependent line break.
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   385
    protected final void outputLineSep() throws IOException {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
        m_writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   389
    void setProp(String name, String val, boolean defaultVal) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   390
        if (val != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   391
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   392
            char first = getFirstCharLocName(name);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   393
            switch (first) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   394
            case 'c':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   395
                if (OutputKeys.CDATA_SECTION_ELEMENTS.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   396
                    addCdataSectionElements(val); // val is cdataSectionNames
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   397
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   398
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   399
            case 'd':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   400
                if (OutputKeys.DOCTYPE_SYSTEM.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   401
                    this.m_doctypeSystem = val;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   402
                } else if (OutputKeys.DOCTYPE_PUBLIC.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   403
                    this.m_doctypePublic = val;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   404
                    if (val.startsWith("-//W3C//DTD XHTML"))
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   405
                        m_spaceBeforeClose = true;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   406
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   407
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   408
            case 'e':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   409
                String newEncoding = val;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   410
                if (OutputKeys.ENCODING.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   411
                    String possible_encoding = Encodings.getMimeEncoding(val);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   412
                    if (possible_encoding != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   413
                        // if the encoding is being set, try to get the
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   414
                        // preferred
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   415
                        // mime-name and set it too.
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   416
                        super.setProp("mime-name", possible_encoding,
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   417
                                defaultVal);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   418
                    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   419
                    final String oldExplicitEncoding = getOutputPropertyNonDefault(OutputKeys.ENCODING);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   420
                    final String oldDefaultEncoding  = getOutputPropertyDefault(OutputKeys.ENCODING);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   421
                    if ( (defaultVal && ( oldDefaultEncoding == null || !oldDefaultEncoding.equalsIgnoreCase(newEncoding)))
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   422
                            || ( !defaultVal && (oldExplicitEncoding == null || !oldExplicitEncoding.equalsIgnoreCase(newEncoding) ))) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   423
                       // We are trying to change the default or the non-default setting of the encoding to a different value
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   424
                       // from what it was
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   425
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   426
                       EncodingInfo encodingInfo = Encodings.getEncodingInfo(newEncoding);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   427
                       if (newEncoding != null && encodingInfo.name == null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   428
                        // We tried to get an EncodingInfo for Object for the given
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   429
                        // encoding, but it came back with an internall null name
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   430
                        // so the encoding is not supported by the JDK, issue a message.
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   431
                        final String msg = Utils.messages.createMessage(
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   432
                                MsgKey.ER_ENCODING_NOT_SUPPORTED,new Object[]{ newEncoding });
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   433
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   434
                        final String msg2 =
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   435
                            "Warning: encoding \"" + newEncoding + "\" not supported, using "
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   436
                                   + Encodings.DEFAULT_MIME_ENCODING;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   437
                        try {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   438
                                // Prepare to issue the warning message
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   439
                                final Transformer tran = super.getTransformer();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   440
                                if (tran != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   441
                                    final ErrorListener errHandler = tran
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   442
                                            .getErrorListener();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   443
                                    // Issue the warning message
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   444
                                    if (null != errHandler
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   445
                                            && m_sourceLocator != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   446
                                        errHandler
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   447
                                                .warning(new TransformerException(
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   448
                                                        msg, m_sourceLocator));
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   449
                                        errHandler
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   450
                                                .warning(new TransformerException(
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   451
                                                        msg2, m_sourceLocator));
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   452
                                    } else {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   453
                                        System.out.println(msg);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   454
                                        System.out.println(msg2);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   455
                                    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   456
                                } else {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   457
                                    System.out.println(msg);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   458
                                    System.out.println(msg2);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   459
                                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   460
                            } catch (Exception e) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   461
                            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   462
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   463
                            // We said we are using UTF-8, so use it
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   464
                            newEncoding = Encodings.DEFAULT_MIME_ENCODING;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   465
                            val = Encodings.DEFAULT_MIME_ENCODING; // to store the modified value into the properties a little later
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   466
                            encodingInfo = Encodings.getEncodingInfo(newEncoding);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   467
                        }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   468
                       // The encoding was good, or was forced to UTF-8 above
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   469
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   470
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   471
                       // If there is already a non-default set encoding and we
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   472
                       // are trying to set the default encoding, skip the this block
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   473
                       // as the non-default value is already the one to use.
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   474
                       if (defaultVal == false || oldExplicitEncoding == null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   475
                           m_encodingInfo = encodingInfo;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   476
                           if (newEncoding != null)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   477
                               m_isUTF8 = newEncoding.equals(Encodings.DEFAULT_MIME_ENCODING);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   478
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   479
                           // if there was a previously set OutputStream
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   480
                           OutputStream os = getOutputStream();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   481
                           if (os != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   482
                               Writer w = getWriter();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   483
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   484
                               // If the writer was previously set, but
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   485
                               // set by the user, or if the new encoding is the same
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   486
                               // as the old encoding, skip this block
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   487
                               String oldEncoding = getOutputProperty(OutputKeys.ENCODING);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   488
                               if ((w == null || !m_writer_set_by_user)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   489
                                       && !newEncoding.equalsIgnoreCase(oldEncoding)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   490
                                   // Make the change of encoding in our internal
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   491
                                   // table, then call setOutputStreamInternal
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   492
                                   // which will stomp on the old Writer (if any)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   493
                                   // with a new Writer with the new encoding.
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   494
                                   super.setProp(name, val, defaultVal);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   495
                                   setOutputStreamInternal(os,false);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   496
                               }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   497
                           }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   498
                       }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   499
                    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   500
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   501
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   502
            case 'i':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   503
                if (OutputPropertiesFactory.S_KEY_INDENT_AMOUNT.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   504
                    setIndentAmount(Integer.parseInt(val));
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   505
                } else if (OutputKeys.INDENT.equals(name)) {
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 24888
diff changeset
   506
                    boolean b = val.endsWith("yes") ? true : false;
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   507
                    m_doIndent = b;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   508
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   509
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   510
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   511
            case 'l':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   512
                if (OutputPropertiesFactory.S_KEY_LINE_SEPARATOR.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   513
                    m_lineSep = val.toCharArray();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   514
                    m_lineSepLen = m_lineSep.length;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   515
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   516
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   517
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   518
            case 'm':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   519
                if (OutputKeys.MEDIA_TYPE.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   520
                    m_mediatype = val;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   521
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   522
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   523
            case 'o':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   524
                if (OutputKeys.OMIT_XML_DECLARATION.equals(name)) {
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 24888
diff changeset
   525
                    boolean b = val.endsWith("yes") ? true : false;
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   526
                    this.m_shouldNotWriteXMLHeader = b;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   527
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   528
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   529
            case 's':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   530
                // if standalone was explicitly specified
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   531
                if (OutputKeys.STANDALONE.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   532
                    if (defaultVal) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   533
                        setStandaloneInternal(val);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   534
                    } else {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   535
                        m_standaloneWasSpecified = true;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   536
                        setStandaloneInternal(val);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   537
                    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   538
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   539
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   540
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   541
            case 'v':
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   542
                if (OutputKeys.VERSION.equals(name)) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   543
                    m_version = val;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   544
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   545
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   546
            default:
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   547
                break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   548
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   549
            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   550
            super.setProp(name, val, defaultVal);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   551
        }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   552
    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   553
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
     * Specifies an output format for this serializer. It the
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
     * serializer has already been associated with an output format,
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
     * it will switch to the new format. This method should not be
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
     * called while the serializer is in the process of serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
     * a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
     * @param format The output format to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   563
    public void setOutputFormat(Properties format) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
        boolean shouldFlush = m_shouldFlush;
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   566
        if (format != null) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   567
            // Set the default values first,
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   568
            // and the non-default values after that,
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   569
            // just in case there is some unexpected
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   570
            // residual values left over from over-ridden default values
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   571
            Enumeration propNames;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   572
            propNames = format.propertyNames();
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   573
            while (propNames.hasMoreElements()) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   574
                String key = (String) propNames.nextElement();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   575
                // Get the value, possibly a default value
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   576
                String value = format.getProperty(key);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   577
                // Get the non-default value (if any).
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   578
                String explicitValue = (String) format.get(key);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   579
                if (explicitValue == null && value != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   580
                    // This is a default value
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   581
                    this.setOutputPropertyDefault(key,value);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   582
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   583
                if (explicitValue != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   584
                    // This is an explicit non-default value
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   585
                    this.setOutputProperty(key,explicitValue);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   586
                }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
        // Access this only from the Hashtable level... we don't want to
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
        // get default properties.
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
        String entitiesFileName =
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
            (String) format.get(OutputPropertiesFactory.S_KEY_ENTITIES);
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   595
        if (null != entitiesFileName) {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   596
            String method = (String) format.get(OutputKeys.METHOD);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
            m_charInfo = CharInfo.getCharInfo(entitiesFileName, method);
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   600
        m_shouldFlush = shouldFlush;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
     * Returns the output format for this serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
     * @return The output format in use
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
     */
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   608
    public Properties getOutputFormat() {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   609
        Properties def = new Properties();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   610
        {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   611
            Set<String> s = getOutputPropDefaultKeys();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   612
            for (String key : s) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   613
                String val = getOutputPropertyDefault(key);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   614
                def.put(key, val);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   615
            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   616
        }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   617
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   618
        Properties props = new Properties(def);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   619
        {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   620
            Set<String> s = getOutputPropKeys();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   621
            for (String key : s) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   622
                String val = getOutputPropertyNonDefault(key);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   623
                if (val != null)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   624
                    props.put(key, val);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   625
            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   626
        }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   627
        return props;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
     * Specifies a writer to which the document should be serialized.
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
     * This method should not be called while the serializer is in
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
     * the process of serializing a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
     * @param writer The output writer stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   637
    public void setWriter(Writer writer) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   638
        setWriterInternal(writer, true);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   639
    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   640
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   641
    private boolean m_writer_set_by_user;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   642
    private void setWriterInternal(Writer writer, boolean setByUser) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   643
        m_writer_set_by_user = setByUser;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   644
        m_writer = writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
        // if we are tracing events we need to trace what
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
        // characters are written to the output writer.
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   647
        if (m_tracer != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   648
            boolean noTracerYet = true;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   649
            Writer w2 = m_writer;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   650
            while (w2 instanceof WriterChain) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   651
                if (w2 instanceof SerializerTraceWriter) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   652
                    noTracerYet = false;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   653
                    break;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   654
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   655
                w2 = ((WriterChain)w2).getWriter();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   656
            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   657
            if (noTracerYet)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   658
                m_writer = new SerializerTraceWriter(m_writer, m_tracer);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   659
        }
6
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
     * Set if the operating systems end-of-line line separator should
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
     * be used when serializing.  If set false NL character
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
     * (decimal 10) is left alone, otherwise the new-line will be replaced on
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
     * output with the systems line separator. For example on UNIX this is
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
     * NL, while on Windows it is two characters, CR NL, where CR is the
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
     * carriage-return (decimal 13).
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
     * @param use_sytem_line_break True if an input NL is replaced with the
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
     * operating systems end-of-line separator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
     * @return The previously set value of the serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   674
    public boolean setLineSepUse(boolean use_sytem_line_break) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
        boolean oldValue = m_lineSepUse;
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
        m_lineSepUse = use_sytem_line_break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
        return oldValue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
     * Specifies an output stream to which the document should be
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
     * serialized. This method should not be called while the
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
     * serializer is in the process of serializing a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
     * The encoding specified in the output properties is used, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
     * if no encoding was specified, the default for the selected
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
     * output method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
     * @param output The output stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   691
    public void setOutputStream(OutputStream output) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   692
        setOutputStreamInternal(output, true);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   693
    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   694
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   695
    private void setOutputStreamInternal(OutputStream output, boolean setByUser)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   696
    {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   697
        m_outputStream = output;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   698
        String encoding = getOutputProperty(OutputKeys.ENCODING);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   699
        if (Encodings.DEFAULT_MIME_ENCODING.equalsIgnoreCase(encoding))
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   700
        {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   701
            // We wrap the OutputStream with a writer, but
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   702
            // not one set by the user
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   703
            try {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   704
                setWriterInternal(new WriterToUTF8Buffered(output), false);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   705
            } catch (UnsupportedEncodingException e) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   706
                e.printStackTrace();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   707
            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   708
        } else if (
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   709
                "WINDOWS-1250".equals(encoding)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   710
                || "US-ASCII".equals(encoding)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   711
                || "ASCII".equals(encoding))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
        {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   713
            setWriterInternal(new WriterToASCI(output), false);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   714
        } else if (encoding != null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   715
            Writer osw = null;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   716
                try
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   717
                {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   718
                    osw = Encodings.getWriter(output, encoding);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   719
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   720
                catch (UnsupportedEncodingException uee)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   721
                {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   722
                    osw = null;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   723
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   724
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   725
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   726
            if (osw == null) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   727
                System.out.println(
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   728
                    "Warning: encoding \""
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   729
                        + encoding
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   730
                        + "\" not supported"
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   731
                        + ", using "
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   732
                        + Encodings.DEFAULT_MIME_ENCODING);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   733
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   734
                encoding = Encodings.DEFAULT_MIME_ENCODING;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   735
                setEncoding(encoding);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   736
                try {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   737
                    osw = Encodings.getWriter(output, encoding);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   738
                } catch (UnsupportedEncodingException e) {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   739
                    // We can't really get here, UTF-8 is always supported
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   740
                    // This try-catch exists to make the compiler happy
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   741
                    e.printStackTrace();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   742
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   743
            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   744
            setWriterInternal(osw,false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
        }
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   746
        else {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   747
            // don't have any encoding, but we have an OutputStream
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   748
            Writer osw = new OutputStreamWriter(output);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   749
            setWriterInternal(osw,false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
   753
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
     * @see SerializationHandler#setEscaping(boolean)
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
    public boolean setEscaping(boolean escape)
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
        final boolean temp = m_escaping;
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
        m_escaping = escape;
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
        return temp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
     * Might print a newline character and the indentation amount
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
     * of the given depth.
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
     * @param depth the indentation depth (element nesting depth)
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
     * @throws org.xml.sax.SAXException if an error occurs during writing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
    protected void indent(int depth) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
        if (m_startNewLine)
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
            outputLineSep();
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   779
        /*
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   780
         * Default value is 4, so printSpace directly.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
         */
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
   782
        printSpace(depth * m_indentAmount);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
     * Indent at the current element nesting depth.
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
     * @throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
    protected void indent() throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
        indent(m_elemContext.m_currentElemDepth);
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
     * Prints <var>n</var> spaces.
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
     * @param n         Number of spaces to print.
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
     * @throws org.xml.sax.SAXException if an error occurs when writing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
    private void printSpace(int n) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
    {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   802
        final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
        for (int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
            writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
     * Report an attribute type declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
     * <p>Only the effective (first) declaration for an attribute will
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
     * be reported.  The type will be one of the strings "CDATA",
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
     * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY",
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
     * "ENTITIES", or "NOTATION", or a parenthesized token group with
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
     * the separator "|" and all whitespace removed.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
     * @param eName The name of the associated element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
     * @param aName The name of the attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
     * @param type A string representing the attribute type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
     * @param valueDefault A string representing the attribute default
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
     *        ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
     *        none of these applies.
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
     * @param value A string representing the attribute's default value,
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
     *        or null if there is none.
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
     * @exception SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
    public void attributeDecl(
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
        String eName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
        String aName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
        String type,
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
        String valueDefault,
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
        String value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
        // Do not inline external DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
        if (m_inExternalDTD)
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
        {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   842
            final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
            DTDprolog();
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
            writer.write("<!ATTLIST ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
            writer.write(eName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
            writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
            writer.write(aName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
            writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
            writer.write(type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
            if (valueDefault != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
                writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
                writer.write(valueDefault);
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
            //writer.write(" ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
            //writer.write(value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
            writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
            writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
     * Get the character stream where the events will be serialized to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
     * @return Reference to the result Writer, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
    public Writer getWriter()
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
        return m_writer;
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
     * Report a parsed external entity declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
     * <p>Only the effective (first) declaration for each entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
     * will be reported.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
     * @param name The name of the entity.  If it is a parameter
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
     *        entity, the name will begin with '%'.
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
     * @param publicId The declared public identifier of the entity, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
     *        null if none was declared.
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
     * @param systemId The declared system identifier of the entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
     * @exception SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
     * @see #internalEntityDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
     * @see org.xml.sax.DTDHandler#unparsedEntityDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
    public void externalEntityDecl(
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
        String name,
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
        String publicId,
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
        String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
            DTDprolog();
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
            m_writer.write("<!ENTITY ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
            m_writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
            if (publicId != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
                m_writer.write(" PUBLIC \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
                m_writer.write(publicId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
                m_writer.write(" SYSTEM \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
                m_writer.write(systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
            m_writer.write("\" >");
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
            m_writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
        } catch (IOException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
            // TODO Auto-generated catch block
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
            e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
     * Tell if this character can be written without escaping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
    protected boolean escapingNotNeeded(char ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
        final boolean ret;
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
        if (ch < 127)
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
            // This is the old/fast code here, but is this
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
            // correct for all encodings?
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
   933
            if (ch >= 0x20 || (0x0A == ch || 0x0D == ch || 0x09 == ch))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
                ret= true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
                ret = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
            ret = m_encodingInfo.isInEncoding(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
        return ret;
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
     * Once a surrogate has been detected, write out the pair of
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
     * characters if it is in the encoding, or if there is no
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
     * encoding, otherwise write out an entity reference
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
     * of the value of the unicode code point of the character
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
     * represented by the high/low surrogate pair.
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
     * An exception is thrown if there is no low surrogate in the pair,
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
     * because the array ends unexpectely, or if the low char is there
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
     * but its value is such that it is not a low surrogate.
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
     * @param c the first (high) part of the surrogate, which
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
     * must be confirmed before calling this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
     * @param ch Character array.
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
     * @param i position Where the surrogate was detected.
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
     * @param end The end index of the significant characters.
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
     * @return 0 if the pair of characters was written out as-is,
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
     * the unicode code point of the character represented by
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
     * the surrogate pair if an entity reference with that value
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
     * was written out.
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
     * @throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
     * @throws org.xml.sax.SAXException if invalid UTF-16 surrogate detected.
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
    protected int writeUTF16Surrogate(char c, char ch[], int i, int end)
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
        int codePoint = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
        if (i + 1 >= end)
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
            throw new IOException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
                Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
                    MsgKey.ER_INVALID_UTF16_SURROGATE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
                    new Object[] { Integer.toHexString((int) c)}));
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
        final char high = c;
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
        final char low = ch[i+1];
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
        if (!Encodings.isLowUTF16Surrogate(low)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
            throw new IOException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
                Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
                    MsgKey.ER_INVALID_UTF16_SURROGATE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
                    new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
                        Integer.toHexString((int) c)
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
                            + " "
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
                            + Integer.toHexString(low)}));
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
   992
        final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
        // If we make it to here we have a valid high, low surrogate pair
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
        if (m_encodingInfo.isInEncoding(c,low)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
            // If the character formed by the surrogate pair
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
            // is in the encoding, so just write it out
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
            writer.write(ch,i,2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
            // Don't know what to do with this char, it is
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
            // not in the encoding and not a high char in
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
            // a surrogate pair, so write out as an entity ref
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
            final String encoding = getEncoding();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
            if (encoding != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
                /* The output encoding is known,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
                 * so somthing is wrong.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
                  */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
                codePoint = Encodings.toCodePoint(high, low);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
                // not in the encoding, so write out a character reference
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
                writer.write('&');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
                writer.write('#');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
                writer.write(Integer.toString(codePoint));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
                writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
                /* The output encoding is not known,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
                 * so just write it out as-is.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
                 */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
                writer.write(ch, i, 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
        // non-zero only if character reference was written out.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
        return codePoint;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
     * Handle one of the default entities, return false if it
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
     * is not a default entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
     * @param ch character to be escaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
     * @param i index into character array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
     * @param chars non-null reference to character array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
     * @param len length of chars.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
     * @param fromTextNode true if the characters being processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
     * are from a text node, false if they are from an attribute value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
     * @param escLF true if the linefeed should be escaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
     * @return i+1 if the character was written, else i.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
     * @throws java.io.IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
     */
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1042
    protected int accumDefaultEntity(
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  1043
        Writer writer,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
        char ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
        int i,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
        char[] chars,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
        int len,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
        boolean fromTextNode,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
        boolean escLF)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
        if (!escLF && CharInfo.S_LINEFEED == ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
            writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
            // if this is text node character and a special one of those,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
            // or if this is a character from attribute value and a special one of those
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1061
            if ((fromTextNode && m_charInfo.isSpecialTextChar(ch)) || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch)))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
                String outputStringForChar = m_charInfo.getOutputStringForChar(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
                if (null != outputStringForChar)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
                    writer.write(outputStringForChar);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
                    return i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
                return i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
        return i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
     * Normalize the characters, but don't escape.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
     * @param ch The characters from the XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
     * @param start The start position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
     * @param length The number of characters to read from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
     * @param isCData true if a CDATA block should be built around the characters.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
     * @param useSystemLineSeparator true if the operating systems
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
     * end-of-line separator should be output rather than a new-line character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
     * @throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
    void writeNormalizedChars(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
        char ch[],
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
        int start,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
        int length,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
        boolean isCData,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
        boolean useSystemLineSeparator)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
        throws IOException, org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
    {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  1100
        final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
        int end = start + length;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
        for (int i = start; i < end; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
            char c = ch[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
            if (CharInfo.S_LINEFEED == c && useSystemLineSeparator)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
                writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
            else if (isCData && (!escapingNotNeeded(c)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
                //                if (i != 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
                if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
                    closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
                // This needs to go into a function...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
                if (Encodings.isHighUTF16Surrogate(c))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
                    writeUTF16Surrogate(c, ch, i, end);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
                    i++ ; // process two input characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
                    writer.write("&#");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
                    String intStr = Integer.toString((int) c);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
                    writer.write(intStr);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
                    writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
                //                if ((i != 0) && (i < (end - 1)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
                //                if (!m_cdataTagOpen && (i < (end - 1)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
                //                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
                //                    writer.write(CDATA_DELIMITER_OPEN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
                //                    m_cdataTagOpen = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
                //                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
            else if (
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
                isCData
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
                    && ((i < (end - 2))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
                        && (']' == c)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
                        && (']' == ch[i + 1])
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
                        && ('>' == ch[i + 2])))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
                writer.write(CDATA_CONTINUE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
                i += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
                if (escapingNotNeeded(c))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
                    if (isCData && !m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
                        writer.write(CDATA_DELIMITER_OPEN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
                        m_cdataTagOpen = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
                    writer.write(c);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
                // This needs to go into a function...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
                else if (Encodings.isHighUTF16Surrogate(c))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
                    if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
                        closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
                    writeUTF16Surrogate(c, ch, i, end);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
                    i++; // process two input characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
                    if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
                        closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
                    writer.write("&#");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
                    String intStr = Integer.toString((int) c);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
                    writer.write(intStr);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
                    writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
     * Ends an un-escaping section.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
     * @see #startNonEscaping
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
    public void endNonEscaping() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
        m_disableOutputEscapingStates.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
     * Starts an un-escaping section. All characters printed within an un-
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
     * escaping section are printed as is, without escaping special characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
     * into entity references. Only XML and HTML serializers need to support
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
     * this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
     * <p> The contents of the un-escaping section will be delivered through the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
     * regular <tt>characters</tt> event.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
    public void startNonEscaping() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
        m_disableOutputEscapingStates.push(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
     * Receive notification of cdata.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
     * <p>The Parser will call this method to report each chunk of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
     * character data.  SAX parsers may return all contiguous character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
     * data in a single chunk, or they may split it into several
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
     * chunks; however, all of the characters in any single event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
     * must come from the same external entity, so that the Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
     * provides useful information.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
     * <p>The application must not attempt to read from the array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
     * outside of the specified range.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
     * <p>Note that some parsers will report whitespace using the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
     * ignorableWhitespace() method rather than this one (validating
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
     * parsers must do so).</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
     * @param ch The characters from the XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
     * @param start The start position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
     * @param length The number of characters to read from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
     * @see #ignorableWhitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
     * @see org.xml.sax.Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
    protected void cdata(char ch[], int start, final int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
            final int old_start = start;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
            if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
                closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
                m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
            if (shouldIndent())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
                indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
            boolean writeCDataBrackets =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
                (((length >= 1) && escapingNotNeeded(ch[start])));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
            /* Write out the CDATA opening delimiter only if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
             * we are supposed to, and if we are not already in
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
             * the middle of a CDATA section
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
            if (writeCDataBrackets && !m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
                m_writer.write(CDATA_DELIMITER_OPEN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
                m_cdataTagOpen = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
            // writer.write(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
            if (isEscapingDisabled())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
                charactersRaw(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
                writeNormalizedChars(ch, start, length, true, m_lineSepUse);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
            /* used to always write out CDATA closing delimiter here,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
             * but now we delay, so that we can merge CDATA sections on output.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
             * need to write closing delimiter later
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
            if (writeCDataBrackets)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
                /* if the CDATA section ends with ] don't leave it open
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
                 * as there is a chance that an adjacent CDATA sections
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
                 * starts with ]>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
                 * We don't want to merge ]] with > , or ] with ]>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
                 */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
                if (ch[start + length - 1] == ']')
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
                    closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
            // time to fire off CDATA event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
            if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
                super.fireCDATAEvent(ch, old_start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
        catch (IOException ioe)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
            throw new org.xml.sax.SAXException(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
                Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
                    MsgKey.ER_OIERROR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
                    null),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
                ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
            //"IO error", ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
     * Tell if the character escaping should be disabled for the current state.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
     * @return true if the character escaping should be disabled.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
    private boolean isEscapingDisabled()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
        return m_disableOutputEscapingStates.peekOrFalse();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
     * If available, when the disable-output-escaping attribute is used,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
     * output raw text without escaping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
     * @param ch The characters from the XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
     * @param start The start position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
     * @param length The number of characters to read from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
    protected void charactersRaw(char ch[], int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1331
        if (isInEntityRef())
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
            if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
                closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
                m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
            m_writer.write(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
     * Receive notification of character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
     * <p>The Parser will call this method to report each chunk of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
     * character data.  SAX parsers may return all contiguous character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
     * data in a single chunk, or they may split it into several
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
     * chunks; however, all of the characters in any single event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
     * must come from the same external entity, so that the Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
     * provides useful information.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
     * <p>The application must not attempt to read from the array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
     * outside of the specified range.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
     * <p>Note that some parsers will report whitespace using the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
     * ignorableWhitespace() method rather than this one (validating
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
     * parsers must do so).</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
     * @param chars The characters from the XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
     * @param start The start position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
     * @param length The number of characters to read from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
     * @see #ignorableWhitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
     * @see org.xml.sax.Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
    public void characters(final char chars[], final int start, final int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
        // It does not make sense to continue with rest of the method if the number of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
        // characters to read from array is 0.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
        // Section 7.6.1 of XSLT 1.0 (http://www.w3.org/TR/xslt#value-of) suggest no text node
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
        // is created if string is empty.
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1384
        if (length == 0 || (isInEntityRef()))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
            return;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1386
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1387
        final boolean shouldNotFormat = !shouldFormatOutput();
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1388
        if (m_elemContext.m_startTagOpen)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
            closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
            m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
        else if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
            startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
        if (m_cdataStartCalled || m_elemContext.m_isCdataSection)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
            /* either due to startCDATA() being called or due to
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
             * cdata-section-elements atribute, we need this as cdata
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
            cdata(chars, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
        if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
            closeCDATA();
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1410
        // the check with _escaping is a bit of a hack for XLSTC
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
        if (m_disableOutputEscapingStates.peekOrFalse() || (!m_escaping))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
        {
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1414
            if (shouldNotFormat) {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1415
                charactersRaw(chars, start, length);
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1416
                m_isprevtext = true;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1417
            } else {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1418
                m_charactersBuffer.addRawText(chars, start, length);
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1419
            }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
            // time to fire off characters generation event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
            if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
                super.fireCharEvent(chars, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1427
        if (m_elemContext.m_startTagOpen)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
            closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
            m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1433
        if (shouldNotFormat) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1434
            outputCharacters(chars, start, length);
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1435
        } else {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1436
            m_charactersBuffer.addText(chars, start, length);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1437
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1438
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1439
        // time to fire off characters generation event
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1440
        if (m_tracer != null)
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1441
            super.fireCharEvent(chars, start, length);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1442
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1443
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1444
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1445
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1446
     * This method checks if the content in current element should be formatted.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1447
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1448
     * @return True if the content should be formatted.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1449
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1450
    protected boolean shouldFormatOutput() {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1451
        return m_doIndent && !m_ispreserveSpace;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1452
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1453
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1454
    /**
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1455
     * @return True if the content in current element should be formatted.
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1456
     */
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1457
    public boolean getIndent() {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1458
        return shouldFormatOutput();
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1459
    }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1460
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1461
    /**
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1462
     * Write out the characters.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1463
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1464
     * @param chars The characters of the text.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1465
     * @param start The start position in the char array.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1466
     * @param length The number of characters from the char array.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1467
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1468
    private void outputCharacters(final char chars[], final int start, final int length) throws SAXException {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
            int i;
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1472
            char ch1;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
            int startClean;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
            // skip any leading whitspace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
            // don't go off the end and use a hand inlined version
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
            // of isWhitespace(ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1478
            final int end = start + length;
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1479
            int lastDirty = start - 1; // last character that needed processing
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1480
            for (i = start;
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1481
                ((i < end)
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1482
                    && ((ch1 = chars[i]) == 0x20
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1483
                        || (ch1 == 0xA && m_lineSepUse)
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1484
                        || ch1 == 0xD
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1485
                        || ch1 == 0x09));
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1486
                i++)
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1487
            {
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1488
                /*
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1489
                 * We are processing leading whitespace, but are doing the same
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1490
                 * processing for dirty characters here as for non-whitespace.
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1491
                 *
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1492
                 */
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1493
                if (!m_charInfo.isTextASCIIClean(ch1))
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1494
                {
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1495
                    lastDirty = processDirty(chars,end, i,ch1, lastDirty, true);
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1496
                    i = lastDirty;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
            }
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1499
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1500
//          int lengthClean;    // number of clean characters in a row
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1501
//          final boolean[] isAsciiClean = m_charInfo.getASCIIClean();
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1502
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1503
            final boolean isXML10 = XMLVERSION10.equals(getVersion());
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1504
            // we've skipped the leading whitespace, now deal with the rest
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
            for (; i < end; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
            {
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1507
                {
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1508
                    // A tight loop to skip over common clean chars
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1509
                    // This tight loop makes it easier for the JIT
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1510
                    // to optimize.
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1511
                    char ch2;
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1512
                    while (i<end
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1513
                            && ((ch2 = chars[i])<127)
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1514
                            && m_charInfo.isTextASCIIClean(ch2))
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1515
                            i++;
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1516
                    if (i == end)
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1517
                        break;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1518
                }
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1519
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1520
                final char ch = chars[i];
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1521
                /*  The check for isCharacterInC0orC1Ranger and
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1522
                 *  isNELorLSEPCharacter has been added
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1523
                 *  to support Control Characters in XML 1.1
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1524
                 */
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1525
                if (!isCharacterInC0orC1Range(ch) &&
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1526
                    (isXML10 || !isNELorLSEPCharacter(ch)) &&
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1527
                    (escapingNotNeeded(ch) && (!m_charInfo.isSpecialTextChar(ch)))
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1528
                        || ('"' == ch))
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1529
                {
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1530
                    ; // a character needing no special processing
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  1531
                }
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1532
                else
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1533
                {
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1534
                    lastDirty = processDirty(chars,end, i, ch, lastDirty, true);
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1535
                    i = lastDirty;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
            // we've reached the end. Any clean characters at the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1540
            // end of the array than need to be written out?
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1541
            startClean = lastDirty + 1;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1542
            if (i > startClean)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1543
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1544
                int lengthClean = i - startClean;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1545
                m_writer.write(chars, startClean, lengthClean);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1546
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1547
7f561c08de6b Initial load
duke
parents:
diff changeset
  1548
            // For indentation purposes, mark that we've just writen text out
7f561c08de6b Initial load
duke
parents:
diff changeset
  1549
            m_isprevtext = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1550
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1551
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1552
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1553
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1554
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1555
    }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1556
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1557
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1558
     * Used to flush the buffered characters when indentation is on, this method
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1559
     * will be called when the next node is traversed.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1560
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1561
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1562
    final protected void flushCharactersBuffer() throws SAXException {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1563
        try {
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1564
            if (shouldFormatOutput() && m_charactersBuffer.isAnyCharactersBuffered()) {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1565
                if (m_elemContext.m_isCdataSection) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1566
                    /*
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1567
                     * due to cdata-section-elements atribute, we need this as
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1568
                     * cdata
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1569
                     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1570
                    char[] chars = m_charactersBuffer.toChars();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1571
                    cdata(chars, 0, chars.length);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1572
                    return;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1573
                }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1574
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1575
                m_childNodeNum++;
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1576
                boolean skipBeginningNewlines = false;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1577
                if (shouldIndentForText()) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1578
                    indent();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1579
                    m_startNewLine = true;
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1580
                    // newline has always been added here because if this is the
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1581
                    // text before the first element, shouldIndent() won't
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1582
                    // return true.
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1583
                    skipBeginningNewlines = true;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1584
                }
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  1585
                m_charactersBuffer.flush(skipBeginningNewlines);
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1586
            }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1587
        } catch (IOException e) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1588
            throw new SAXException(e);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1589
        } finally {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1590
            m_charactersBuffer.clear();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1591
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1592
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1593
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1594
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1595
     * True if should indent in flushCharactersBuffer method.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1596
     * This method may be overridden in sub-class.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1597
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1598
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1599
    protected boolean shouldIndentForText() {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1600
        return (shouldIndent() && m_childNodeNum > 1);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1601
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1602
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1603
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1604
     * This method checks if a given character is between C0 or C1 range
7f561c08de6b Initial load
duke
parents:
diff changeset
  1605
     * of Control characters.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1606
     * This method is added to support Control Characters for XML 1.1
7f561c08de6b Initial load
duke
parents:
diff changeset
  1607
     * If a given character is TAB (0x09), LF (0x0A) or CR (0x0D), this method
7f561c08de6b Initial load
duke
parents:
diff changeset
  1608
     * return false. Since they are whitespace characters, no special processing is needed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1609
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1610
     * @param ch
7f561c08de6b Initial load
duke
parents:
diff changeset
  1611
     * @return boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
  1612
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1613
    private static boolean isCharacterInC0orC1Range(char ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1614
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1615
        if(ch == 0x09 || ch == 0x0A || ch == 0x0D)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1616
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1617
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1618
                return (ch >= 0x7F && ch <= 0x9F)|| (ch >= 0x01 && ch <= 0x1F);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1619
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1620
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1621
     * This method checks if a given character either NEL (0x85) or LSEP (0x2028)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1622
     * These are new end of line charcters added in XML 1.1.  These characters must be
7f561c08de6b Initial load
duke
parents:
diff changeset
  1623
     * written as Numeric Character References (NCR) in XML 1.1 output document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1624
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1625
     * @param ch
7f561c08de6b Initial load
duke
parents:
diff changeset
  1626
     * @return boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
  1627
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1628
    private static boolean isNELorLSEPCharacter(char ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1629
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1630
        return (ch == 0x85 || ch == 0x2028);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1631
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1632
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1633
     * Process a dirty character and any preeceding clean characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  1634
     * that were not yet processed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1635
     * @param chars array of characters being processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1636
     * @param end one (1) beyond the last character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1637
     * in chars to be processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1638
     * @param i the index of the dirty character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1639
     * @param ch the character in chars[i]
7f561c08de6b Initial load
duke
parents:
diff changeset
  1640
     * @param lastDirty the last dirty character previous to i
7f561c08de6b Initial load
duke
parents:
diff changeset
  1641
     * @param fromTextNode true if the characters being processed are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1642
     * from a text node, false if they are from an attribute value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1643
     * @return the index of the last character processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1644
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1645
    private int processDirty(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1646
        char[] chars,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1647
        int end,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1648
        int i,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1649
        char ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1650
        int lastDirty,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1651
        boolean fromTextNode) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1652
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1653
        int startClean = lastDirty + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1654
        // if we have some clean characters accumulated
7f561c08de6b Initial load
duke
parents:
diff changeset
  1655
        // process them before the dirty one.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1656
        if (i > startClean)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1657
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1658
            int lengthClean = i - startClean;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1659
            m_writer.write(chars, startClean, lengthClean);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1660
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1661
7f561c08de6b Initial load
duke
parents:
diff changeset
  1662
        // process the "dirty" character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1663
        if (CharInfo.S_LINEFEED == ch && fromTextNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1664
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1665
            m_writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1666
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1667
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1668
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1669
            startClean =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1670
                accumDefaultEscape(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1671
                    m_writer,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1672
                    (char)ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1673
                    i,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1674
                    chars,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1675
                    end,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1676
                    fromTextNode,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1677
                    false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1678
            i = startClean - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1679
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1680
        // Return the index of the last character that we just processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1681
        // which is a dirty character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1682
        return i;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1683
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1684
7f561c08de6b Initial load
duke
parents:
diff changeset
  1685
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1686
     * Receive notification of character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1687
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1688
     * @param s The string of characters to process.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1689
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1690
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1691
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1692
    public void characters(String s) throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1693
    {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1694
        if (isInEntityRef())
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1695
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1696
        final int length = s.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1697
        if (length > m_charsBuff.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1698
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1699
            m_charsBuff = new char[length * 2 + 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1700
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1701
        s.getChars(0, length, m_charsBuff, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1702
        characters(m_charsBuff, 0, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1703
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1704
7f561c08de6b Initial load
duke
parents:
diff changeset
  1705
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1706
     * Escape and writer.write a character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1707
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1708
     * @param ch character to be escaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1709
     * @param i index into character array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1710
     * @param chars non-null reference to character array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1711
     * @param len length of chars.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1712
     * @param fromTextNode true if the characters being processed are
7f561c08de6b Initial load
duke
parents:
diff changeset
  1713
     * from a text node, false if the characters being processed are from
7f561c08de6b Initial load
duke
parents:
diff changeset
  1714
     * an attribute value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1715
     * @param escLF true if the linefeed should be escaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1716
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1717
     * @return i+1 if a character was written, i+2 if two characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  1718
     * were written out, else return i.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1719
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1720
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1721
     */
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1722
    protected int accumDefaultEscape(
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1723
        Writer writer,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1724
        char ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1725
        int i,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1726
        char[] chars,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1727
        int len,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1728
        boolean fromTextNode,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1729
        boolean escLF)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1730
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1731
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1732
7f561c08de6b Initial load
duke
parents:
diff changeset
  1733
        int pos = accumDefaultEntity(writer, ch, i, chars, len, fromTextNode, escLF);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1734
7f561c08de6b Initial load
duke
parents:
diff changeset
  1735
        if (i == pos)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1736
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1737
            if (Encodings.isHighUTF16Surrogate(ch))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1738
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1739
7f561c08de6b Initial load
duke
parents:
diff changeset
  1740
                // Should be the UTF-16 low surrogate of the hig/low pair.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1741
                char next;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1742
                // Unicode code point formed from the high/low pair.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1743
                int codePoint = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1744
7f561c08de6b Initial load
duke
parents:
diff changeset
  1745
                if (i + 1 >= len)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1746
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1747
                    throw new IOException(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1748
                        Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1749
                            MsgKey.ER_INVALID_UTF16_SURROGATE,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1750
                            new Object[] { Integer.toHexString(ch)}));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1751
                    //"Invalid UTF-16 surrogate detected: "
7f561c08de6b Initial load
duke
parents:
diff changeset
  1752
7f561c08de6b Initial load
duke
parents:
diff changeset
  1753
                    //+Integer.toHexString(ch)+ " ?");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1754
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1755
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1756
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1757
                    next = chars[++i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1758
7f561c08de6b Initial load
duke
parents:
diff changeset
  1759
                    if (!(Encodings.isLowUTF16Surrogate(next)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1760
                        throw new IOException(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1761
                            Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1762
                                MsgKey
7f561c08de6b Initial load
duke
parents:
diff changeset
  1763
                                    .ER_INVALID_UTF16_SURROGATE,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1764
                                new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1765
                                    Integer.toHexString(ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1766
                                        + " "
7f561c08de6b Initial load
duke
parents:
diff changeset
  1767
                                        + Integer.toHexString(next)}));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1768
                    //"Invalid UTF-16 surrogate detected: "
7f561c08de6b Initial load
duke
parents:
diff changeset
  1769
7f561c08de6b Initial load
duke
parents:
diff changeset
  1770
                    //+Integer.toHexString(ch)+" "+Integer.toHexString(next));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1771
                    codePoint = Encodings.toCodePoint(ch,next);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1772
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1773
7f561c08de6b Initial load
duke
parents:
diff changeset
  1774
                writer.write("&#");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1775
                writer.write(Integer.toString(codePoint));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1776
                writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1777
                pos += 2; // count the two characters that went into writing out this entity
7f561c08de6b Initial load
duke
parents:
diff changeset
  1778
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1779
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1780
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1781
                /*  This if check is added to support control characters in XML 1.1.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1782
                 *  If a character is a Control Character within C0 and C1 range, it is desirable
7f561c08de6b Initial load
duke
parents:
diff changeset
  1783
                 *  to write it out as Numeric Character Reference(NCR) regardless of XML Version
7f561c08de6b Initial load
duke
parents:
diff changeset
  1784
                 *  being used for output document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1785
                 */
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1786
                if (isCharacterInC0orC1Range(ch) ||
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1787
                        (XMLVERSION11.equals(getVersion()) && isNELorLSEPCharacter(ch)))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1788
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1789
                    writer.write("&#");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1790
                    writer.write(Integer.toString(ch));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1791
                    writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1792
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1793
                else if ((!escapingNotNeeded(ch) ||
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1794
                    (  (fromTextNode && m_charInfo.isSpecialTextChar(ch))
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1795
                     || (!fromTextNode && m_charInfo.isSpecialAttrChar(ch))))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1796
                && m_elemContext.m_currentElemDepth > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1797
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1798
                    writer.write("&#");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1799
                    writer.write(Integer.toString(ch));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1800
                    writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1801
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1802
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1803
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1804
                    writer.write(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1805
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1806
                pos++;  // count the single character that was processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1807
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1808
7f561c08de6b Initial load
duke
parents:
diff changeset
  1809
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1810
        return pos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1811
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1812
7f561c08de6b Initial load
duke
parents:
diff changeset
  1813
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1814
     * Receive notification of the beginning of an element, although this is a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1815
     * SAX method additional namespace or attribute information can occur before
7f561c08de6b Initial load
duke
parents:
diff changeset
  1816
     * or after this call, that is associated with this element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1817
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1818
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1819
     * @param namespaceURI The Namespace URI, or the empty string if the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1820
     *        element has no Namespace URI or if Namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1821
     *        processing is not being performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1822
     * @param localName The local name (without prefix), or the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1823
     *        empty string if Namespace processing is not being
7f561c08de6b Initial load
duke
parents:
diff changeset
  1824
     *        performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1825
     * @param name The element type name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1826
     * @param atts The attributes attached to the element, if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1827
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1828
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1829
     * @see org.xml.sax.ContentHandler#startElement
7f561c08de6b Initial load
duke
parents:
diff changeset
  1830
     * @see org.xml.sax.ContentHandler#endElement
7f561c08de6b Initial load
duke
parents:
diff changeset
  1831
     * @see org.xml.sax.AttributeList
7f561c08de6b Initial load
duke
parents:
diff changeset
  1832
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1833
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1834
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1835
    public void startElement(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1836
        String namespaceURI,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1837
        String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1838
        String name,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1839
        Attributes atts)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1840
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1841
    {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1842
        if (isInEntityRef())
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1843
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1844
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1845
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1846
            m_childNodeNum++;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1847
            flushCharactersBuffer();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1848
        }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1849
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1850
        if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1851
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1852
            startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1853
            m_needToCallStartDocument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1854
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1855
        else if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1856
            closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1857
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1858
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1859
            if ((true == m_needToOutputDocTypeDecl)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1860
                && (null != getDoctypeSystem()))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1861
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1862
                outputDocTypeDecl(name, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1863
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1864
7f561c08de6b Initial load
duke
parents:
diff changeset
  1865
            m_needToOutputDocTypeDecl = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1866
7f561c08de6b Initial load
duke
parents:
diff changeset
  1867
            /* before we over-write the current elementLocalName etc.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1868
             * lets close out the old one (if we still need to)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1869
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1870
            if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1871
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1872
                closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1873
                m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1874
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1875
7f561c08de6b Initial load
duke
parents:
diff changeset
  1876
            if (namespaceURI != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1877
                ensurePrefixIsDeclared(namespaceURI, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1878
7f561c08de6b Initial load
duke
parents:
diff changeset
  1879
            if (shouldIndent() && m_startNewLine)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1880
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1881
                indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1882
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1883
7f561c08de6b Initial load
duke
parents:
diff changeset
  1884
            m_startNewLine = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1885
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  1886
            final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1887
            writer.write('<');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1888
            writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1889
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1890
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1891
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1892
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1893
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1894
7f561c08de6b Initial load
duke
parents:
diff changeset
  1895
        // process the attributes now, because after this SAX call they might be gone
7f561c08de6b Initial load
duke
parents:
diff changeset
  1896
        if (atts != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1897
            addAttributes(atts);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1898
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1899
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1900
            m_ispreserveSpace = m_preserveSpaces.peekOrFalse();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1901
            m_preserveSpaces.push(m_ispreserveSpace);
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1902
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1903
            m_childNodeNumStack.add(m_childNodeNum);
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1904
            m_childNodeNum = 0;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1905
        }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  1906
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1907
        m_elemContext = m_elemContext.push(namespaceURI,localName,name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1908
        m_isprevtext = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1909
7f561c08de6b Initial load
duke
parents:
diff changeset
  1910
        if (m_tracer != null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  1911
            firePseudoAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1912
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1913
7f561c08de6b Initial load
duke
parents:
diff changeset
  1914
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1915
7f561c08de6b Initial load
duke
parents:
diff changeset
  1916
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1917
      * Receive notification of the beginning of an element, additional
7f561c08de6b Initial load
duke
parents:
diff changeset
  1918
      * namespace or attribute information can occur before or after this call,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1919
      * that is associated with this element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1920
      *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1921
      *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1922
      * @param elementNamespaceURI The Namespace URI, or the empty string if the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1923
      *        element has no Namespace URI or if Namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1924
      *        processing is not being performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1925
      * @param elementLocalName The local name (without prefix), or the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1926
      *        empty string if Namespace processing is not being
7f561c08de6b Initial load
duke
parents:
diff changeset
  1927
      *        performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1928
      * @param elementName The element type name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1929
      * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1930
      *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1931
      * @see org.xml.sax.ContentHandler#startElement
7f561c08de6b Initial load
duke
parents:
diff changeset
  1932
      * @see org.xml.sax.ContentHandler#endElement
7f561c08de6b Initial load
duke
parents:
diff changeset
  1933
      * @see org.xml.sax.AttributeList
7f561c08de6b Initial load
duke
parents:
diff changeset
  1934
      *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1935
      * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1936
      */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1937
    public void startElement(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1938
        String elementNamespaceURI,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1939
        String elementLocalName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1940
        String elementName)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1941
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1942
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1943
        startElement(elementNamespaceURI, elementLocalName, elementName, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1944
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1945
7f561c08de6b Initial load
duke
parents:
diff changeset
  1946
    public void startElement(String elementName) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1947
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1948
        startElement(null, null, elementName, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1949
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1950
7f561c08de6b Initial load
duke
parents:
diff changeset
  1951
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1952
     * Output the doc type declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1953
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1954
     * @param name non-null reference to document type name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1955
     * NEEDSDOC @param closeDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
  1956
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1957
     * @throws java.io.IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1958
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1959
    void outputDocTypeDecl(String name, boolean closeDecl) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1960
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1961
        if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1962
            closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1963
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1964
        {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  1965
            final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1966
            writer.write("<!DOCTYPE ");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1967
            writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1968
7f561c08de6b Initial load
duke
parents:
diff changeset
  1969
            String doctypePublic = getDoctypePublic();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1970
            if (null != doctypePublic)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1971
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1972
                writer.write(" PUBLIC \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1973
                writer.write(doctypePublic);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1974
                writer.write('\"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1975
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1976
7f561c08de6b Initial load
duke
parents:
diff changeset
  1977
            String doctypeSystem = getDoctypeSystem();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1978
            if (null != doctypeSystem)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1979
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1980
                if (null == doctypePublic)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1981
                    writer.write(" SYSTEM \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1982
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1983
                    writer.write(" \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1984
7f561c08de6b Initial load
duke
parents:
diff changeset
  1985
                writer.write(doctypeSystem);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1986
7f561c08de6b Initial load
duke
parents:
diff changeset
  1987
                if (closeDecl)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1988
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1989
                    writer.write("\">");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1990
                    writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1991
                    closeDecl = false; // done closing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1992
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1993
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1994
                    writer.write('\"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1995
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1996
            boolean dothis = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1997
            if (dothis)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1998
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1999
                // at one point this code seemed right,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2000
                // but not anymore - Brian M.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2001
                if (closeDecl)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2002
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2003
                    writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2004
                    writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2005
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2006
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2007
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2008
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2009
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2010
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2011
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2012
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2013
7f561c08de6b Initial load
duke
parents:
diff changeset
  2014
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2015
     * Process the attributes, which means to write out the currently
7f561c08de6b Initial load
duke
parents:
diff changeset
  2016
     * collected attributes to the writer. The attributes are not
7f561c08de6b Initial load
duke
parents:
diff changeset
  2017
     * cleared by this method
7f561c08de6b Initial load
duke
parents:
diff changeset
  2018
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2019
     * @param writer the writer to write processed attributes to.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2020
     * @param nAttrs the number of attributes in m_attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
  2021
     * to be processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2022
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2023
     * @throws java.io.IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2024
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2025
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2026
    public void processAttributes(Writer writer, int nAttrs) throws IOException, SAXException
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2027
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2028
            /* real SAX attributes are not passed in, so process the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2029
             * attributes that were collected after the startElement call.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2030
             * _attribVector is a "cheap" list for Stream serializer output
7f561c08de6b Initial load
duke
parents:
diff changeset
  2031
             * accumulated over a series of calls to attribute(name,value)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2032
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2033
            String encoding = getEncoding();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2034
            for (int i = 0; i < nAttrs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2035
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2036
                // elementAt is JDK 1.1.8
7f561c08de6b Initial load
duke
parents:
diff changeset
  2037
                final String name = m_attributes.getQName(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2038
                final String value = m_attributes.getValue(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2039
                writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2040
                writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2041
                writer.write("=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2042
                writeAttrString(writer, value, encoding);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2043
                writer.write('\"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2044
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2045
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2046
7f561c08de6b Initial load
duke
parents:
diff changeset
  2047
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2048
     * Returns the specified <var>string</var> after substituting <VAR>specials</VAR>,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2049
     * and UTF-16 surrogates for chracter references <CODE>&amp;#xnn</CODE>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2050
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2051
     * @param   string      String to convert to XML format.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2052
     * @param   encoding    CURRENTLY NOT IMPLEMENTED.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2053
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2054
     * @throws java.io.IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2055
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2056
    public void writeAttrString(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2057
        Writer writer,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2058
        String string,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2059
        String encoding)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2060
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2061
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2062
        final int len = string.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2063
        if (len > m_attrBuff.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2064
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2065
           m_attrBuff = new char[len*2 + 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2066
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2067
        string.getChars(0,len, m_attrBuff, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2068
        final char[] stringChars = m_attrBuff;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2069
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2070
        for (int i = 0; i < len; )
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2071
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2072
            char ch = stringChars[i];
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2073
            if (escapingNotNeeded(ch) && (!m_charInfo.isSpecialAttrChar(ch)))
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2074
            {
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2075
                writer.write(ch);
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2076
                i++;
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2077
            }
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2078
            else
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2079
            { // I guess the parser doesn't normalize cr/lf in attributes. -sb
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2080
//                if ((CharInfo.S_CARRIAGERETURN == ch)
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2081
//                    && ((i + 1) < len)
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2082
//                    && (CharInfo.S_LINEFEED == stringChars[i + 1]))
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2083
//                {
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2084
//                    i++;
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2085
//                    ch = CharInfo.S_LINEFEED;
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2086
//                }
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2087
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2088
                i = accumDefaultEscape(writer, ch, i, stringChars, len, false, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2089
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2090
        }
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  2091
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2092
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2093
7f561c08de6b Initial load
duke
parents:
diff changeset
  2094
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2095
     * Receive notification of the end of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2096
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2097
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2098
     * @param namespaceURI The Namespace URI, or the empty string if the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2099
     *        element has no Namespace URI or if Namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  2100
     *        processing is not being performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2101
     * @param localName The local name (without prefix), or the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2102
     *        empty string if Namespace processing is not being
7f561c08de6b Initial load
duke
parents:
diff changeset
  2103
     *        performed.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2104
     * @param name The element type name
7f561c08de6b Initial load
duke
parents:
diff changeset
  2105
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2106
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2107
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2108
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2109
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2110
    public void endElement(String namespaceURI, String localName, String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2111
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2112
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2113
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2114
        if (isInEntityRef())
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2115
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2116
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2117
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2118
            flushCharactersBuffer();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2119
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2120
        // namespaces declared at the current depth are no longer valid
7f561c08de6b Initial load
duke
parents:
diff changeset
  2121
        // so get rid of them
7f561c08de6b Initial load
duke
parents:
diff changeset
  2122
        m_prefixMap.popNamespaces(m_elemContext.m_currentElemDepth, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2123
7f561c08de6b Initial load
duke
parents:
diff changeset
  2124
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  2125
        {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2126
            final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2127
            if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2128
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2129
                if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2130
                    super.fireStartElem(m_elemContext.m_elementName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2131
                int nAttrs = m_attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2132
                if (nAttrs > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2133
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2134
                    processAttributes(m_writer, nAttrs);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2135
                    // clear attributes object for re-use with next element
7f561c08de6b Initial load
duke
parents:
diff changeset
  2136
                    m_attributes.clear();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2137
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2138
                if (m_spaceBeforeClose)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2139
                    writer.write(" />");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2140
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2141
                    writer.write("/>");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2142
                /* don't need to pop cdataSectionState because
7f561c08de6b Initial load
duke
parents:
diff changeset
  2143
                 * this element ended so quickly that we didn't get
7f561c08de6b Initial load
duke
parents:
diff changeset
  2144
                 * to push the state.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2145
                 */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2146
7f561c08de6b Initial load
duke
parents:
diff changeset
  2147
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2148
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2149
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2150
                if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2151
                    closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2152
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2153
                if (shouldIndent() && (m_childNodeNum > 1 || !m_isprevtext))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2154
                    indent(m_elemContext.m_currentElemDepth - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2155
                writer.write('<');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2156
                writer.write('/');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2157
                writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2158
                writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2159
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2160
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2161
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2162
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2163
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2164
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2165
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2166
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2167
            m_ispreserveSpace = m_preserveSpaces.popAndTop();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2168
            m_childNodeNum = m_childNodeNumStack.remove(m_childNodeNumStack.size() - 1);
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2169
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2170
            m_isprevtext = false;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2171
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2172
7f561c08de6b Initial load
duke
parents:
diff changeset
  2173
        // fire off the end element event
7f561c08de6b Initial load
duke
parents:
diff changeset
  2174
        if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2175
            super.fireEndElem(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2176
        m_elemContext = m_elemContext.m_prev;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2177
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2178
7f561c08de6b Initial load
duke
parents:
diff changeset
  2179
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2180
     * Receive notification of the end of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2181
     * @param name The element type name
7f561c08de6b Initial load
duke
parents:
diff changeset
  2182
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2183
     *     wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2184
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2185
    public void endElement(String name) throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2186
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2187
        endElement(null, null, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2188
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2189
7f561c08de6b Initial load
duke
parents:
diff changeset
  2190
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2191
     * Begin the scope of a prefix-URI Namespace mapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  2192
     * just before another element is about to start.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2193
     * This call will close any open tags so that the prefix mapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  2194
     * will not apply to the current element, but the up comming child.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2195
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2196
     * @see org.xml.sax.ContentHandler#startPrefixMapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  2197
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2198
     * @param prefix The Namespace prefix being declared.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2199
     * @param uri The Namespace URI the prefix is mapped to.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2200
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2201
     * @throws org.xml.sax.SAXException The client may throw
7f561c08de6b Initial load
duke
parents:
diff changeset
  2202
     *            an exception during processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2203
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2204
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2205
    public void startPrefixMapping(String prefix, String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2206
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2207
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2208
        // the "true" causes the flush of any open tags
7f561c08de6b Initial load
duke
parents:
diff changeset
  2209
        startPrefixMapping(prefix, uri, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2210
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2211
7f561c08de6b Initial load
duke
parents:
diff changeset
  2212
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2213
     * Handle a prefix/uri mapping, which is associated with a startElement()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2214
     * that is soon to follow. Need to close any open start tag to make
7f561c08de6b Initial load
duke
parents:
diff changeset
  2215
     * sure than any name space attributes due to this event are associated wih
7f561c08de6b Initial load
duke
parents:
diff changeset
  2216
     * the up comming element, not the current one.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2217
     * @see ExtendedContentHandler#startPrefixMapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  2218
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2219
     * @param prefix The Namespace prefix being declared.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2220
     * @param uri The Namespace URI the prefix is mapped to.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2221
     * @param shouldFlush true if any open tags need to be closed first, this
7f561c08de6b Initial load
duke
parents:
diff changeset
  2222
     * will impact which element the mapping applies to (open parent, or its up
7f561c08de6b Initial load
duke
parents:
diff changeset
  2223
     * comming child)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2224
     * @return returns true if the call made a change to the current
7f561c08de6b Initial load
duke
parents:
diff changeset
  2225
     * namespace information, false if it did not change anything, e.g. if the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2226
     * prefix/namespace mapping was already in scope from before.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2227
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2228
     * @throws org.xml.sax.SAXException The client may throw
7f561c08de6b Initial load
duke
parents:
diff changeset
  2229
     *            an exception during processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2230
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2231
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2232
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2233
    public boolean startPrefixMapping(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2234
        String prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2235
        String uri,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2236
        boolean shouldFlush)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2237
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2238
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2239
7f561c08de6b Initial load
duke
parents:
diff changeset
  2240
        /* Remember the mapping, and at what depth it was declared
7f561c08de6b Initial load
duke
parents:
diff changeset
  2241
         * This is one greater than the current depth because these
7f561c08de6b Initial load
duke
parents:
diff changeset
  2242
         * mappings will apply to the next depth. This is in
7f561c08de6b Initial load
duke
parents:
diff changeset
  2243
         * consideration that startElement() will soon be called
7f561c08de6b Initial load
duke
parents:
diff changeset
  2244
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2245
7f561c08de6b Initial load
duke
parents:
diff changeset
  2246
        boolean pushed;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2247
        int pushDepth;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2248
        if (shouldFlush)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2249
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2250
            flushPending();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2251
            // the prefix mapping applies to the child element (one deeper)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2252
            pushDepth = m_elemContext.m_currentElemDepth + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2253
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2254
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2255
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2256
            // the prefix mapping applies to the current element
7f561c08de6b Initial load
duke
parents:
diff changeset
  2257
            pushDepth = m_elemContext.m_currentElemDepth;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2258
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2259
        pushed = m_prefixMap.pushNamespace(prefix, uri, pushDepth);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2260
7f561c08de6b Initial load
duke
parents:
diff changeset
  2261
        if (pushed)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2262
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2263
            /* Brian M.: don't know if we really needto do this. The
7f561c08de6b Initial load
duke
parents:
diff changeset
  2264
             * callers of this object should have injected both
7f561c08de6b Initial load
duke
parents:
diff changeset
  2265
             * startPrefixMapping and the attributes.  We are
7f561c08de6b Initial load
duke
parents:
diff changeset
  2266
             * just covering our butt here.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2267
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2268
            String name;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2269
            if (EMPTYSTRING.equals(prefix))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2270
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2271
                name = "xmlns";
7f561c08de6b Initial load
duke
parents:
diff changeset
  2272
                addAttributeAlways(XMLNS_URI, name, name, "CDATA", uri, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2273
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2274
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2275
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2276
                if (!EMPTYSTRING.equals(uri))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2277
                    // hack for XSLTC attribset16 test
7f561c08de6b Initial load
duke
parents:
diff changeset
  2278
                { // that maps ns1 prefix to "" URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  2279
                    name = "xmlns:" + prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2280
7f561c08de6b Initial load
duke
parents:
diff changeset
  2281
                    /* for something like xmlns:abc="w3.pretend.org"
7f561c08de6b Initial load
duke
parents:
diff changeset
  2282
                     *  the      uri is the value, that is why we pass it in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2283
                     * value, or 5th slot of addAttributeAlways()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2284
                     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2285
                    addAttributeAlways(XMLNS_URI, prefix, name, "CDATA", uri, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2286
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2287
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2288
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2289
        return pushed;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2290
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2291
7f561c08de6b Initial load
duke
parents:
diff changeset
  2292
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2293
     * Receive notification of an XML comment anywhere in the document. This
7f561c08de6b Initial load
duke
parents:
diff changeset
  2294
     * callback will be used for comments inside or outside the document
7f561c08de6b Initial load
duke
parents:
diff changeset
  2295
     * element, including comments in the external DTD subset (if read).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2296
     * @param ch An array holding the characters in the comment.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2297
     * @param start The starting position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2298
     * @param length The number of characters to use from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2299
     * @throws org.xml.sax.SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2300
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2301
    public void comment(char ch[], int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2302
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2303
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2304
7f561c08de6b Initial load
duke
parents:
diff changeset
  2305
        int start_old = start;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2306
        if (isInEntityRef())
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2307
            return;
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2308
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2309
            m_childNodeNum++;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2310
            flushCharactersBuffer();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2311
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2312
        if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2313
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2314
            closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2315
            m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2316
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2317
        else if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2318
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2319
            startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2320
            m_needToCallStartDocument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2321
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2322
7f561c08de6b Initial load
duke
parents:
diff changeset
  2323
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  2324
        {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2325
            if (shouldIndent() && m_isStandalone)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2326
                indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2327
7f561c08de6b Initial load
duke
parents:
diff changeset
  2328
            final int limit = start + length;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2329
            boolean wasDash = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2330
            if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2331
                closeCDATA();
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2332
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2333
            if (shouldIndent() && !m_isStandalone)
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2334
                indent();
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2335
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2336
            final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2337
            writer.write(COMMENT_BEGIN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2338
            // Detect occurrences of two consecutive dashes, handle as necessary.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2339
            for (int i = start; i < limit; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2340
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2341
                if (wasDash && ch[i] == '-')
7f561c08de6b Initial load
duke
parents:
diff changeset
  2342
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2343
                    writer.write(ch, start, i - start);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2344
                    writer.write(" -");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2345
                    start = i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2346
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2347
                wasDash = (ch[i] == '-');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2348
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2349
7f561c08de6b Initial load
duke
parents:
diff changeset
  2350
            // if we have some chars in the comment
7f561c08de6b Initial load
duke
parents:
diff changeset
  2351
            if (length > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2352
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2353
                // Output the remaining characters (if any)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2354
                final int remainingChars = (limit - start);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2355
                if (remainingChars > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2356
                    writer.write(ch, start, remainingChars);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2357
                // Protect comment end from a single trailing dash
7f561c08de6b Initial load
duke
parents:
diff changeset
  2358
                if (ch[limit - 1] == '-')
7f561c08de6b Initial load
duke
parents:
diff changeset
  2359
                    writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2360
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2361
            writer.write(COMMENT_END);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2362
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2363
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2364
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2365
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2366
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2367
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2368
        /*
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2369
         * Don't write out any indentation whitespace now,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2370
         * because there may be non-whitespace text after this.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2371
         *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2372
         * Simply mark that at this point if we do decide
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2373
         * to indent that we should
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2374
         * add a newline on the end of the current line before
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2375
         * the indentation at the start of the next line.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
  2376
         */
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2377
        m_startNewLine = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2378
        // time to generate comment event
7f561c08de6b Initial load
duke
parents:
diff changeset
  2379
        if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2380
            super.fireCommentEvent(ch, start_old,length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2381
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2382
7f561c08de6b Initial load
duke
parents:
diff changeset
  2383
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2384
     * Report the end of a CDATA section.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2385
     * @throws org.xml.sax.SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2386
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2387
     *  @see  #startCDATA
7f561c08de6b Initial load
duke
parents:
diff changeset
  2388
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2389
    public void endCDATA() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2390
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2391
        if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2392
            closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2393
        m_cdataStartCalled = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2394
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2395
7f561c08de6b Initial load
duke
parents:
diff changeset
  2396
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2397
     * Report the end of DTD declarations.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2398
     * @throws org.xml.sax.SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2399
     * @see #startDTD
7f561c08de6b Initial load
duke
parents:
diff changeset
  2400
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2401
    public void endDTD() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2402
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2403
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  2404
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2405
            // Don't output doctype declaration until startDocumentInternal
7f561c08de6b Initial load
duke
parents:
diff changeset
  2406
            // has been called. Otherwise, it can appear before XML decl.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2407
            if (m_needToCallStartDocument) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2408
                return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2409
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2410
7f561c08de6b Initial load
duke
parents:
diff changeset
  2411
            if (m_needToOutputDocTypeDecl)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2412
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2413
                outputDocTypeDecl(m_elemContext.m_elementName, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2414
                m_needToOutputDocTypeDecl = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2415
            }
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2416
            final Writer writer = m_writer;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2417
            if (!m_inDoctype)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2418
                writer.write("]>");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2419
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2420
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2421
                writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2422
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2423
7f561c08de6b Initial load
duke
parents:
diff changeset
  2424
            writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2425
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2426
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2427
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2428
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2429
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2430
7f561c08de6b Initial load
duke
parents:
diff changeset
  2431
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2432
7f561c08de6b Initial load
duke
parents:
diff changeset
  2433
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2434
     * End the scope of a prefix-URI Namespace mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2435
     * @see org.xml.sax.ContentHandler#endPrefixMapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  2436
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2437
     * @param prefix The prefix that was being mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2438
     * @throws org.xml.sax.SAXException The client may throw
7f561c08de6b Initial load
duke
parents:
diff changeset
  2439
     *            an exception during processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2440
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2441
    public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2442
    { // do nothing
7f561c08de6b Initial load
duke
parents:
diff changeset
  2443
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2444
7f561c08de6b Initial load
duke
parents:
diff changeset
  2445
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2446
     * Receive notification of ignorable whitespace in element content.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2447
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2448
     * Not sure how to get this invoked quite yet.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2449
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2450
     * @param ch The characters from the XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2451
     * @param start The start position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2452
     * @param length The number of characters to read from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2453
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  2454
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2455
     * @see #characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  2456
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2457
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2458
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2459
    public void ignorableWhitespace(char ch[], int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2460
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2461
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2462
7f561c08de6b Initial load
duke
parents:
diff changeset
  2463
        if (0 == length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2464
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2465
        characters(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2466
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2467
7f561c08de6b Initial load
duke
parents:
diff changeset
  2468
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2469
     * Receive notification of a skipped entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2470
     * @see org.xml.sax.ContentHandler#skippedEntity
7f561c08de6b Initial load
duke
parents:
diff changeset
  2471
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2472
     * @param name The name of the skipped entity.  If it is a
7f561c08de6b Initial load
duke
parents:
diff changeset
  2473
     *       parameter                   entity, the name will begin with '%',
7f561c08de6b Initial load
duke
parents:
diff changeset
  2474
     * and if it is the external DTD subset, it will be the string
7f561c08de6b Initial load
duke
parents:
diff changeset
  2475
     * "[dtd]".
7f561c08de6b Initial load
duke
parents:
diff changeset
  2476
     * @throws org.xml.sax.SAXException Any SAX exception, possibly wrapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  2477
     * another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2478
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2479
    public void skippedEntity(String name) throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2480
    { // TODO: Should handle
7f561c08de6b Initial load
duke
parents:
diff changeset
  2481
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2482
7f561c08de6b Initial load
duke
parents:
diff changeset
  2483
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2484
     * Report the start of a CDATA section.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2485
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2486
     * @throws org.xml.sax.SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2487
     * @see #endCDATA
7f561c08de6b Initial load
duke
parents:
diff changeset
  2488
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2489
    public void startCDATA() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2490
    {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2491
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2492
            m_childNodeNum++;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2493
            flushCharactersBuffer();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2494
        }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2495
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2496
        m_cdataStartCalled = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2497
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2498
7f561c08de6b Initial load
duke
parents:
diff changeset
  2499
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2500
     * Report the beginning of an entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2501
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2502
     * The start and end of the document entity are not reported.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2503
     * The start and end of the external DTD subset are reported
7f561c08de6b Initial load
duke
parents:
diff changeset
  2504
     * using the pseudo-name "[dtd]".  All other events must be
7f561c08de6b Initial load
duke
parents:
diff changeset
  2505
     * properly nested within start/end entity events.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2506
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2507
     * @param name The name of the entity.  If it is a parameter
7f561c08de6b Initial load
duke
parents:
diff changeset
  2508
     *        entity, the name will begin with '%'.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2509
     * @throws org.xml.sax.SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2510
     * @see #endEntity
7f561c08de6b Initial load
duke
parents:
diff changeset
  2511
     * @see org.xml.sax.ext.DeclHandler#internalEntityDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
  2512
     * @see org.xml.sax.ext.DeclHandler#externalEntityDecl
7f561c08de6b Initial load
duke
parents:
diff changeset
  2513
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2514
    public void startEntity(String name) throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2515
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2516
        if (name.equals("[dtd]"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2517
            m_inExternalDTD = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2518
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2519
        // if this is not the magic [dtd] name
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2520
        if (!m_inExternalDTD) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2521
            // if it's not in nested entity reference
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2522
            if (!isInEntityRef()) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2523
                if (shouldFormatOutput()) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2524
                    m_charactersBuffer.addEntityReference(name);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2525
                } else {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2526
                    outputEntityReference(name);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2527
                }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2528
            }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2529
            m_inEntityRef++;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2530
        }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2531
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2532
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2533
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2534
     * Write out the entity reference with the form as "&amp;entityName;".
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2535
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2536
     * @param name The name of the entity.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2537
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2538
    private void outputEntityReference(String name) throws SAXException {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2539
        startNonEscaping();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2540
        characters("&" + name + ';');
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2541
        endNonEscaping();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2542
        m_isprevtext = true;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2543
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2544
7f561c08de6b Initial load
duke
parents:
diff changeset
  2545
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2546
     * For the enclosing elements starting tag write out
7f561c08de6b Initial load
duke
parents:
diff changeset
  2547
     * out any attributes followed by ">"
7f561c08de6b Initial load
duke
parents:
diff changeset
  2548
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2549
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2550
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2551
    protected void closeStartTag() throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2552
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2553
        if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2554
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2555
7f561c08de6b Initial load
duke
parents:
diff changeset
  2556
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
  2557
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2558
                if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2559
                    super.fireStartElem(m_elemContext.m_elementName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2560
                int nAttrs = m_attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2561
                if (nAttrs > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2562
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2563
                     processAttributes(m_writer, nAttrs);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2564
                    // clear attributes object for re-use with next element
7f561c08de6b Initial load
duke
parents:
diff changeset
  2565
                    m_attributes.clear();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2566
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2567
                m_writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  2568
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2569
            catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2570
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2571
                throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2572
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2573
7f561c08de6b Initial load
duke
parents:
diff changeset
  2574
            /* whether Xalan or XSLTC, we have the prefix mappings now, so
7f561c08de6b Initial load
duke
parents:
diff changeset
  2575
             * lets determine if the current element is specified in the cdata-
7f561c08de6b Initial load
duke
parents:
diff changeset
  2576
             * section-elements list.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2577
             */
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2578
            if (m_StringOfCDATASections != null)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2579
                m_elemContext.m_isCdataSection = isCdataSection();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2580
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2581
7f561c08de6b Initial load
duke
parents:
diff changeset
  2582
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2583
7f561c08de6b Initial load
duke
parents:
diff changeset
  2584
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2585
     * Report the start of DTD declarations, if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2586
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2587
     * Any declarations are assumed to be in the internal subset unless
7f561c08de6b Initial load
duke
parents:
diff changeset
  2588
     * otherwise indicated.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2589
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2590
     * @param name The document type name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2591
     * @param publicId The declared public identifier for the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2592
     *        external DTD subset, or null if none was declared.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2593
     * @param systemId The declared system identifier for the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2594
     *        external DTD subset, or null if none was declared.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2595
     * @throws org.xml.sax.SAXException The application may raise an
7f561c08de6b Initial load
duke
parents:
diff changeset
  2596
     *            exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2597
     * @see #endDTD
7f561c08de6b Initial load
duke
parents:
diff changeset
  2598
     * @see #startEntity
7f561c08de6b Initial load
duke
parents:
diff changeset
  2599
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2600
    public void startDTD(String name, String publicId, String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2601
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2602
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2603
        setDoctypeSystem(systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2604
        setDoctypePublic(publicId);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2605
7f561c08de6b Initial load
duke
parents:
diff changeset
  2606
        m_elemContext.m_elementName = name;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2607
        m_inDoctype = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2608
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2609
7f561c08de6b Initial load
duke
parents:
diff changeset
  2610
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2611
     * Returns the m_indentAmount.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2612
     * @return int
7f561c08de6b Initial load
duke
parents:
diff changeset
  2613
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2614
    public int getIndentAmount()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2615
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2616
        return m_indentAmount;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2617
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2618
7f561c08de6b Initial load
duke
parents:
diff changeset
  2619
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2620
     * Sets the m_indentAmount.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2621
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2622
     * @param m_indentAmount The m_indentAmount to set
7f561c08de6b Initial load
duke
parents:
diff changeset
  2623
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2624
    public void setIndentAmount(int m_indentAmount)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2625
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2626
        this.m_indentAmount = m_indentAmount;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2627
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2628
7f561c08de6b Initial load
duke
parents:
diff changeset
  2629
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2630
     * Tell if, based on space preservation constraints and the doIndent property,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2631
     * if an indent should occur.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2632
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2633
     * @return True if an indent should occur.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2634
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2635
    protected boolean shouldIndent()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2636
    {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2637
        return shouldFormatOutput() && (m_elemContext.m_currentElemDepth > 0 || m_isStandalone);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2638
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2639
7f561c08de6b Initial load
duke
parents:
diff changeset
  2640
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2641
     * Searches for the list of qname properties with the specified key in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2642
     * property list. If the key is not found in this property list, the default
7f561c08de6b Initial load
duke
parents:
diff changeset
  2643
     * property list, and its defaults, recursively, are then checked. The
7f561c08de6b Initial load
duke
parents:
diff changeset
  2644
     * method returns <code>null</code> if the property is not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2645
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2646
     * @param   key   the property key.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2647
     * @param props the list of properties to search in.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2648
     *
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2649
     * Sets the ArrayList of local-name/URI pairs of the cdata section elements
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2650
     * specified in the cdata-section-elements property.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2651
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2652
     * This method is essentially a copy of getQNameProperties() from
7f561c08de6b Initial load
duke
parents:
diff changeset
  2653
     * OutputProperties. Eventually this method should go away and a call
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2654
     * to setCdataSectionElements(ArrayList<String> v) should be made directly.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2655
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2656
    private void setCdataSectionElements(String key, Properties props) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2657
        String s = props.getProperty(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2658
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2659
        if (null != s) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2660
            // ArrayList<String> of URI/LocalName pairs
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2661
            ArrayList<String> al = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2662
            int l = s.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2663
            boolean inCurly = false;
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2664
            StringBuilder buf = new StringBuilder();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2665
7f561c08de6b Initial load
duke
parents:
diff changeset
  2666
            // parse through string, breaking on whitespaces.  I do this instead
7f561c08de6b Initial load
duke
parents:
diff changeset
  2667
            // of a tokenizer so I can track whitespace inside of curly brackets,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2668
            // which theoretically shouldn't happen if they contain legal URLs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2669
            for (int i = 0; i < l; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2670
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2671
                char c = s.charAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2672
7f561c08de6b Initial load
duke
parents:
diff changeset
  2673
                if (Character.isWhitespace(c))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2674
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2675
                    if (!inCurly)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2676
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2677
                        if (buf.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2678
                        {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2679
                            addCdataSectionElement(buf.toString(), al);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2680
                            buf.setLength(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2681
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2682
                        continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2683
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2684
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2685
                else if ('{' == c)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2686
                    inCurly = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2687
                else if ('}' == c)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2688
                    inCurly = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2689
7f561c08de6b Initial load
duke
parents:
diff changeset
  2690
                buf.append(c);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2691
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2692
7f561c08de6b Initial load
duke
parents:
diff changeset
  2693
            if (buf.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2694
            {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2695
                addCdataSectionElement(buf.toString(), al);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2696
                buf.setLength(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2697
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2698
            // call the official, public method to set the collected names
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2699
            setCdataSectionElements(al);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2700
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2701
7f561c08de6b Initial load
duke
parents:
diff changeset
  2702
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2703
7f561c08de6b Initial load
duke
parents:
diff changeset
  2704
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2705
     * Adds a URI/LocalName pair of strings to the list.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2706
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2707
     * @param URI_and_localName String of the form "{uri}local" or "local"
7f561c08de6b Initial load
duke
parents:
diff changeset
  2708
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2709
     * @return a QName object
7f561c08de6b Initial load
duke
parents:
diff changeset
  2710
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2711
    private void addCdataSectionElement(String URI_and_localName, ArrayList<String> al) {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2712
        StringTokenizer tokenizer = new StringTokenizer(URI_and_localName, "{}", false);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2713
        String s1 = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2714
        String s2 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2715
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2716
        if (null == s2) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2717
            // add null URI and the local name
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2718
            al.add(null);
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2719
            al.add(s1);
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2720
        } else {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2721
            // add URI, then local name
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2722
            al.add(s1);
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2723
            al.add(s2);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2724
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2725
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2726
7f561c08de6b Initial load
duke
parents:
diff changeset
  2727
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2728
     * Remembers the cdata sections specified in the cdata-section-elements.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2729
     * The "official way to set URI and localName pairs.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2730
     * This method should be used by both Xalan and XSLTC.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2731
     *
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2732
     * @param URI_and_localNames an ArrayList of pairs of Strings (URI/local)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2733
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2734
    public void setCdataSectionElements(ArrayList<String> URI_and_localNames) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2735
        // convert to the new way.
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2736
        if (URI_and_localNames != null) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2737
            final int len = URI_and_localNames.size() - 1;
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2738
            if (len > 0) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2739
                final StringBuilder sb = new StringBuilder();
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2740
                for (int i = 0; i < len; i += 2) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2741
                    // whitspace separated "{uri1}local1 {uri2}local2 ..."
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2742
                    if (i != 0)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2743
                        sb.append(' ');
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2744
                    final String uri = (String) URI_and_localNames.get(i);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2745
                    final String localName =
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2746
                        (String) URI_and_localNames.get(i + 1);
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  2747
                    if (uri != null) {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2748
                        // If there is no URI don't put this in, just the localName then.
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2749
                        sb.append('{');
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2750
                        sb.append(uri);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2751
                        sb.append('}');
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2752
                    }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2753
                    sb.append(localName);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2754
                }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2755
                m_StringOfCDATASections = sb.toString();
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2756
            }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2757
        }
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  2758
        initCdataElems(m_StringOfCDATASections);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2759
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2760
7f561c08de6b Initial load
duke
parents:
diff changeset
  2761
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2762
     * Makes sure that the namespace URI for the given qualified attribute name
7f561c08de6b Initial load
duke
parents:
diff changeset
  2763
     * is declared.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2764
     * @param ns the namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  2765
     * @param rawName the qualified name
7f561c08de6b Initial load
duke
parents:
diff changeset
  2766
     * @return returns null if no action is taken, otherwise it returns the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2767
     * prefix used in declaring the namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2768
     * @throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2769
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2770
    protected String ensureAttributesNamespaceIsDeclared(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2771
        String ns,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2772
        String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2773
        String rawName)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2774
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2775
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2776
7f561c08de6b Initial load
duke
parents:
diff changeset
  2777
        if (ns != null && ns.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2778
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2779
7f561c08de6b Initial load
duke
parents:
diff changeset
  2780
            // extract the prefix in front of the raw name
7f561c08de6b Initial load
duke
parents:
diff changeset
  2781
            int index = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2782
            String prefixFromRawName =
7f561c08de6b Initial load
duke
parents:
diff changeset
  2783
                (index = rawName.indexOf(":")) < 0
7f561c08de6b Initial load
duke
parents:
diff changeset
  2784
                    ? ""
7f561c08de6b Initial load
duke
parents:
diff changeset
  2785
                    : rawName.substring(0, index);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2786
7f561c08de6b Initial load
duke
parents:
diff changeset
  2787
            if (index > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2788
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2789
                // we have a prefix, lets see if it maps to a namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  2790
                String uri = m_prefixMap.lookupNamespace(prefixFromRawName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2791
                if (uri != null && uri.equals(ns))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2792
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2793
                    // the prefix in the raw name is already maps to the given namespace uri
7f561c08de6b Initial load
duke
parents:
diff changeset
  2794
                    // so we don't need to do anything
7f561c08de6b Initial load
duke
parents:
diff changeset
  2795
                    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2796
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2797
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2798
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2799
                    // The uri does not map to the prefix in the raw name,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2800
                    // so lets make the mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2801
                    this.startPrefixMapping(prefixFromRawName, ns, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2802
                    this.addAttribute(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2803
                        "http://www.w3.org/2000/xmlns/",
7f561c08de6b Initial load
duke
parents:
diff changeset
  2804
                        prefixFromRawName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2805
                        "xmlns:" + prefixFromRawName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2806
                        "CDATA",
7f561c08de6b Initial load
duke
parents:
diff changeset
  2807
                        ns, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2808
                    return prefixFromRawName;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2809
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2810
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2811
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2812
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2813
                // we don't have a prefix in the raw name.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2814
                // Does the URI map to a prefix already?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2815
                String prefix = m_prefixMap.lookupPrefix(ns);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2816
                if (prefix == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2817
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2818
                    // uri is not associated with a prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2819
                    // so lets generate a new prefix to use
7f561c08de6b Initial load
duke
parents:
diff changeset
  2820
                    prefix = m_prefixMap.generateNextPrefix();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2821
                    this.startPrefixMapping(prefix, ns, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2822
                    this.addAttribute(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2823
                        "http://www.w3.org/2000/xmlns/",
7f561c08de6b Initial load
duke
parents:
diff changeset
  2824
                        prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2825
                        "xmlns:" + prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2826
                        "CDATA",
7f561c08de6b Initial load
duke
parents:
diff changeset
  2827
                        ns, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2828
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2829
7f561c08de6b Initial load
duke
parents:
diff changeset
  2830
                return prefix;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2831
7f561c08de6b Initial load
duke
parents:
diff changeset
  2832
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2833
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2834
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2835
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2836
7f561c08de6b Initial load
duke
parents:
diff changeset
  2837
    void ensurePrefixIsDeclared(String ns, String rawName)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2838
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2839
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2840
7f561c08de6b Initial load
duke
parents:
diff changeset
  2841
        if (ns != null && ns.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2842
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2843
            int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2844
            final boolean no_prefix = ((index = rawName.indexOf(":")) < 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2845
            String prefix = (no_prefix) ? "" : rawName.substring(0, index);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2846
7f561c08de6b Initial load
duke
parents:
diff changeset
  2847
            if (null != prefix)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2848
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2849
                String foundURI = m_prefixMap.lookupNamespace(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2850
7f561c08de6b Initial load
duke
parents:
diff changeset
  2851
                if ((null == foundURI) || !foundURI.equals(ns))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2852
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2853
                    this.startPrefixMapping(prefix, ns);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2854
7f561c08de6b Initial load
duke
parents:
diff changeset
  2855
                    // Bugzilla1133: Generate attribute as well as namespace event.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2856
                    // SAX does expect both.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2857
7f561c08de6b Initial load
duke
parents:
diff changeset
  2858
                    this.addAttributeAlways(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2859
                        "http://www.w3.org/2000/xmlns/",
7f561c08de6b Initial load
duke
parents:
diff changeset
  2860
                        no_prefix ? "xmlns" : prefix,  // local name
7f561c08de6b Initial load
duke
parents:
diff changeset
  2861
                        no_prefix ? "xmlns" : ("xmlns:"+ prefix), // qname
7f561c08de6b Initial load
duke
parents:
diff changeset
  2862
                        "CDATA",
7f561c08de6b Initial load
duke
parents:
diff changeset
  2863
                        ns,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2864
                        false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2865
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2866
7f561c08de6b Initial load
duke
parents:
diff changeset
  2867
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2868
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2869
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2870
7f561c08de6b Initial load
duke
parents:
diff changeset
  2871
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2872
     * This method flushes any pending events, which can be startDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2873
     * closing the opening tag of an element, or closing an open CDATA section.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2874
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2875
    public void flushPending() throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2876
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2877
            if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2878
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2879
                startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2880
                m_needToCallStartDocument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2881
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2882
            if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2883
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2884
                closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2885
                m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2886
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2887
7f561c08de6b Initial load
duke
parents:
diff changeset
  2888
            if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2889
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2890
                closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2891
                m_cdataTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2892
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2893
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2894
7f561c08de6b Initial load
duke
parents:
diff changeset
  2895
    public void setContentHandler(ContentHandler ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2896
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2897
        // this method is really only useful in the ToSAXHandler classes but it is
7f561c08de6b Initial load
duke
parents:
diff changeset
  2898
        // in the interface.  If the method defined here is ever called
7f561c08de6b Initial load
duke
parents:
diff changeset
  2899
        // we are probably in trouble.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2900
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2901
7f561c08de6b Initial load
duke
parents:
diff changeset
  2902
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2903
     * Adds the given attribute to the set of attributes, even if there is
7f561c08de6b Initial load
duke
parents:
diff changeset
  2904
     * no currently open element. This is useful if a SAX startPrefixMapping()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2905
     * should need to add an attribute before the element name is seen.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2906
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2907
     * This method is a copy of its super classes method, except that some
7f561c08de6b Initial load
duke
parents:
diff changeset
  2908
     * tracing of events is done.  This is so the tracing is only done for
7f561c08de6b Initial load
duke
parents:
diff changeset
  2909
     * stream serializers, not for SAX ones.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2910
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2911
     * @param uri the URI of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
  2912
     * @param localName the local name of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
  2913
     * @param rawName   the qualified name of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
  2914
     * @param type the type of the attribute (probably CDATA)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2915
     * @param value the value of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
  2916
     * @param xslAttribute true if this attribute is coming from an xsl:attribute element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2917
     * @return true if the attribute value was added,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2918
     * false if the attribute already existed and the value was
7f561c08de6b Initial load
duke
parents:
diff changeset
  2919
     * replaced with the new value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2920
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2921
    public boolean addAttributeAlways(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2922
        String uri,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2923
        String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2924
        String rawName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2925
        String type,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2926
        String value,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2927
        boolean xslAttribute)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2928
    {
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  2929
        if (!m_charactersBuffer.isAnyCharactersBuffered()) {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2930
            return doAddAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  2931
        } else {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2932
            /*
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2933
             * If stylesheet includes xsl:copy-of an attribute node, XSLTC will
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2934
             * fire an addAttribute event. When a text node is handling in
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2935
             * ToStream, addAttribute has no effect. But closeStartTag call is
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2936
             * delayed to flushCharactersBuffer() method if the text node is
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2937
             * buffered, so here we ignore the attribute to avoid corrupting the
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2938
             * start tag content.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2939
             *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2940
             */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2941
            return m_attributes.getIndex(rawName) < 0;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2942
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2943
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2944
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2945
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2946
     * Does really add the attribute to the set of attributes.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2947
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2948
    private boolean doAddAttributeAlways(
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2949
        String uri,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2950
        String localName,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2951
        String rawName,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2952
        String type,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2953
        String value,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2954
        boolean xslAttribute)
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2955
    {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2956
        boolean was_added;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2957
        int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2958
        //if (uri == null || localName == null || uri.length() == 0)
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  2959
        index = m_attributes.getIndex(rawName);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  2960
        // Don't use 'localName' as it gives incorrect value, rely only on 'rawName'
7f561c08de6b Initial load
duke
parents:
diff changeset
  2961
        /*else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2962
            index = m_attributes.getIndex(uri, localName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2963
        }*/
7f561c08de6b Initial load
duke
parents:
diff changeset
  2964
        if (index >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2965
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2966
            String old_value = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2967
            if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2968
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2969
                old_value = m_attributes.getValue(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2970
                if (value.equals(old_value))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2971
                    old_value = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2972
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2973
7f561c08de6b Initial load
duke
parents:
diff changeset
  2974
            /* We've seen the attribute before.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2975
             * We may have a null uri or localName, but all we really
7f561c08de6b Initial load
duke
parents:
diff changeset
  2976
             * want to re-set is the value anyway.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2977
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2978
            m_attributes.setValue(index, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2979
            was_added = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2980
            if (old_value != null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  2981
                firePseudoAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2982
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2983
7f561c08de6b Initial load
duke
parents:
diff changeset
  2984
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2985
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2986
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2987
            // the attribute doesn't exist yet, create it
7f561c08de6b Initial load
duke
parents:
diff changeset
  2988
            if (xslAttribute)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2989
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2990
                /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  2991
                 * This attribute is from an xsl:attribute element so we take some care in
7f561c08de6b Initial load
duke
parents:
diff changeset
  2992
                 * adding it, e.g.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2993
                 *   <elem1  foo:attr1="1" xmlns:foo="uri1">
7f561c08de6b Initial load
duke
parents:
diff changeset
  2994
                 *       <xsl:attribute name="foo:attr2">2</xsl:attribute>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2995
                 *   </elem1>
7f561c08de6b Initial load
duke
parents:
diff changeset
  2996
                 *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2997
                 * We are adding attr1 and attr2 both as attributes of elem1,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2998
                 * and this code is adding attr2 (the xsl:attribute ).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2999
                 * We could have a collision with the prefix like in the example above.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3000
                 */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3001
7f561c08de6b Initial load
duke
parents:
diff changeset
  3002
                // In the example above, is there a prefix like foo ?
7f561c08de6b Initial load
duke
parents:
diff changeset
  3003
                final int colonIndex = rawName.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  3004
                if (colonIndex > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3005
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3006
                    String prefix = rawName.substring(0,colonIndex);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3007
                    NamespaceMappings.MappingRecord existing_mapping = m_prefixMap.getMappingFromPrefix(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3008
7f561c08de6b Initial load
duke
parents:
diff changeset
  3009
                    /* Before adding this attribute (foo:attr2),
7f561c08de6b Initial load
duke
parents:
diff changeset
  3010
                     * is the prefix for it (foo) already mapped at the current depth?
7f561c08de6b Initial load
duke
parents:
diff changeset
  3011
                     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3012
                    if (existing_mapping != null
7f561c08de6b Initial load
duke
parents:
diff changeset
  3013
                    && existing_mapping.m_declarationDepth == m_elemContext.m_currentElemDepth
7f561c08de6b Initial load
duke
parents:
diff changeset
  3014
                    && !existing_mapping.m_uri.equals(uri))
7f561c08de6b Initial load
duke
parents:
diff changeset
  3015
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3016
                        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  3017
                         * There is an existing mapping of this prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3018
                         * it differs from the one we need,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3019
                         * and unfortunately it is at the current depth so we
7f561c08de6b Initial load
duke
parents:
diff changeset
  3020
                         * can not over-ride it.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3021
                         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3022
7f561c08de6b Initial load
duke
parents:
diff changeset
  3023
                        /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  3024
                         * Are we lucky enough that an existing other prefix maps to this URI ?
7f561c08de6b Initial load
duke
parents:
diff changeset
  3025
                         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3026
                        prefix = m_prefixMap.lookupPrefix(uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3027
                        if (prefix == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3028
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3029
                            /* Unfortunately there is no existing prefix that happens to map to ours,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3030
                             * so to avoid a prefix collision we must generated a new prefix to use.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3031
                             * This is OK because the prefix URI mapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  3032
                             * defined in the xsl:attribute is short in scope,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3033
                             * just the xsl:attribute element itself,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3034
                             * and at this point in serialization the body of the
7f561c08de6b Initial load
duke
parents:
diff changeset
  3035
                             * xsl:attribute, if any, is just a String. Right?
7f561c08de6b Initial load
duke
parents:
diff changeset
  3036
                             *   . . . I sure hope so - Brian M.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3037
                             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3038
                            prefix = m_prefixMap.generateNextPrefix();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3039
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3040
7f561c08de6b Initial load
duke
parents:
diff changeset
  3041
                        rawName = prefix + ':' + localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3042
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3043
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3044
7f561c08de6b Initial load
duke
parents:
diff changeset
  3045
                try
7f561c08de6b Initial load
duke
parents:
diff changeset
  3046
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3047
                    /* This is our last chance to make sure the namespace for this
7f561c08de6b Initial load
duke
parents:
diff changeset
  3048
                     * attribute is declared, especially if we just generated an alternate
7f561c08de6b Initial load
duke
parents:
diff changeset
  3049
                     * prefix to avoid a collision (the new prefix/rawName will go out of scope
7f561c08de6b Initial load
duke
parents:
diff changeset
  3050
                     * soon and be lost ...  last chance here.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3051
                     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3052
                    String prefixUsed =
7f561c08de6b Initial load
duke
parents:
diff changeset
  3053
                        ensureAttributesNamespaceIsDeclared(
7f561c08de6b Initial load
duke
parents:
diff changeset
  3054
                            uri,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3055
                            localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3056
                            rawName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3057
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3058
                catch (SAXException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3059
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3060
                    // TODO Auto-generated catch block
7f561c08de6b Initial load
duke
parents:
diff changeset
  3061
                    e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3062
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3063
            }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3064
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3065
            m_attributes.addAttribute(uri, localName, rawName, type, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3066
            was_added = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3067
            if (m_tracer != null){
7f561c08de6b Initial load
duke
parents:
diff changeset
  3068
                firePseudoAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3069
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3070
        }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3071
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3072
        if (m_doIndent && rawName.equals("xml:space")) {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3073
            if (value.equals("preserve")) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3074
                m_ispreserveSpace = true;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3075
                if (m_preserveSpaces.size() > 0)
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3076
                    m_preserveSpaces.setTop(m_ispreserveSpace);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3077
            } else if (value.equals("default")) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3078
                m_ispreserveSpace = false;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3079
                if (m_preserveSpaces.size() > 0)
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3080
                    m_preserveSpaces.setTop(m_ispreserveSpace);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3081
            }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3082
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3083
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3084
        return was_added;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3085
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3086
7f561c08de6b Initial load
duke
parents:
diff changeset
  3087
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3088
     * To fire off the pseudo characters of attributes, as they currently
7f561c08de6b Initial load
duke
parents:
diff changeset
  3089
     * exist. This method should be called everytime an attribute is added,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3090
     * or when an attribute value is changed, or an element is created.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3091
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3092
    protected void firePseudoAttributes() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3093
        if (m_tracer != null) {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3094
            try {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3095
                // flush out the "<elemName" if not already flushed
7f561c08de6b Initial load
duke
parents:
diff changeset
  3096
                m_writer.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3097
7f561c08de6b Initial load
duke
parents:
diff changeset
  3098
                // make a StringBuffer to write the name="value" pairs to.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3099
                StringBuffer sb = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3100
                int nAttrs = m_attributes.getLength();
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3101
                if (nAttrs > 0) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3102
                    // make a writer that internally appends to the same
7f561c08de6b Initial load
duke
parents:
diff changeset
  3103
                    // StringBuffer
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3104
                    Writer writer = new ToStream.WritertoStringBuffer(sb);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3105
7f561c08de6b Initial load
duke
parents:
diff changeset
  3106
                    processAttributes(writer, nAttrs);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3107
                    // Don't clear the attributes!
7f561c08de6b Initial load
duke
parents:
diff changeset
  3108
                    // We only want to see what would be written out
7f561c08de6b Initial load
duke
parents:
diff changeset
  3109
                    // at this point, we don't want to loose them.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3110
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3111
                sb.append('>');  // the potential > after the attributes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3112
                // convert the StringBuffer to a char array and
7f561c08de6b Initial load
duke
parents:
diff changeset
  3113
                // emit the trace event that these characters "might"
7f561c08de6b Initial load
duke
parents:
diff changeset
  3114
                // be written
7f561c08de6b Initial load
duke
parents:
diff changeset
  3115
                char ch[] = sb.toString().toCharArray();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3116
                m_tracer.fireGenerateEvent(
7f561c08de6b Initial load
duke
parents:
diff changeset
  3117
                    SerializerTrace.EVENTTYPE_OUTPUT_PSEUDO_CHARACTERS,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3118
                    ch,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3119
                    0,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3120
                    ch.length);
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3121
            } catch (IOException ioe) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3122
                // ignore ?
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3123
            } catch (SAXException se) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3124
                // ignore ?
7f561c08de6b Initial load
duke
parents:
diff changeset
  3125
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3126
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3127
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3128
7f561c08de6b Initial load
duke
parents:
diff changeset
  3129
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3130
     * This inner class is used only to collect attribute values
7f561c08de6b Initial load
duke
parents:
diff changeset
  3131
     * written by the method writeAttrString() into a string buffer.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3132
     * In this manner trace events, and the real writing of attributes will use
7f561c08de6b Initial load
duke
parents:
diff changeset
  3133
     * the same code.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3134
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3135
    private class WritertoStringBuffer extends Writer {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3136
        final private StringBuffer m_stringbuf;
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3137
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3138
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3139
         * @see java.io.Writer#write(char[], int, int)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3140
         */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3141
        WritertoStringBuffer(StringBuffer sb) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3142
            m_stringbuf = sb;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3143
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3144
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3145
        public void write(char[] arg0, int arg1, int arg2) throws IOException {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3146
            m_stringbuf.append(arg0, arg1, arg2);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3147
        }
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3148
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3149
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3150
         * @see java.io.Writer#flush()
7f561c08de6b Initial load
duke
parents:
diff changeset
  3151
         */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3152
        public void flush() throws IOException {}
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3153
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3154
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3155
         * @see java.io.Writer#close()
7f561c08de6b Initial load
duke
parents:
diff changeset
  3156
         */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3157
        public void close() throws IOException {}
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3158
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3159
        public void write(int i) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3160
            m_stringbuf.append((char) i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3161
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3162
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3163
        public void write(String s) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3164
            m_stringbuf.append(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3165
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3166
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3167
7f561c08de6b Initial load
duke
parents:
diff changeset
  3168
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3169
     * @see SerializationHandler#setTransformer(Transformer)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3170
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3171
    public void setTransformer(Transformer transformer) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3172
        super.setTransformer(transformer);
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3173
        if (m_tracer != null && !(m_writer instanceof SerializerTraceWriter)) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3174
            m_writer = new SerializerTraceWriter(m_writer, m_tracer);
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3175
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3176
    }
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3177
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3178
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3179
     * Try's to reset the super class and reset this class for
7f561c08de6b Initial load
duke
parents:
diff changeset
  3180
     * re-use, so that you don't need to create a new serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  3181
     * (mostly for performance reasons).
7f561c08de6b Initial load
duke
parents:
diff changeset
  3182
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3183
     * @return true if the class was successfuly reset.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3184
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3185
    public boolean reset() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3186
        boolean wasReset = false;
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3187
        if (super.reset()) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3188
            resetToStream();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3189
            wasReset = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3190
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3191
        return wasReset;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3192
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3193
7f561c08de6b Initial load
duke
parents:
diff changeset
  3194
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3195
     * Reset all of the fields owned by ToStream class
7f561c08de6b Initial load
duke
parents:
diff changeset
  3196
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3197
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3198
    private void resetToStream() {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3199
         this.m_cdataStartCalled = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3200
         /* The stream is being reset. It is one of
7f561c08de6b Initial load
duke
parents:
diff changeset
  3201
          * ToXMLStream, ToHTMLStream ... and this type can't be changed
7f561c08de6b Initial load
duke
parents:
diff changeset
  3202
          * so neither should m_charInfo which is associated with the
7f561c08de6b Initial load
duke
parents:
diff changeset
  3203
          * type of Stream. Just leave m_charInfo as-is for the next re-use.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3204
          */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3205
         // this.m_charInfo = null; // don't set to null
7f561c08de6b Initial load
duke
parents:
diff changeset
  3206
7f561c08de6b Initial load
duke
parents:
diff changeset
  3207
         this.m_disableOutputEscapingStates.clear();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3208
7f561c08de6b Initial load
duke
parents:
diff changeset
  3209
         this.m_escaping = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3210
         // Leave m_format alone for now - Brian M.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3211
         // this.m_format = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3212
         this.m_inDoctype = false;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3213
         this.m_ispreserveSpace = false;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3214
         this.m_preserveSpaces.clear();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3215
         this.m_childNodeNum = 0;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3216
         this.m_childNodeNumStack.clear();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3217
         this.m_charactersBuffer.clear();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3218
         this.m_isprevtext = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3219
         this.m_isUTF8 = false; //  ?? used anywhere ??
7f561c08de6b Initial load
duke
parents:
diff changeset
  3220
         this.m_shouldFlush = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3221
         this.m_spaceBeforeClose = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3222
         this.m_startNewLine = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3223
         this.m_lineSepUse = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3224
         // DON'T SET THE WRITER TO NULL, IT MAY BE REUSED !!
7f561c08de6b Initial load
duke
parents:
diff changeset
  3225
         // this.m_writer = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3226
         this.m_expandDTDEntities = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3227
7f561c08de6b Initial load
duke
parents:
diff changeset
  3228
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3229
7f561c08de6b Initial load
duke
parents:
diff changeset
  3230
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3231
      * Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3232
      * @param encoding the character encoding
7f561c08de6b Initial load
duke
parents:
diff changeset
  3233
      */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3234
     public void setEncoding(String encoding)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3235
     {
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3236
         setOutputProperty(OutputKeys.ENCODING,encoding);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3237
     }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3238
7f561c08de6b Initial load
duke
parents:
diff changeset
  3239
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3240
     * Simple stack for boolean values.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3241
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3242
     * This class is a copy of the one in com.sun.org.apache.xml.internal.utils.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3243
     * It exists to cut the serializers dependancy on that package.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3244
     * A minor changes from that package are:
7f561c08de6b Initial load
duke
parents:
diff changeset
  3245
     * doesn't implement Clonable
7f561c08de6b Initial load
duke
parents:
diff changeset
  3246
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  3247
     * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
  3248
     */
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3249
    static final class BoolStack {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3250
        /** Array of boolean values */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3251
        private boolean m_values[];
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3252
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3253
        /** Array size allocated */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3254
        private int m_allocatedSize;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3255
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3256
        /** Index into the array of booleans */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3257
        private int m_index;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3258
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3259
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3260
         * Default constructor.  Note that the default
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3261
         * block size is very small, for small lists.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3262
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3263
        public BoolStack() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3264
            this(32);
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3265
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3266
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3267
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3268
         * Construct a IntVector, using the given block size.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3269
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3270
         * @param size array size to allocate
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3271
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3272
        public BoolStack(int size) {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3273
            m_allocatedSize = size;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3274
            m_values = new boolean[size];
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3275
            m_index = -1;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3276
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3277
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3278
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3279
         * Get the length of the list.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3280
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3281
         * @return Current length of the list
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3282
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3283
        public final int size() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3284
            return m_index + 1;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3285
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3286
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3287
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3288
         * Clears the stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3289
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3290
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3291
        public final void clear() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3292
            m_index = -1;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3293
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3294
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3295
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3296
         * Pushes an item onto the top of this stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3297
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3298
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3299
         * @param val the boolean to be pushed onto this stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3300
         * @return  the <code>item</code> argument.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3301
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3302
        public final boolean push(boolean val) {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3303
            if (m_index == m_allocatedSize - 1)
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3304
                grow();
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3305
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3306
            return (m_values[++m_index] = val);
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3307
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3308
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3309
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3310
         * Removes the object at the top of this stack and returns that
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3311
         * object as the value of this function.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3312
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3313
         * @return     The object at the top of this stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3314
         * @throws  EmptyStackException  if this stack is empty.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3315
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3316
        public final boolean pop() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3317
            return m_values[m_index--];
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3318
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3319
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3320
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3321
         * Removes the object at the top of this stack and returns the
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3322
         * next object at the top as the value of this function.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3323
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3324
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3325
         * @return Next object to the top or false if none there
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3326
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3327
        public final boolean popAndTop() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3328
            m_index--;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3329
            return (m_index >= 0) ? m_values[m_index] : false;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3330
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3331
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3332
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3333
         * Set the item at the top of this stack
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3334
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3335
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3336
         * @param b Object to set at the top of this stack
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3337
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3338
        public final void setTop(boolean b) {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3339
            m_values[m_index] = b;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3340
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3341
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3342
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3343
         * Looks at the object at the top of this stack without removing it
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3344
         * from the stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3345
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3346
         * @return     the object at the top of this stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3347
         * @throws  EmptyStackException  if this stack is empty.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3348
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3349
        public final boolean peek() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3350
            return m_values[m_index];
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3351
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3352
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3353
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3354
         * Looks at the object at the top of this stack without removing it
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3355
         * from the stack.  If the stack is empty, it returns false.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3356
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3357
         * @return     the object at the top of this stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3358
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3359
        public final boolean peekOrFalse() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3360
            return (m_index > -1) ? m_values[m_index] : false;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3361
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3362
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3363
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3364
         * Looks at the object at the top of this stack without removing it
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3365
         * from the stack.  If the stack is empty, it returns true.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3366
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3367
         * @return     the object at the top of this stack.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3368
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3369
        public final boolean peekOrTrue() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3370
            return (m_index > -1) ? m_values[m_index] : true;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3371
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3372
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3373
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3374
         * Tests if this stack is empty.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3375
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3376
         * @return  <code>true</code> if this stack is empty;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3377
         *          <code>false</code> otherwise.
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3378
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3379
        public boolean isEmpty() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3380
            return (m_index == -1);
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3381
        }
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3382
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3383
        /**
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3384
         * Grows the size of the stack
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3385
         *
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3386
         */
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3387
        private void grow() {
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3388
            m_allocatedSize *= 2;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3389
            boolean newVector[] = new boolean[m_allocatedSize];
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3390
            System.arraycopy(m_values, 0, newVector, 0, m_index + 1);
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3391
            m_values = newVector;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3392
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3393
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3394
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3395
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3396
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3397
     * This inner class is used to buffer the text nodes and the entity
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3398
     * reference nodes if indentation is on. There is only one CharacterBuffer
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3399
     * instance in ToStream, it contains a queue of GenericCharacters,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3400
     * GenericCharacters can be a text node or an entity reference node. The
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3401
     * text nodes and entity reference nodes are joined together and then are
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3402
     * flushed.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3403
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3404
    private class CharacterBuffer {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3405
        /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3406
         * GenericCharacters is immutable.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3407
         */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3408
        private abstract class GenericCharacters {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3409
            /**
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3410
             * @return True if all characters in this Text are newlines.
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3411
             */
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3412
            abstract boolean flush(boolean skipBeginningNewlines) throws SAXException;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3413
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3414
            /**
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3415
             * Converts this GenericCharacters to a new character array. This
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3416
             * method is used to handle cdata-section-elements attribute in
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3417
             * xsl:output. Therefore it doesn't need to consider
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3418
             * skipBeginningNewlines because the text will be involved with CDATA
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3419
             * tag.
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3420
             */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3421
            abstract char[] toChars();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3422
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3423
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3424
        private List<GenericCharacters> bufferedCharacters = new ArrayList<>();
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3425
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3426
        /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3427
         * Append a text node to the buffer.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3428
         */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3429
        public void addText(final char chars[], final int start, final int length) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3430
            bufferedCharacters.add(new GenericCharacters() {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3431
                char[] text;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3432
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3433
                {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3434
                    text = Arrays.copyOfRange(chars, start, start + length);
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3435
                }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3436
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3437
                boolean flush(boolean skipBeginningNewlines) throws SAXException {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3438
                    int start = 0;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3439
                    while (skipBeginningNewlines && text[start] == '\n') {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3440
                        start++;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3441
                        if (start == text.length) {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3442
                            return true;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3443
                        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3444
                    }
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3445
                    outputCharacters(text, start, text.length - start);
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3446
                    return false;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3447
                }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3448
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3449
                char[] toChars() {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3450
                    return text;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3451
                }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3452
            });
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3453
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3454
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3455
        /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3456
         * Append an entity reference to the buffer.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3457
         */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3458
        public void addEntityReference(String entityName) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3459
            bufferedCharacters.add(new GenericCharacters() {
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3460
                boolean flush(boolean skipBeginningNewlines) throws SAXException {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3461
                    if (m_elemContext.m_startTagOpen)
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3462
                    {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3463
                        closeStartTag();
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3464
                        m_elemContext.m_startTagOpen = false;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3465
                    }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3466
                    if (m_cdataTagOpen)
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3467
                        closeCDATA();
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3468
                    char[] cs = toChars();
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3469
                    try {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3470
                        m_writer.write(cs, 0, cs.length);
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3471
                        m_isprevtext = true;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3472
                    } catch (IOException e) {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3473
                        throw new SAXException(e);
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3474
                    }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3475
                    return false;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3476
                }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3477
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3478
                char[] toChars() {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3479
                    return ("&" + entityName + ";").toCharArray();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3480
                }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3481
            });
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3482
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3483
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3484
        /**
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3485
         * Append a raw text to the buffer. Used to handle raw characters event.
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3486
         */
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3487
        public void addRawText(final char chars[], final int start, final int length) {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3488
            bufferedCharacters.add(new GenericCharacters() {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3489
                char[] text;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3490
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3491
                {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3492
                    text = Arrays.copyOfRange(chars, start, start + length);
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3493
                }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3494
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3495
                boolean flush(boolean skipBeginningNewlines) throws SAXException {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3496
                    try {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3497
                        int start = 0;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3498
                        while (skipBeginningNewlines && text[start] == '\n') {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3499
                            start++;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3500
                            if (start == text.length) {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3501
                                return true;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3502
                            }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3503
                        }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3504
                        m_writer.write(text, start, text.length - start);
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3505
                        m_isprevtext = true;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3506
                    } catch (IOException e) {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3507
                        throw new SAXException(e);
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3508
                    }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3509
                    return false;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3510
                }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3511
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3512
                char[] toChars() {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3513
                    return text;
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3514
                }
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3515
            });
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3516
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3517
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3518
        /**
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3519
         * @return True if any GenericCharacters are buffered.
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3520
         */
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3521
        public boolean isAnyCharactersBuffered() {
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3522
            return bufferedCharacters.size() > 0;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3523
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3524
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3525
        /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3526
         * Flush all buffered GenericCharacters.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3527
         */
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3528
        public void flush(boolean skipBeginningNewlines) throws SAXException {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3529
            Iterator<GenericCharacters> itr = bufferedCharacters.iterator();
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3530
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3531
            boolean continueSkipBeginningNewlines = skipBeginningNewlines;
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3532
            while (itr.hasNext()) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3533
                GenericCharacters element = itr.next();
43845
93896d0f44f3 8174025: Regression in XML Transform caused by JDK-8087303
fyuan
parents: 43744
diff changeset
  3534
                continueSkipBeginningNewlines = element.flush(continueSkipBeginningNewlines);
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3535
                itr.remove();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3536
            }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3537
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3538
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3539
        /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3540
         * Converts all buffered GenericCharacters to a new character array.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3541
         */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3542
        public char[] toChars() {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3543
            StringBuilder sb = new StringBuilder();
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3544
            for (GenericCharacters element : bufferedCharacters) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3545
                sb.append(element.toChars());
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3546
            }
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3547
            return sb.toString().toCharArray();
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3548
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3549
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3550
        /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3551
         * Clear the buffer.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3552
         */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3553
        public void clear() {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3554
            bufferedCharacters.clear();
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3555
        }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3556
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 42249
diff changeset
  3557
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  3558
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3559
    // Implement DTDHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
  3560
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3561
     * If this method is called, the serializer is used as a
7f561c08de6b Initial load
duke
parents:
diff changeset
  3562
     * DTDHandler, which changes behavior how the serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  3563
     * handles document entities.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3564
     * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3565
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3566
    public void notationDecl(String name, String pubID, String sysID) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3567
        // TODO Auto-generated method stub
7f561c08de6b Initial load
duke
parents:
diff changeset
  3568
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3569
            DTDprolog();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3570
7f561c08de6b Initial load
duke
parents:
diff changeset
  3571
            m_writer.write("<!NOTATION ");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3572
            m_writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3573
            if (pubID != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3574
                m_writer.write(" PUBLIC \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3575
                m_writer.write(pubID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3576
7f561c08de6b Initial load
duke
parents:
diff changeset
  3577
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3578
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3579
                m_writer.write(" SYSTEM \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3580
                m_writer.write(sysID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3581
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3582
            m_writer.write("\" >");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3583
            m_writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3584
        } catch (IOException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3585
            // TODO Auto-generated catch block
7f561c08de6b Initial load
duke
parents:
diff changeset
  3586
            e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3587
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3588
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3589
7f561c08de6b Initial load
duke
parents:
diff changeset
  3590
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3591
     * If this method is called, the serializer is used as a
7f561c08de6b Initial load
duke
parents:
diff changeset
  3592
     * DTDHandler, which changes behavior how the serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  3593
     * handles document entities.
7f561c08de6b Initial load
duke
parents:
diff changeset
  3594
     * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
7f561c08de6b Initial load
duke
parents:
diff changeset
  3595
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3596
    public void unparsedEntityDecl(String name, String pubID, String sysID, String notationName) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3597
        // TODO Auto-generated method stub
7f561c08de6b Initial load
duke
parents:
diff changeset
  3598
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3599
            DTDprolog();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3600
7f561c08de6b Initial load
duke
parents:
diff changeset
  3601
            m_writer.write("<!ENTITY ");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3602
            m_writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3603
            if (pubID != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3604
                m_writer.write(" PUBLIC \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3605
                m_writer.write(pubID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3606
7f561c08de6b Initial load
duke
parents:
diff changeset
  3607
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3608
            else {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3609
                m_writer.write(" SYSTEM \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3610
                m_writer.write(sysID);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3611
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3612
            m_writer.write("\" NDATA ");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3613
            m_writer.write(notationName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3614
            m_writer.write(" >");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3615
            m_writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3616
        } catch (IOException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3617
            // TODO Auto-generated catch block
7f561c08de6b Initial load
duke
parents:
diff changeset
  3618
            e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
  3619
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3620
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3621
7f561c08de6b Initial load
duke
parents:
diff changeset
  3622
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3623
     * A private helper method to output the
7f561c08de6b Initial load
duke
parents:
diff changeset
  3624
     * @throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  3625
     * @throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  3626
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3627
    private void DTDprolog() throws SAXException, IOException {
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3628
        final Writer writer = m_writer;
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3629
        if (m_needToOutputDocTypeDecl) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3630
            outputDocTypeDecl(m_elemContext.m_elementName, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3631
            m_needToOutputDocTypeDecl = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3632
        }
42249
39ec1a731d99 8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
clanger
parents: 25868
diff changeset
  3633
        if (m_inDoctype) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3634
            writer.write(" [");
7f561c08de6b Initial load
duke
parents:
diff changeset
  3635
            writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  3636
            m_inDoctype = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3637
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3638
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  3639
7f561c08de6b Initial load
duke
parents:
diff changeset
  3640
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  3641
     * If set to false the serializer does not expand DTD entities,
7f561c08de6b Initial load
duke
parents:
diff changeset
  3642
     * but leaves them as is, the default value is true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3643
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  3644
    public void setDTDEntityExpansion(boolean expand) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  3645
        m_expandDTDEntities = expand;
7f561c08de6b Initial load
duke
parents:
diff changeset
  3646
    }
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3647
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3648
    /**
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3649
     * Remembers the cdata sections specified in the cdata-section-elements by appending the given
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3650
     * cdata section elements to the list. This method can be called multiple times, but once an
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3651
     * element is put in the list of cdata section elements it can not be removed.
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3652
     * This method should be used by both Xalan and XSLTC.
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3653
     *
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3654
     * @param URI_and_localNames a whitespace separated list of element names, each element
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3655
     * is a URI in curly braces (optional) and a local name. An example of such a parameter is:
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3656
     * "{http://company.com}price {myURI2}book chapter"
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3657
     */
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3658
    public void addCdataSectionElements(String URI_and_localNames)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3659
    {
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3660
        if (URI_and_localNames != null)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3661
            initCdataElems(URI_and_localNames);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3662
        if (m_StringOfCDATASections == null)
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3663
            m_StringOfCDATASections = URI_and_localNames;
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3664
        else
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3665
            m_StringOfCDATASections += (" " + URI_and_localNames);
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 16953
diff changeset
  3666
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  3667
}