jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java
author joehw
Thu, 07 Jun 2012 13:47:53 -0700
changeset 12902 0a840d92fa30
parent 12458 d601e4bba306
child 23954 1161e065d446
permissions -rw-r--r--
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark Summary: roll back XalanJ-2271 that caused the regression Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
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
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: ToXMLStream.java,v 1.2.4.2 2005/09/15 12:01:25 suresh_emailid Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 package com.sun.org.apache.xml.internal.serializer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import javax.xml.transform.ErrorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.transform.Result;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import javax.xml.transform.Transformer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.serializer.utils.Utils;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * This class converts SAX or SAX-like calls to a
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * serialized xml document.  The xsl:output method is "xml".
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * This class is used explicitly in code generated by XSLTC,
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * so it is "public", but it should
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * be viewed as internal or package private, this is not an API.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
public final class ToXMLStream extends ToStream
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
     * remembers if we need to write out "]]>" to close the CDATA
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    boolean m_cdataTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
     * Map that tells which XML characters should have special treatment, and it
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
     *  provides character to entity name lookup.
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     */
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
    59
    private static CharInfo m_xmlcharInfo =
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
//      new CharInfo(CharInfo.XML_ENTITIES_RESOURCE);
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
        CharInfo.getCharInfo(CharInfo.XML_ENTITIES_RESOURCE, Method.XML);
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     * Default constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    public ToXMLStream()
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
        m_charInfo = m_xmlcharInfo;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
        initCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
        // initialize namespaces
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
        m_prefixMap = new NamespaceMappings();
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     * Copy properties from another SerializerToXML.
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     * @param xmlListener non-null reference to a SerializerToXML object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    public void CopyFrom(ToXMLStream xmlListener)
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        m_writer = xmlListener.m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        // m_outputStream = xmlListener.m_outputStream;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        String encoding = xmlListener.getEncoding();
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        setEncoding(encoding);
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        setOmitXMLDeclaration(xmlListener.getOmitXMLDeclaration());
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        m_ispreserve = xmlListener.m_ispreserve;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
        m_preserves = xmlListener.m_preserves;
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        m_isprevtext = xmlListener.m_isprevtext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        m_doIndent = xmlListener.m_doIndent;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        setIndentAmount(xmlListener.getIndentAmount());
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        m_startNewLine = xmlListener.m_startNewLine;
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        m_needToOutputDocTypeDecl = xmlListener.m_needToOutputDocTypeDecl;
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
        setDoctypeSystem(xmlListener.getDoctypeSystem());
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        setDoctypePublic(xmlListener.getDoctypePublic());
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        setStandalone(xmlListener.getStandalone());
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        setMediaType(xmlListener.getMediaType());
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        m_maxCharacter = xmlListener.m_maxCharacter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
        m_encodingInfo = xmlListener.m_encodingInfo;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        m_spaceBeforeClose = xmlListener.m_spaceBeforeClose;
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        m_cdataStartCalled = xmlListener.m_cdataStartCalled;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
     * Receive notification of the beginning of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    public void startDocumentInternal() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
            super.startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
            m_needToCallStartDocument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
            if (m_inEntityRef)
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            m_needToOutputDocTypeDecl = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            m_startNewLine = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
            /* The call to getXMLVersion() might emit an error message
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
             * and we should emit this message regardless of if we are
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
             * writing out an XML header or not.
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
            if (getOmitXMLDeclaration() == false)
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                String encoding = Encodings.getMimeEncoding(getEncoding());
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
                String version = getVersion();
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                if (version == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                    version = "1.0";
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                String standalone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
                if (m_standaloneWasSpecified)
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
                    standalone = " standalone=\"" + getStandalone() + "\"";
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                    standalone = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
                try
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                    final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                    writer.write("<?xml version=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
                    writer.write(version);
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
                    writer.write("\" encoding=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                    writer.write(encoding);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
                    writer.write('\"');
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
                    writer.write(standalone);
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                    writer.write("?>");
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   163
                    if (m_doIndent) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   164
                        if (m_standaloneWasSpecified
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   165
                                || getDoctypePublic() != null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   166
                                || getDoctypeSystem() != null
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   167
                                || m_isStandalone) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   168
                            // We almost never put a newline after the XML
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   169
                            // header because this XML could be used as
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   170
                            // an extenal general parsed entity
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   171
                            // and we don't know the context into which it
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   172
                            // will be used in the future.  Only when
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   173
                            // standalone, or a doctype system or public is
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   174
                            // specified are we free to insert a new line
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   175
                            // after the header.  Is it even worth bothering
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   176
                            // in these rare cases?
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   177
                            writer.write(m_lineSep, 0, m_lineSepLen);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   178
                        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   179
                    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
                catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
                    throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     * Receive notification of the end of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    public void endDocument() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        flushPending();
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        if (m_doIndent && !m_isprevtext)
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            outputLineSep();
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
                throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
        flushWriter();
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
            super.fireEndDoc();
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     * Starts a whitespace preserving section. All characters printed
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     * within a preserving section are printed without indentation and
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
     * without consolidating multiple spaces. This is equivalent to
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
     * the <tt>xml:space=&quot;preserve&quot;</tt> attribute. Only XML
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
     * and HTML serializers need to support this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     * The contents of the whitespace preserving section will be delivered
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     * through the regular <tt>characters</tt> event.
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    public void startPreserving() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        // Not sure this is really what we want.  -sb
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        m_preserves.push(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        m_ispreserve = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
     * Ends a whitespace preserving section.
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
     * @see #startPreserving
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    public void endPreserving() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
        // Not sure this is really what we want.  -sb
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
        m_ispreserve = m_preserves.isEmpty() ? false : m_preserves.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
     * Receive notification of a processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
     * @param target The processing instruction target.
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
     * @param data The processing instruction data, or null if
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
     *        none was supplied.
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    public void processingInstruction(String target, String data)
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        if (m_inEntityRef)
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        flushPending();
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
            startNonEscaping();
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
            endNonEscaping();
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
                if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
                    closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
                    m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
                else if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
                    startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
                if (shouldIndent())
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                    indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
                final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
                writer.write("<?");
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                writer.write(target);
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
                if (data.length() > 0
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
                    && !Character.isSpaceChar(data.charAt(0)))
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
                    writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
                int indexOfQLT = data.indexOf("?>");
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
                if (indexOfQLT >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
                    // See XSLT spec on error recovery of "?>" in PIs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                    if (indexOfQLT > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
                        writer.write(data.substring(0, indexOfQLT));
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
                    writer.write("? >"); // add space between.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                    if ((indexOfQLT + 2) < data.length())
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
                        writer.write(data.substring(indexOfQLT + 2));
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
                    writer.write(data);
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
                writer.write('?');
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
                writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   330
                /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   331
                 * Before Xalan 1497, a newline char was printed out if not inside of an
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
   332
                 * element. The whitespace is not significant is the output is standalone
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   333
                */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   334
                if (m_elemContext.m_currentElemDepth <= 0 && m_isStandalone)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                    writer.write(m_lineSep, 0, m_lineSepLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
   337
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   338
                /*
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   339
                 * Don't write out any indentation whitespace now,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   340
                 * because there may be non-whitespace text after this.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   341
                 *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   342
                 * Simply mark that at this point if we do decide
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   343
                 * to indent that we should
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   344
                 * 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
   345
                 * the indentation at the start of the next line.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   346
                 */
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
                m_startNewLine = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
            catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
                throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
        if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
            super.fireEscapingEvent(target, data);
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
     * Receive notivication of a entityReference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     * @param name The name of the entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
    public void entityReference(String name) throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
            closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
            m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
            if (shouldIndent())
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
            final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
            writer.write('&');
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
            writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
            writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
        catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
        if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
            super.fireEntityReference(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
     * This method is used to add an attribute to the currently open element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
     * The caller has guaranted that this attribute is unique, which means that it
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
     * not been seen before and will not be seen again.
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
     * @param name the qualified name of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
     * @param value the value of the attribute which can contain only
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
     * ASCII printable characters characters in the range 32 to 127 inclusive.
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
     * @param flags the bit values of this integer give optimization information.
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
    public void addUniqueAttribute(String name, String value, int flags)
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
                final String patchedName = patchName(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
                final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
                if ((flags & NO_BAD_CHARS) > 0 && m_xmlcharInfo.onlyQuotAmpLtGt)
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
                    // "flags" has indicated that the characters
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
                    // '>'  '<'   '&'  and '"' are not in the value and
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
                    // m_htmlcharInfo has recorded that there are no other
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
                    // entities in the range 32 to 127 so we write out the
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
                    // value directly
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
                    writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
                    writer.write(patchedName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
                    writer.write("=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                    writer.write(value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
                    writer.write('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
                    writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
                    writer.write(patchedName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
                    writer.write("=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
                    writeAttrString(writer, value, this.getEncoding());
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
                    writer.write('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
            } catch (IOException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
                throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
     * Add an attribute to the current element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
     * @param uri the URI associated with the element name
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
     * @param localName local part of the attribute name
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
     * @param rawName   prefix:localName
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
     * @param type
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
     * @param value the value of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
     * @param xslAttribute true if this attribute is from an xsl:attribute,
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
     * false if declared within the elements opening tag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
     * @throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    public void addAttribute(
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
        String uri,
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
        String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        String rawName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        String type,
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        String value,
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
        boolean xslAttribute)
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
        if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
            boolean was_added = addAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
            /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
             * We don't run this block of code if:
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
             * 1. The attribute value was only replaced (was_added is false).
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
             * 2. The attribute is from an xsl:attribute element (that is handled
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
             *    in the addAttributeAlways() call just above.
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
             * 3. The name starts with "xmlns", i.e. it is a namespace declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
            if (was_added && !xslAttribute && !rawName.startsWith("xmlns"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
                String prefixUsed =
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
                    ensureAttributesNamespaceIsDeclared(
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
                        uri,
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
                        localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
                        rawName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
                if (prefixUsed != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
                    && rawName != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
                    && !rawName.startsWith(prefixUsed))
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
                    // use a different raw name, with the prefix used in the
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
                    // generated namespace declaration
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
                    rawName = prefixUsed + ":" + localName;
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
            addAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
            /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
             * The startTag is closed, yet we are adding an attribute?
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
             *
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
             * Section: 7.1.3 Creating Attributes Adding an attribute to an
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
             * element after a PI (for example) has been added to it is an
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
             * error. The attributes can be ignored. The spec doesn't explicitly
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
             * say this is disallowed, as it does for child elements, but it
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
             * makes sense to have the same treatment.
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
             *
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
             * We choose to ignore the attribute which is added too late.
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
            // Generate a warning of the ignored attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
            // Create the warning message
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
            String msg = Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
                    MsgKey.ER_ILLEGAL_ATTRIBUTE_POSITION,new Object[]{ localName });
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
                // Prepare to issue the warning message
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
                Transformer tran = super.getTransformer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
                ErrorListener errHandler = tran.getErrorListener();
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
                // Issue the warning message
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
                if (null != errHandler && m_sourceLocator != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
                  errHandler.warning(new TransformerException(msg, m_sourceLocator));
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
                  System.out.println(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
            catch (Exception e){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
     * @see ExtendedContentHandler#endElement(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
    public void endElement(String elemName) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
        endElement(null, null, elemName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
     * This method is used to notify the serializer of a namespace mapping (or node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
     * that applies to the current element whose startElement() call has already been seen.
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
     * The official SAX startPrefixMapping(prefix,uri) is to define a mapping for a child
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
     * element that is soon to be seen with a startElement() call. The official SAX call
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
     * does not apply to the current element, hence the reason for this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
    public void namespaceAfterStartElement(
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
        final String prefix,
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
        final String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
        // hack for XSLTC with finding URI for default namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
        if (m_elemContext.m_elementURI == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
            String prefix1 = getPrefixPart(m_elemContext.m_elementName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
            if (prefix1 == null && EMPTYSTRING.equals(prefix))
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
                // the elements URI is not known yet, and it
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
                // doesn't have a prefix, and we are currently
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
                // setting the uri for prefix "", so we have
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
                // the uri for the element... lets remember it
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
                m_elemContext.m_elementURI = uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
        startPrefixMapping(prefix,uri,false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
        return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
     * From XSLTC
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
     * Declare a prefix to point to a namespace URI. Inform SAX handler
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
     * if this is a new prefix mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
    protected boolean pushNamespace(String prefix, String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
            if (m_prefixMap.pushNamespace(
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
                prefix, uri, m_elemContext.m_currentElemDepth))
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
                startPrefixMapping(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
                return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
        catch (SAXException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
            // falls through
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
     * Try's to reset the super class and reset this class for
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
     * re-use, so that you don't need to create a new serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
     * (mostly for performance reasons).
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
     * @return true if the class was successfuly reset.
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
    public boolean reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
        boolean wasReset = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
        if (super.reset())
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
            resetToXMLStream();
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
            wasReset = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
        return wasReset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
     * Reset all of the fields owned by ToStream class
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
    private void resetToXMLStream()
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
        this.m_cdataTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
     * This method checks for the XML version of output document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
     * If XML version of output document is not specified, then output
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
     * document is of version XML 1.0.
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
     * If XML version of output doucment is specified, but it is not either
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
     * XML 1.0 or XML 1.1, a warning message is generated, the XML Version of
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
     * output document is set to XML 1.0 and processing continues.
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
     * @return string (XML version)
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
    private String getXMLVersion()
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
        String xmlVersion = getVersion();
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
        if(xmlVersion == null || xmlVersion.equals(XMLVERSION10))
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
            xmlVersion = XMLVERSION10;
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
        else if(xmlVersion.equals(XMLVERSION11))
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
            xmlVersion = XMLVERSION11;
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
            String msg = Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
                               MsgKey.ER_XML_VERSION_NOT_SUPPORTED,new Object[]{ xmlVersion });
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
                // Prepare to issue the warning message
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
                Transformer tran = super.getTransformer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
                ErrorListener errHandler = tran.getErrorListener();
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
                // Issue the warning message
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
                if (null != errHandler && m_sourceLocator != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
                    errHandler.warning(new TransformerException(msg, m_sourceLocator));
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
                    System.out.println(msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
            catch (Exception e){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
            xmlVersion = XMLVERSION10;
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        return xmlVersion;
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
}