src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58022 12885822f0c5
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
55575
25165403c62e 8223291: Whitespace is added to CDATA tags when using OutputKeys.INDENT to format XML
joehw
parents: 51786
diff changeset
     2
 * Copyright (c) 2014, 2019, 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
/*
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
     5
 * Licensed to the Apache Software Foundation (ASF) under one or more
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
     6
 * contributor license agreements.  See the NOTICE file distributed with
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
     7
 * this work for additional information regarding copyright ownership.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
     8
 * The ASF licenses this file to You under the Apache License, Version 2.0
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
     9
 * (the "License"); you may not use this file except in compliance with
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
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
 *
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
6
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
 */
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
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.util.Properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import javax.xml.transform.Result;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
    28
import org.xml.sax.Attributes;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
    29
import org.xml.sax.SAXException;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
    30
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.serializer.utils.Utils;
58022
12885822f0c5 8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents: 55575
diff changeset
    33
import javax.xml.transform.ErrorListener;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * This serializer takes a series of SAX or
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * SAX-like events and writes its output
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * to the given stream.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * This class is not a public API, it is public
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * because it is used from another package.
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * @xsl.usage internal
58022
12885822f0c5 8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents: 55575
diff changeset
    44
 * @LastModified: Aug 2019
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
public final class ToHTMLStream 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
    /** This flag is set while receiving events from the DTD */
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    protected boolean m_inDTD = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
    52
    /** True if the previous element is a block element. */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
    53
    private boolean m_isprevblock = false;
6
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 final CharInfo m_htmlcharInfo =
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
//        new CharInfo(CharInfo.HTML_ENTITIES_RESOURCE);
23954
1161e065d446 8029282: Enhance CharInfo set up
joehw
parents: 12902
diff changeset
    61
        CharInfo.getCharInfoInternal(CharInfo.HTML_ENTITIES_RESOURCE, Method.HTML);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    /** A digital search trie for fast, case insensitive lookup of ElemDesc objects. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    static final Trie m_elementFlags = new Trie();
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    static {
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
        initTagReference(m_elementFlags);
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    static void initTagReference(Trie m_elementFlags) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
        // HTML 4.0 loose DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
        m_elementFlags.put("BASEFONT", new ElemDesc(0 | ElemDesc.EMPTY));
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
            "FRAME",
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
            new ElemDesc(0 | ElemDesc.EMPTY | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        m_elementFlags.put("FRAMESET", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        m_elementFlags.put("NOFRAMES", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
            "ISINDEX",
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
            new ElemDesc(0 | ElemDesc.EMPTY | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
            "APPLET",
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
            new ElemDesc(0 | ElemDesc.WHITESPACESENSITIVE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        m_elementFlags.put("CENTER", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        m_elementFlags.put("DIR", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        m_elementFlags.put("MENU", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        // HTML 4.0 strict DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        m_elementFlags.put("TT", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        m_elementFlags.put("I", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        m_elementFlags.put("B", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        m_elementFlags.put("BIG", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        m_elementFlags.put("SMALL", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
        m_elementFlags.put("EM", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
        m_elementFlags.put("STRONG", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        m_elementFlags.put("DFN", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        m_elementFlags.put("CODE", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        m_elementFlags.put("SAMP", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        m_elementFlags.put("KBD", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
        m_elementFlags.put("VAR", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        m_elementFlags.put("CITE", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
        m_elementFlags.put("ABBR", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        m_elementFlags.put("ACRONYM", new ElemDesc(0 | ElemDesc.PHRASE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
            "SUP",
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
            new ElemDesc(0 | ElemDesc.SPECIAL | ElemDesc.ASPECIAL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
            "SUB",
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
            new ElemDesc(0 | ElemDesc.SPECIAL | ElemDesc.ASPECIAL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
            "SPAN",
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
            new ElemDesc(0 | ElemDesc.SPECIAL | ElemDesc.ASPECIAL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
            "BDO",
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
            new ElemDesc(0 | ElemDesc.SPECIAL | ElemDesc.ASPECIAL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            "BR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                    | ElemDesc.SPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                    | ElemDesc.ASPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
                    | ElemDesc.EMPTY
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
                    | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        m_elementFlags.put("BODY", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
            "ADDRESS",
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            "DIV",
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        m_elementFlags.put("A", new ElemDesc(0 | ElemDesc.SPECIAL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
            "MAP",
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
                0 | ElemDesc.SPECIAL | ElemDesc.ASPECIAL | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
            "AREA",
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
            new ElemDesc(0 | ElemDesc.EMPTY | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
            "LINK",
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                0 | ElemDesc.HEADMISC | ElemDesc.EMPTY | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
            "IMG",
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                    | ElemDesc.SPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                    | ElemDesc.ASPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
                    | ElemDesc.EMPTY
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
                    | ElemDesc.WHITESPACESENSITIVE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
            "OBJECT",
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
                    | ElemDesc.SPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
                    | ElemDesc.ASPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
                    | ElemDesc.HEADMISC
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
                    | ElemDesc.WHITESPACESENSITIVE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        m_elementFlags.put("PARAM", new ElemDesc(0 | ElemDesc.EMPTY));
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
            "HR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
                    | ElemDesc.BLOCKFORMFIELDSET
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
                    | ElemDesc.EMPTY));
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
            "P",
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
            "H1",
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
            new ElemDesc(0 | ElemDesc.HEAD | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
            "H2",
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            new ElemDesc(0 | ElemDesc.HEAD | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
            "H3",
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
            new ElemDesc(0 | ElemDesc.HEAD | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            "H4",
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            new ElemDesc(0 | ElemDesc.HEAD | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
            "H5",
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
            new ElemDesc(0 | ElemDesc.HEAD | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
            "H6",
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
            new ElemDesc(0 | ElemDesc.HEAD | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
            "PRE",
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
            new ElemDesc(0 | ElemDesc.PREFORMATTED | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            "Q",
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
            new ElemDesc(0 | ElemDesc.SPECIAL | ElemDesc.ASPECIAL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            "BLOCKQUOTE",
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
        m_elementFlags.put("INS", new ElemDesc(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        m_elementFlags.put("DEL", new ElemDesc(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
            "DL",
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        m_elementFlags.put("DT", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        m_elementFlags.put("DD", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
            "OL",
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
            new ElemDesc(0 | ElemDesc.LIST | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
            "UL",
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
            new ElemDesc(0 | ElemDesc.LIST | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
        m_elementFlags.put("LI", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
        m_elementFlags.put("FORM", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
        m_elementFlags.put("LABEL", new ElemDesc(0 | ElemDesc.FORMCTRL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            "INPUT",
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
                0 | ElemDesc.FORMCTRL | ElemDesc.INLINELABEL | ElemDesc.EMPTY));
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
            "SELECT",
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
            new ElemDesc(0 | ElemDesc.FORMCTRL | ElemDesc.INLINELABEL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        m_elementFlags.put("OPTGROUP", new ElemDesc(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        m_elementFlags.put("OPTION", new ElemDesc(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            "TEXTAREA",
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
            new ElemDesc(0 | ElemDesc.FORMCTRL | ElemDesc.INLINELABEL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
            "FIELDSET",
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
            new ElemDesc(0 | ElemDesc.BLOCK | ElemDesc.BLOCKFORM));
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
        m_elementFlags.put("LEGEND", new ElemDesc(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
            "BUTTON",
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
            new ElemDesc(0 | ElemDesc.FORMCTRL | ElemDesc.INLINELABEL));
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            "TABLE",
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        m_elementFlags.put("CAPTION", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
        m_elementFlags.put("THEAD", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        m_elementFlags.put("TFOOT", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
        m_elementFlags.put("TBODY", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
        m_elementFlags.put("COLGROUP", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
            "COL",
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            new ElemDesc(0 | ElemDesc.EMPTY | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        m_elementFlags.put("TR", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        m_elementFlags.put("TH", new ElemDesc(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
        m_elementFlags.put("TD", new ElemDesc(0));
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
            "HEAD",
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
            new ElemDesc(0 | ElemDesc.BLOCK | ElemDesc.HEADELEM));
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
        m_elementFlags.put("TITLE", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
            "BASE",
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
            new ElemDesc(0 | ElemDesc.EMPTY | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
            "META",
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
                0 | ElemDesc.HEADMISC | ElemDesc.EMPTY | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            "STYLE",
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
                0 | ElemDesc.HEADMISC | ElemDesc.RAW | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
            "SCRIPT",
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
                    | ElemDesc.SPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
                    | ElemDesc.ASPECIAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
                    | ElemDesc.HEADMISC
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
                    | ElemDesc.RAW));
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            "NOSCRIPT",
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
        m_elementFlags.put("HTML", new ElemDesc(0 | ElemDesc.BLOCK));
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        // From "John Ky" <hand@syd.speednet.com.au
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        // Transitional Document Type Definition ()
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        // file:///C:/Documents%20and%20Settings/sboag.BOAG600E/My%20Documents/html/sgml/loosedtd.html#basefont
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
        m_elementFlags.put("FONT", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        // file:///C:/Documents%20and%20Settings/sboag.BOAG600E/My%20Documents/html/present/graphics.html#edef-STRIKE
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        m_elementFlags.put("S", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
        m_elementFlags.put("STRIKE", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        // file:///C:/Documents%20and%20Settings/sboag.BOAG600E/My%20Documents/html/present/graphics.html#edef-U
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        m_elementFlags.put("U", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        // From "John Ky" <hand@syd.speednet.com.au
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
        m_elementFlags.put("NOBR", new ElemDesc(0 | ElemDesc.FONTSTYLE));
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        // HTML 4.0, section 16.5
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
            "IFRAME",
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        // Netscape 4 extension
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
            "LAYER",
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
        // Netscape 4 extension
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
        m_elementFlags.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
            "ILAYER",
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
            new ElemDesc(
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
                0
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
                    | ElemDesc.BLOCK
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
                    | ElemDesc.BLOCKFORM
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
                    | ElemDesc.BLOCKFORMFIELDSET));
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        // NOW FOR ATTRIBUTE INFORMATION . . .
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
        ElemDesc elemDesc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   350
        elemDesc = (ElemDesc) m_elementFlags.get("a");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
        elemDesc.setAttr("HREF", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
        elemDesc.setAttr("NAME", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   355
        elemDesc = (ElemDesc) m_elementFlags.get("area");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        elemDesc.setAttr("HREF", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        elemDesc.setAttr("NOHREF", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   360
        elemDesc = (ElemDesc) m_elementFlags.get("base");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
        elemDesc.setAttr("HREF", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   364
        elemDesc = (ElemDesc) m_elementFlags.get("button");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   368
        elemDesc = (ElemDesc) m_elementFlags.get("blockquote");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   372
        elemDesc = (ElemDesc) m_elementFlags.get("del");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   376
        elemDesc = (ElemDesc) m_elementFlags.get("dir");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
        // ----------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   381
        elemDesc = (ElemDesc) m_elementFlags.get("div");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL); // Netscape 4 extension
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY); // Internet-Explorer extension
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   386
        elemDesc = (ElemDesc) m_elementFlags.get("dl");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   390
        elemDesc = (ElemDesc) m_elementFlags.get("form");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
        elemDesc.setAttr("ACTION", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
        // ----------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
        // Attribution to: "Voytenko, Dimitry" <DVoytenko@SECTORBASE.COM>
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   395
        elemDesc = (ElemDesc) m_elementFlags.get("frame");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
        elemDesc.setAttr("LONGDESC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
        elemDesc.setAttr("NORESIZE",ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   401
        elemDesc = (ElemDesc) m_elementFlags.get("head");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
        elemDesc.setAttr("PROFILE", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   405
        elemDesc = (ElemDesc) m_elementFlags.get("hr");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        elemDesc.setAttr("NOSHADE", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        // ----------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
        // HTML 4.0, section 16.5
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   410
        elemDesc = (ElemDesc) m_elementFlags.get("iframe");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        elemDesc.setAttr("LONGDESC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        // ----------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
        // Netscape 4 extension
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   416
        elemDesc = (ElemDesc) m_elementFlags.get("ilayer");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   420
        elemDesc = (ElemDesc) m_elementFlags.get("img");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
        elemDesc.setAttr("LONGDESC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
        elemDesc.setAttr("USEMAP", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
        elemDesc.setAttr("ISMAP", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   427
        elemDesc = (ElemDesc) m_elementFlags.get("input");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
        elemDesc.setAttr("USEMAP", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
        elemDesc.setAttr("CHECKED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
        elemDesc.setAttr("ISMAP", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
        elemDesc.setAttr("READONLY", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   436
        elemDesc = (ElemDesc) m_elementFlags.get("ins");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
        // ----------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        // Netscape 4 extension
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   441
        elemDesc = (ElemDesc) m_elementFlags.get("layer");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   445
        elemDesc = (ElemDesc) m_elementFlags.get("link");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
        elemDesc.setAttr("HREF", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   449
        elemDesc = (ElemDesc) m_elementFlags.get("menu");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   453
        elemDesc = (ElemDesc) m_elementFlags.get("object");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
        elemDesc.setAttr("CLASSID", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        elemDesc.setAttr("CODEBASE", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        elemDesc.setAttr("DATA", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        elemDesc.setAttr("ARCHIVE", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
        elemDesc.setAttr("USEMAP", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        elemDesc.setAttr("DECLARE", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   462
        elemDesc = (ElemDesc) m_elementFlags.get("ol");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   466
        elemDesc = (ElemDesc) m_elementFlags.get("optgroup");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   470
        elemDesc = (ElemDesc) m_elementFlags.get("option");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
        elemDesc.setAttr("SELECTED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   475
        elemDesc = (ElemDesc) m_elementFlags.get("q");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
        elemDesc.setAttr("CITE", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   479
        elemDesc = (ElemDesc) m_elementFlags.get("script");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
        elemDesc.setAttr("SRC", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
        elemDesc.setAttr("FOR", ElemDesc.ATTRURL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
        elemDesc.setAttr("DEFER", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   485
        elemDesc = (ElemDesc) m_elementFlags.get("select");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
        elemDesc.setAttr("MULTIPLE", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   490
        elemDesc = (ElemDesc) m_elementFlags.get("table");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY); // Internet-Explorer extension
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   494
        elemDesc = (ElemDesc) m_elementFlags.get("td");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   498
        elemDesc = (ElemDesc) m_elementFlags.get("textarea");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
        elemDesc.setAttr("DISABLED", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
        elemDesc.setAttr("READONLY", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   503
        elemDesc = (ElemDesc) m_elementFlags.get("th");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
        // ----------------------------------------------
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
        // The nowrap attribute of a tr element is both
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
        // a Netscape and Internet-Explorer extension
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   509
        elemDesc = (ElemDesc) m_elementFlags.get("tr");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
        elemDesc.setAttr("NOWRAP", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
        // ----------------------------------------------
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
   513
        elemDesc = (ElemDesc) m_elementFlags.get("ul");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
        elemDesc.setAttr("COMPACT", ElemDesc.ATTREMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
     * Dummy element for elements not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
    static private final ElemDesc m_dummy = new ElemDesc(0 | ElemDesc.BLOCK);
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
    /** True if URLs should be specially escaped with the %xx form. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
    private boolean m_specialEscapeURLs = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
    /** True if the META tag should be omitted. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
    private boolean m_omitMetaTag = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
     * Tells if the formatter should use special URL escaping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
     * @param bool True if URLs should be specially escaped with the %xx form.
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
    public void setSpecialEscapeURLs(boolean bool)
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
        m_specialEscapeURLs = bool;
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
     * Tells if the formatter should omit the META tag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
     * @param bool True if the META tag should be omitted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
    public void setOmitMetaTag(boolean bool)
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
        m_omitMetaTag = bool;
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
     * Specifies an output format for this serializer. It the
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
     * serializer has already been associated with an output format,
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
     * it will switch to the new format. This method should not be
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
     * called while the serializer is in the process of serializing
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
     * a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
     * This method can be called multiple times before starting
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
     * the serialization of a particular result-tree. In principle
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
     * all serialization parameters can be changed, with the exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
     * of method="html" (it must be method="html" otherwise we
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
     * shouldn't even have a ToHTMLStream object here!)
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
     * @param format The output format or serialzation parameters
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
     * to use.
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
    public void setOutputFormat(Properties format)
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
        m_specialEscapeURLs =
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
            OutputPropertyUtils.getBooleanProperty(
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
                OutputPropertiesFactory.S_USE_URL_ESCAPING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                format);
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
        m_omitMetaTag =
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
            OutputPropertyUtils.getBooleanProperty(
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
                OutputPropertiesFactory.S_OMIT_META_TAG,
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
                format);
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
        super.setOutputFormat(format);
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
     * Tells if the formatter should use special URL escaping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
     * @return True if URLs should be specially escaped with the %xx form.
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
    private final boolean getSpecialEscapeURLs()
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
        return m_specialEscapeURLs;
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
     * Tells if the formatter should omit the META tag.
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
     * @return True if the META tag should be omitted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
    private final boolean getOmitMetaTag()
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
        return m_omitMetaTag;
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
     * Get a description of the given element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
     * @param name non-null name of element, case insensitive.
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
     * @return non-null reference to ElemDesc, which may be m_dummy if no
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
     *         element description matches the given name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
    public static final ElemDesc getElemDesc(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
        /* this method used to return m_dummy  when name was null
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
         * but now it doesn't check and and requires non-null name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
        Object obj = m_elementFlags.get(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
        if (null != obj)
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
            return (ElemDesc)obj;
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
        return m_dummy;
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
     * A Trie that is just a copy of the "static" one.
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
     * We need this one to be able to use the faster, but not thread-safe
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
     * method Trie.get2(name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
    private Trie m_htmlInfo = new Trie(m_elementFlags);
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
     * Calls to this method could be replaced with calls to
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
     * getElemDesc(name), but this one should be faster.
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
    private ElemDesc getElemDesc2(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
        Object obj = m_htmlInfo.get2(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
        if (null != obj)
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
            return (ElemDesc)obj;
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
        return m_dummy;
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
     * Default constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
    public ToHTMLStream()
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
    {
58022
12885822f0c5 8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents: 55575
diff changeset
   642
        this(null);
12885822f0c5 8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents: 55575
diff changeset
   643
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
58022
12885822f0c5 8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents: 55575
diff changeset
   645
    public ToHTMLStream(ErrorListener l)
12885822f0c5 8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents: 55575
diff changeset
   646
    {
12885822f0c5 8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents: 55575
diff changeset
   647
        super(l);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
        m_charInfo = m_htmlcharInfo;
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
        // initialize namespaces
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
        m_prefixMap = new NamespaceMappings();
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
    /** The name of the current element. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
//    private String m_currentElementName = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
     * Receive notification of the beginning of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
    protected void startDocumentInternal() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
        super.startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
        m_needToCallStartDocument = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
        m_needToOutputDocTypeDecl = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        m_startNewLine = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
        setOmitXMLDeclaration(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        if (true == m_needToOutputDocTypeDecl)
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
            String doctypeSystem = getDoctypeSystem();
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
            String doctypePublic = getDoctypePublic();
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
            if ((null != doctypeSystem) || (null != doctypePublic))
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
                final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
                try
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
                writer.write("<!DOCTYPE html");
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
                if (null != doctypePublic)
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
                    writer.write(" PUBLIC \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
                    writer.write(doctypePublic);
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
                    writer.write('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
                if (null != doctypeSystem)
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
                    if (null == doctypePublic)
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
                        writer.write(" SYSTEM \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
                        writer.write(" \"");
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
                    writer.write(doctypeSystem);
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
                    writer.write('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
                writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
                outputLineSep();
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
                catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
                    throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
        m_needToOutputDocTypeDecl = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
     * Receive notification of the end of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
    public final void endDocument() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
    {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   725
        if (m_doIndent) {
55575
25165403c62e 8223291: Whitespace is added to CDATA tags when using OutputKeys.INDENT to format XML
joehw
parents: 51786
diff changeset
   726
            flushCharactersBuffer(false);
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   727
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
        flushPending();
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
        if (m_doIndent && !m_isprevtext)
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
            outputLineSep();
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
            catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
                throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
        flushWriter();
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
        if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
            super.fireEndDoc();
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
    /**
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   747
     * If the previous is an inline element, won't insert a new line before the
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   748
     * text.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   749
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   750
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   751
    protected boolean shouldIndentForText() {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   752
        return super.shouldIndentForText() && m_isprevblock;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   753
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   754
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   755
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   756
     * Only check m_doIndent, disregard m_ispreserveSpace.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   757
     *
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   758
     * @return True if the content should be formatted.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   759
     */
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   760
    protected boolean shouldFormatOutput() {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   761
        return m_doIndent;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   762
    }
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   763
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   764
    /**
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   765
     * Receive notification of the beginning of an element.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
     *
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   768
     * @param namespaceURI
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   769
     * @param localName
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   770
     * @param name
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   771
     *            The element type name.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   772
     * @param atts
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   773
     *            The attributes attached to the element, if any.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   774
     * @throws org.xml.sax.SAXException
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   775
     *             Any SAX exception, possibly wrapping another exception.
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   776
     * @see #endElement
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   777
     * @see org.xml.sax.AttributeList
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
    public void startElement(
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
        String namespaceURI,
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
        String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
        String name,
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
        Attributes atts)
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   784
        throws SAXException
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
    {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   786
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   787
            // will add extra one if having namespace but no matter
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   788
            m_childNodeNum++;
55575
25165403c62e 8223291: Whitespace is added to CDATA tags when using OutputKeys.INDENT to format XML
joehw
parents: 51786
diff changeset
   789
            flushCharactersBuffer(false);
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   790
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
        ElemContext elemContext = m_elemContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
        // clean up any pending things first
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
        if (elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
            closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
            elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
        else if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
            closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
            m_cdataTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
        else if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
            startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
            m_needToCallStartDocument = false;
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
        // if this element has a namespace then treat it like XML
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
        if (null != namespaceURI && namespaceURI.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
            super.startElement(namespaceURI, localName, name, atts);
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
            // getElemDesc2(name) is faster than getElemDesc(name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
            ElemDesc elemDesc = getElemDesc2(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
            int elemFlags = elemDesc.getFlags();
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
            // deal with indentation issues first
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
            if (m_doIndent)
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
                boolean isBlockElement = (elemFlags & ElemDesc.BLOCK) != 0;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   829
                if ((elemContext.m_elementName != null)
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   830
                        // If this element is a block element,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   831
                        // or if this is not a block element, then if the
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   832
                        // previous is neither a text nor an inline
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   833
                        && (isBlockElement || (!(m_isprevtext || !m_isprevblock))))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
                    m_startNewLine = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
                    indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
                }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   839
                m_isprevblock = isBlockElement;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
            // save any attributes for later processing
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
            if (atts != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
                addAttributes(atts);
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
            m_isprevtext = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
            final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
            writer.write('<');
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
            writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   851
            if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   852
                m_childNodeNumStack.add(m_childNodeNum);
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   853
                m_childNodeNum = 0;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   854
            }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
            if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
                firePseudoAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
            if ((elemFlags & ElemDesc.EMPTY) != 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
                // an optimization for elements which are expected
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
                // to be empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
                m_elemContext = elemContext.push();
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
                /* XSLTC sometimes calls namespaceAfterStartElement()
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
                 * so we need to remember the name
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
                 */
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
                m_elemContext.m_elementName = name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
                m_elemContext.m_elementDesc = elemDesc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
                return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
                elemContext = elemContext.push(namespaceURI,localName,name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
                m_elemContext = elemContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
                elemContext.m_elementDesc = elemDesc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
                elemContext.m_isRaw = (elemFlags & ElemDesc.RAW) != 0;
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   877
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   878
                // set m_startNewLine for the next element
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   879
                if (m_doIndent) {
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   880
                    // elemFlags is equivalent to m_elemContext.m_elementDesc.getFlags(),
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   881
                    // in this branch m_elemContext.m_elementName is not null
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   882
                    boolean isBlockElement = (elemFlags & ElemDesc.BLOCK) != 0;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   883
                    if (isBlockElement)
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   884
                        m_startNewLine = true;
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   885
                }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
            if ((elemFlags & ElemDesc.HEADELEM) != 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
                // This is the <HEAD> element, do some special processing
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
                closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
                elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
                if (!m_omitMetaTag)
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
                    if (m_doIndent)
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
                        indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
                    writer.write(
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
                        "<META http-equiv=\"Content-Type\" content=\"text/html; charset=");
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
                    String encoding = getEncoding();
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
                    String encode = Encodings.getMimeEncoding(encoding);
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
                    writer.write(encode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
                    writer.write("\">");
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
     *  Receive notification of the end of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
     *  @param namespaceURI
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
     *  @param localName
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
     *  @param name The element type name
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
     *  @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
     *             wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
    public final void endElement(
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
        final String namespaceURI,
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
        final String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
        final String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
    {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   929
        if (m_doIndent) {
55575
25165403c62e 8223291: Whitespace is added to CDATA tags when using OutputKeys.INDENT to format XML
joehw
parents: 51786
diff changeset
   930
            flushCharactersBuffer(false);
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
   931
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
        // deal with any pending issues
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
        if (m_cdataTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
            closeCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
        // if the element has a namespace, treat it like XML, not HTML
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
        if (null != namespaceURI && namespaceURI.length() > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
            super.endElement(namespaceURI, localName, name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
            ElemContext elemContext = m_elemContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
            final ElemDesc elemDesc = elemContext.m_elementDesc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
            final int elemFlags = elemDesc.getFlags();
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
            final boolean elemEmpty = (elemFlags & ElemDesc.EMPTY) != 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
            // deal with any indentation issues
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
            if (m_doIndent)
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
                final boolean isBlockElement = (elemFlags&ElemDesc.BLOCK) != 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
                boolean shouldIndent = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   958
                // If this element is a block element,
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   959
                // or if this is not a block element, then if the previous is
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   960
                // neither a text nor an inline
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   961
                if (isBlockElement || (!(m_isprevtext || !m_isprevblock)))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
                    m_startNewLine = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
                    shouldIndent = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
                }
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   966
                if (!elemContext.m_startTagOpen && shouldIndent && (m_childNodeNum > 1 || !m_isprevtext))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
                    indent(elemContext.m_currentElemDepth - 1);
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   968
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
   969
                m_isprevblock = isBlockElement;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
            final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
            if (!elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
                writer.write("</");
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
                writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
                writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
                // the start-tag open when this method was called,
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
                // so we need to process it now.
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
                if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
                    super.fireStartElem(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
                // the starting tag was still open when we received this endElement() call
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
                // so we need to process any gathered attributes NOW, before they go away.
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
                int nAttrs = m_attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
                if (nAttrs > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
                    processAttributes(m_writer, nAttrs);
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
                    // clear attributes object for re-use with next element
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
                    m_attributes.clear();
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
                if (!elemEmpty)
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
                    // As per Dave/Paul recommendation 12/06/2000
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
                    // if (shouldIndent)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
                    // writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
                    //  indent(m_currentIndent);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
                    writer.write("></");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
                    writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
                    writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
                    writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1013
            if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1014
                m_childNodeNum = m_childNodeNumStack.remove(m_childNodeNumStack.size() - 1);
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1015
                // clean up because the element has ended
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1016
                m_isprevtext = false;
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1017
            }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
            // fire off the end element event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
            if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
                super.fireEndElem(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
            // OPTIMIZE-EMPTY
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
            if (elemEmpty)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
                // a quick exit if the HTML element had no children.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
                // This block of code can be removed if the corresponding block of code
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
                // in startElement() also labeled with "OPTIMIZE-EMPTY" is also removed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
                m_elemContext = elemContext.m_prev;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
                return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
            // some more clean because the element has ended.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
            m_elemContext = elemContext.m_prev;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
//            m_isRawStack.pop();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
        catch (IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
     * Process an attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
     * @param   writer The writer to write the processed output to.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
     * @param   name   The name of the attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
     * @param   value   The value of the attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
     * @param   elemDesc The description of the HTML element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
     *           that has this attribute.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
    protected void processAttribute(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
        java.io.Writer writer,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
        String name,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
        String value,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
        ElemDesc elemDesc)
51786
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1057
        throws IOException, SAXException
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
        writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
        if (   ((value.length() == 0) || value.equalsIgnoreCase(name))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
            && elemDesc != null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
            && elemDesc.isAttrFlagSet(name, ElemDesc.ATTREMPTY))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
            writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
            // %REVIEW% %OPT%
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
            // Two calls to single-char write may NOT
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
            // be more efficient than one to string-write...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
            writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
            writer.write("=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
            if (   elemDesc != null
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
                && elemDesc.isAttrFlagSet(name, ElemDesc.ATTRURL))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
                writeAttrURI(writer, value, m_specialEscapeURLs);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
                writeAttrString(writer, value, this.getEncoding());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
            writer.write('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
     * Tell if a character is an ASCII digit.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
    private boolean isASCIIDigit(char c)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
        return (c >= '0' && c <= '9');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
     * Make an integer into an HH hex value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
     * Does no checking on the size of the input, since this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
     * is only meant to be used locally by writeAttrURI.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
     * @param i must be a value less than 255.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
     * @return should be a two character string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
    private static String makeHHString(int i)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
        String s = Integer.toHexString(i).toUpperCase();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
        if (s.length() == 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
            s = "0" + s;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
        return s;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
    * Dmitri Ilyin: Makes sure if the String is HH encoded sign.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
    * @param str must be 2 characters long
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
    * @return true or false
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
    private boolean isHHSign(String str)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
        boolean sign = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
            char r = (char) Integer.parseInt(str, 16);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
        catch (NumberFormatException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
            sign = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
        return sign;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
     * Write the specified <var>string</var> after substituting non ASCII characters,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
     * with <CODE>%HH</CODE>, where HH is the hex of the byte value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
     * @param   string      String to convert to XML format.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
     * @param doURLEscaping True if we should try to encode as
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
     *                      per http://www.ietf.org/rfc/rfc2396.txt.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
     * @throws org.xml.sax.SAXException if a bad surrogate pair is detected.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
    public void writeAttrURI(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
        final java.io.Writer writer, String string, boolean doURLEscaping)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
        // http://www.ietf.org/rfc/rfc2396.txt says:
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
        // A URI is always in an "escaped" form, since escaping or unescaping a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
        // completed URI might change its semantics.  Normally, the only time
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
        // escape encodings can safely be made is when the URI is being created
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
        // from its component parts; each component may have its own set of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
        // characters that are reserved, so only the mechanism responsible for
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
        // generating or interpreting that component can determine whether or
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
        // not escaping a character will change its semantics. Likewise, a URI
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
        // must be separated into its components before the escaped characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
        // within those components can be safely decoded.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
        // ...So we do our best to do limited escaping of the URL, without
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
        // causing damage.  If the URL is already properly escaped, in theory, this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
        // function should not change the string value.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
        final int end = string.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
        if (end > m_attrBuff.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
           m_attrBuff = new char[end*2 + 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
        string.getChars(0,end, m_attrBuff, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
        final char[] chars = m_attrBuff;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
        int cleanStart = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
        int cleanLength = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
        char ch = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
        for (int i = 0; i < end; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
            ch = chars[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
            if ((ch < 32) || (ch > 126))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
                if (cleanLength > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
                    writer.write(chars, cleanStart, cleanLength);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
                    cleanLength = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
                if (doURLEscaping)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
                    // Encode UTF16 to UTF8.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
                    // Reference is Unicode, A Primer, by Tony Graham.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
                    // Page 92.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
                    // Note that Kay doesn't escape 0x20...
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
                    //  if(ch == 0x20) // Not sure about this... -sb
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
                    //  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
                    //    writer.write(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
                    //  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
                    //  else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
                    if (ch <= 0x7F)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
                        writer.write(makeHHString(ch));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
                    else if (ch <= 0x7FF)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
                        // Clear low 6 bits before rotate, put high 4 bits in low byte,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
                        // and set two high bits.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
                        int high = (ch >> 6) | 0xC0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
                        int low = (ch & 0x3F) | 0x80;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
                        // First 6 bits, + high bit
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
                        writer.write(makeHHString(high));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
                        writer.write(makeHHString(low));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
                    else if (Encodings.isHighUTF16Surrogate(ch)) // high surrogate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
                        // I'm sure this can be done in 3 instructions, but I choose
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
                        // to try and do it exactly like it is done in the book, at least
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
                        // until we are sure this is totally clean.  I don't think performance
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
                        // is a big issue with this particular function, though I could be
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
                        // wrong.  Also, the stuff below clearly does more masking than
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
                        // it needs to do.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
                        // Clear high 6 bits.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
                        int highSurrogate = ((int) ch) & 0x03FF;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
                        // Middle 4 bits (wwww) + 1
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
                        // "Note that the value of wwww from the high surrogate bit pattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
                        // is incremented to make the uuuuu bit pattern in the scalar value
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
                        // so the surrogate pair don't address the BMP."
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
                        int wwww = ((highSurrogate & 0x03C0) >> 6);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
                        int uuuuu = wwww + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
                        // next 4 bits
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
                        int zzzz = (highSurrogate & 0x003C) >> 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
                        // low 2 bits
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
                        int yyyyyy = ((highSurrogate & 0x0003) << 4) & 0x30;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
                        // Get low surrogate character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
                        ch = chars[++i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
                        // Clear high 6 bits.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
                        int lowSurrogate = ((int) ch) & 0x03FF;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
                        // put the middle 4 bits into the bottom of yyyyyy (byte 3)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
                        yyyyyy = yyyyyy | ((lowSurrogate & 0x03C0) >> 6);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
                        // bottom 6 bits.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
                        int xxxxxx = (lowSurrogate & 0x003F);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
                        int byte1 = 0xF0 | (uuuuu >> 2); // top 3 bits of uuuuu
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
                        int byte2 =
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
                            0x80 | (((uuuuu & 0x03) << 4) & 0x30) | zzzz;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
                        int byte3 = 0x80 | yyyyyy;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
                        int byte4 = 0x80 | xxxxxx;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
                        writer.write(makeHHString(byte1));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
                        writer.write(makeHHString(byte2));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
                        writer.write(makeHHString(byte3));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
                        writer.write(makeHHString(byte4));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
                        int high = (ch >> 12) | 0xE0; // top 4 bits
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
                        int middle = ((ch & 0x0FC0) >> 6) | 0x80;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
                        // middle 6 bits
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
                        int low = (ch & 0x3F) | 0x80;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
                        // First 6 bits, + high bit
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
                        writer.write(makeHHString(high));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
                        writer.write(makeHHString(middle));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
                        writer.write('%');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
                        writer.write(makeHHString(low));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
                else if (escapingNotNeeded(ch))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
                    writer.write(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
                    writer.write("&#");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
                    writer.write(Integer.toString(ch));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
                    writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
                // In this character range we have first written out any previously accumulated
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
                // "clean" characters, then processed the current more complicated character,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
                // which may have incremented "i".
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
                // We now we reset the next possible clean character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
                cleanStart = i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
            // Since http://www.ietf.org/rfc/rfc2396.txt refers to the URI grammar as
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
            // not allowing quotes in the URI proper syntax, nor in the fragment
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
            // identifier, we believe that it's OK to double escape quotes.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
            else if (ch == '"')
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
                // If the character is a '%' number number, try to avoid double-escaping.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
                // There is a question if this is legal behavior.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
                // Dmitri Ilyin: to check if '%' number number is invalid. It must be checked if %xx is a sign, that would be encoded
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
                // The encoded signes are in Hex form. So %xx my be in form %3C that is "<" sign. I will try to change here a little.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
                //        if( ((i+2) < len) && isASCIIDigit(stringArray[i+1]) && isASCIIDigit(stringArray[i+2]) )
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
                // We are no longer escaping '%'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
                if (cleanLength > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
                    writer.write(chars, cleanStart, cleanLength);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
                    cleanLength = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
                // Mike Kay encodes this as &#34;, so he may know something I don't?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
                if (doURLEscaping)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
                    writer.write("%22");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
                    writer.write("&quot;"); // we have to escape this, I guess.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
                // We have written out any clean characters, then the escaped '%' and now we
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
                // We now we reset the next possible clean character.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
                cleanStart = i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
            else if (ch == '&')
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
                // HTML 4.01 reads, "Authors should use "&amp;" (ASCII decimal 38)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
                // instead of "&" to avoid confusion with the beginning of a character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
                // reference (entity reference open delimiter).
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
                if (cleanLength > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
                    writer.write(chars, cleanStart, cleanLength);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
                    cleanLength = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
                writer.write("&amp;");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
                cleanStart = i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
                // no processing for this character, just count how
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
                // many characters in a row that we have that need no processing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
                cleanLength++;
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
        // are there any clean characters at the end of the array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
        // that we haven't processed yet?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
        if (cleanLength > 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
            // if the whole string can be written out as-is do so
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
            // otherwise write out the clean chars at the end of the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
            // array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
            if (cleanStart == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
                writer.write(string);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
                writer.write(chars, cleanStart, cleanLength);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
        else if (cleanLength == 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
            // a little optimization for 1 clean character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
            // (we could have let the previous if(...) handle them all)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
            writer.write(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
     * Writes the specified <var>string</var> after substituting <VAR>specials</VAR>,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
     * and UTF-16 surrogates for character references <CODE>&amp;#xnn</CODE>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
     * @param   string      String to convert to XML format.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
     * @param   encoding    CURRENTLY NOT IMPLEMENTED.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
    public void writeAttrString(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
        final java.io.Writer writer, String string, String encoding)
51786
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1381
        throws IOException, SAXException
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
        final int end = string.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
        if (end > m_attrBuff.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
            m_attrBuff = new char[end * 2 + 1];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
        string.getChars(0, end, m_attrBuff, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
        final char[] chars = m_attrBuff;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
        int cleanStart = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
        int cleanLength = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
        char ch = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
        for (int i = 0; i < end; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
            ch = chars[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
            // System.out.println("SPECIALSSIZE: "+SPECIALSSIZE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
            // System.out.println("ch: "+(int)ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
            // System.out.println("m_maxCharacter: "+(int)m_maxCharacter);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
            // System.out.println("m_attrCharsMap[ch]: "+(int)m_attrCharsMap[ch]);
12902
0a840d92fa30 7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents: 12458
diff changeset
  1405
            if (escapingNotNeeded(ch) && (!m_charInfo.isSpecialAttrChar(ch)))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
                cleanLength++;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
            else if ('<' == ch || '>' == ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
                cleanLength++; // no escaping in this case, as specified in 15.2
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
            else if (
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
                ('&' == ch) && ((i + 1) < end) && ('{' == chars[i + 1]))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
                cleanLength++; // no escaping in this case, as specified in 15.2
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
                if (cleanLength > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
                    writer.write(chars,cleanStart,cleanLength);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
                    cleanLength = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
                int pos = accumDefaultEntity(writer, ch, i, chars, end, false, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
7f561c08de6b Initial load
duke
parents:
diff changeset
  1427
                if (i != pos)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
                    i = pos - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
                {
51786
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1433
                    if (Encodings.isHighUTF16Surrogate(ch) ||
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1434
                            Encodings.isLowUTF16Surrogate(ch))
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1435
                    {
51786
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1436
                        if (writeUTF16Surrogate(ch, chars, i, end) >= 0) {
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1437
                            // move the index if the low surrogate is consumed
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1438
                            // as writeUTF16Surrogate has written the pair
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1439
                            if (Encodings.isHighUTF16Surrogate(ch)) {
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1440
                                i++;
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1441
                            }
c93f14a4ae29 8207760: SAXException: Invalid UTF-16 surrogate detected: d83c ?
joehw
parents: 47216
diff changeset
  1442
                        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1443
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1444
7f561c08de6b Initial load
duke
parents:
diff changeset
  1445
                    // The next is kind of a hack to keep from escaping in the case
7f561c08de6b Initial load
duke
parents:
diff changeset
  1446
                    // of Shift_JIS and the like.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1447
7f561c08de6b Initial load
duke
parents:
diff changeset
  1448
                    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  1449
                    else if ((ch < m_maxCharacter) && (m_maxCharacter == 0xFFFF)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1450
                    && (ch != 160))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1451
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1452
                    writer.write(ch);  // no escaping in this case
7f561c08de6b Initial load
duke
parents:
diff changeset
  1453
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1454
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1455
                    */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1456
                    String outputStringForChar = m_charInfo.getOutputStringForChar(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1457
                    if (null != outputStringForChar)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1458
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1459
                        writer.write(outputStringForChar);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1460
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1461
                    else if (escapingNotNeeded(ch))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1462
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1463
                        writer.write(ch); // no escaping in this case
7f561c08de6b Initial load
duke
parents:
diff changeset
  1464
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1465
                    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1466
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1467
                        writer.write("&#");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1468
                        writer.write(Integer.toString(ch));
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
                        writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1472
                cleanStart = i + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
        } // end of for()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
        // are there any clean characters at the end of the array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
        // that we haven't processed yet?
7f561c08de6b Initial load
duke
parents:
diff changeset
  1478
        if (cleanLength > 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1479
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1480
            // if the whole string can be written out as-is do so
7f561c08de6b Initial load
duke
parents:
diff changeset
  1481
            // otherwise write out the clean chars at the end of the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1482
            // array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1483
            if (cleanStart == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1484
                writer.write(string);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1485
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1486
                writer.write(chars, cleanStart, cleanLength);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1487
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1488
        else if (cleanLength == 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1489
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1490
            // a little optimization for 1 clean character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1491
            // (we could have let the previous if(...) handle them all)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1492
            writer.write(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1493
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1494
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1495
7f561c08de6b Initial load
duke
parents:
diff changeset
  1496
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1499
     * Receive notification of character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1500
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1501
     * <p>The Parser will call this method to report each chunk of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1502
     * character data.  SAX parsers may return all contiguous character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1503
     * data in a single chunk, or they may split it into several
7f561c08de6b Initial load
duke
parents:
diff changeset
  1504
     * chunks; however, all of the characters in any single event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
     * must come from the same external entity, so that the Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
     * provides useful information.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1507
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1508
     * <p>The application must not attempt to read from the array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1509
     * outside of the specified range.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1510
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1511
     * <p>Note that some parsers will report whitespace using the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1512
     * ignorableWhitespace() method rather than this one (validating
7f561c08de6b Initial load
duke
parents:
diff changeset
  1513
     * parsers must do so).</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1514
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1515
     * @param chars The characters from the XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1516
     * @param start The start position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1517
     * @param length The number of characters to read from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1518
     * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1519
     *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1520
     * @see #ignorableWhitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1521
     * @see org.xml.sax.Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1522
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1523
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1524
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1525
    public final void characters(char chars[], int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1526
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1527
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1528
7f561c08de6b Initial load
duke
parents:
diff changeset
  1529
        if (m_elemContext.m_isRaw)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1530
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1531
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1532
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1533
                if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1534
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1535
                    closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
                    m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
//              With m_ispreserve just set true it looks like shouldIndent()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1540
//              will always return false, so drop any possible indentation.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1541
//              if (shouldIndent())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1542
//                  indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1543
7f561c08de6b Initial load
duke
parents:
diff changeset
  1544
                // writer.write("<![CDATA[");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1545
                // writer.write(chars, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1546
                writeNormalizedChars(chars, start, length, false, m_lineSepUse);
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
  1547
                m_isprevtext = true;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1548
                // writer.write("]]>");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1549
7f561c08de6b Initial load
duke
parents:
diff changeset
  1550
                // time to generate characters event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1551
                if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1552
                    super.fireCharEvent(chars, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1553
7f561c08de6b Initial load
duke
parents:
diff changeset
  1554
                return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1555
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1556
            catch (IOException ioe)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1557
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1558
                throw new org.xml.sax.SAXException(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1559
                    Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1560
                        MsgKey.ER_OIERROR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1561
                        null),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1562
                    ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1563
                //"IO error", ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1564
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1565
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1566
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1567
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1568
            super.characters(chars, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1569
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1570
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1571
7f561c08de6b Initial load
duke
parents:
diff changeset
  1572
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1573
     *  Receive notification of cdata.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1574
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1575
     *  <p>The Parser will call this method to report each chunk of
7f561c08de6b Initial load
duke
parents:
diff changeset
  1576
     *  character data.  SAX parsers may return all contiguous character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1577
     *  data in a single chunk, or they may split it into several
7f561c08de6b Initial load
duke
parents:
diff changeset
  1578
     *  chunks; however, all of the characters in any single event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1579
     *  must come from the same external entity, so that the Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1580
     *  provides useful information.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1581
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1582
     *  <p>The application must not attempt to read from the array
7f561c08de6b Initial load
duke
parents:
diff changeset
  1583
     *  outside of the specified range.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1584
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1585
     *  <p>Note that some parsers will report whitespace using the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1586
     *  ignorableWhitespace() method rather than this one (validating
7f561c08de6b Initial load
duke
parents:
diff changeset
  1587
     *  parsers must do so).</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
  1588
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1589
     *  @param ch The characters from the XML document.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1590
     *  @param start The start position in the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1591
     *  @param length The number of characters to read from the array.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1592
     *  @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1593
     *             wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1594
     *  @see #ignorableWhitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1595
     *  @see org.xml.sax.Locator
7f561c08de6b Initial load
duke
parents:
diff changeset
  1596
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1597
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1598
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1599
    public final void cdata(char ch[], int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1600
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1601
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1602
        if ((null != m_elemContext.m_elementName)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1603
            && (m_elemContext.m_elementName.equalsIgnoreCase("SCRIPT")
7f561c08de6b Initial load
duke
parents:
diff changeset
  1604
                || m_elemContext.m_elementName.equalsIgnoreCase("STYLE")))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1605
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1606
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1607
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1608
                if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1609
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1610
                    closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1611
                    m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1612
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1613
7f561c08de6b Initial load
duke
parents:
diff changeset
  1614
                if (shouldIndent())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1615
                    indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1616
7f561c08de6b Initial load
duke
parents:
diff changeset
  1617
                // writer.write(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1618
                writeNormalizedChars(ch, start, length, true, m_lineSepUse);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1619
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1620
            catch (IOException ioe)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1621
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1622
                throw new org.xml.sax.SAXException(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1623
                    Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1624
                        MsgKey.ER_OIERROR,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1625
                        null),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1626
                    ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1627
                //"IO error", ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1628
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1629
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1630
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1631
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1632
            super.cdata(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1633
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1634
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1635
7f561c08de6b Initial load
duke
parents:
diff changeset
  1636
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1637
     *  Receive notification of a processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1638
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1639
     *  @param target The processing instruction target.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1640
     *  @param data The processing instruction data, or null if
7f561c08de6b Initial load
duke
parents:
diff changeset
  1641
     *         none was supplied.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1642
     *  @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1643
     *             wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1644
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1645
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1646
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1647
    public void processingInstruction(String target, String data)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1648
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1649
    {
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1650
        if (m_doIndent) {
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1651
            m_childNodeNum++;
55575
25165403c62e 8223291: Whitespace is added to CDATA tags when using OutputKeys.INDENT to format XML
joehw
parents: 51786
diff changeset
  1652
            flushCharactersBuffer(false);
43744
5436902a27d7 8173290: 3% regression in SPECjvm2008-XML with b150
fyuan
parents: 42805
diff changeset
  1653
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1654
        // Process any pending starDocument and startElement first.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1655
        flushPending();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1656
7f561c08de6b Initial load
duke
parents:
diff changeset
  1657
        // Use a fairly nasty hack to tell if the next node is supposed to be
7f561c08de6b Initial load
duke
parents:
diff changeset
  1658
        // unescaped text.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1659
        if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1660
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1661
            startNonEscaping();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1662
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1663
        else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1664
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1665
            endNonEscaping();
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
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1670
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1671
            if (m_elemContext.m_startTagOpen)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1672
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1673
                closeStartTag();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1674
                m_elemContext.m_startTagOpen = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1675
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1676
            else if (m_needToCallStartDocument)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1677
                startDocumentInternal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1678
7f561c08de6b Initial load
duke
parents:
diff changeset
  1679
            if (shouldIndent())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1680
                indent();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1681
7f561c08de6b Initial load
duke
parents:
diff changeset
  1682
            final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1683
            //writer.write("<?" + target);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1684
            writer.write("<?");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1685
            writer.write(target);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1686
7f561c08de6b Initial load
duke
parents:
diff changeset
  1687
            if (data.length() > 0 && !Character.isSpaceChar(data.charAt(0)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1688
                writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1689
7f561c08de6b Initial load
duke
parents:
diff changeset
  1690
            //writer.write(data + ">"); // different from XML
7f561c08de6b Initial load
duke
parents:
diff changeset
  1691
            writer.write(data); // different from XML
7f561c08de6b Initial load
duke
parents:
diff changeset
  1692
            writer.write('>'); // different from XML
7f561c08de6b Initial load
duke
parents:
diff changeset
  1693
7f561c08de6b Initial load
duke
parents:
diff changeset
  1694
            // Always output a newline char if not inside of an
7f561c08de6b Initial load
duke
parents:
diff changeset
  1695
            // element. The whitespace is not significant in that
7f561c08de6b Initial load
duke
parents:
diff changeset
  1696
            // case.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1697
            if (m_elemContext.m_currentElemDepth <= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1698
                outputLineSep();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1699
7f561c08de6b Initial load
duke
parents:
diff changeset
  1700
            m_startNewLine = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1701
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1702
            catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1703
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1704
                throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1705
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1706
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1707
7f561c08de6b Initial load
duke
parents:
diff changeset
  1708
        // now generate the PI event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1709
        if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1710
            super.fireEscapingEvent(target, data);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1711
     }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1712
7f561c08de6b Initial load
duke
parents:
diff changeset
  1713
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1714
     * Receive notivication of a entityReference.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1715
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1716
     * @param name non-null reference to entity name string.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1717
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1718
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1719
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1720
    public final void entityReference(String name)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1721
        throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1722
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1723
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1724
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1725
7f561c08de6b Initial load
duke
parents:
diff changeset
  1726
        final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1727
        writer.write('&');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1728
        writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1729
        writer.write(';');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1730
7f561c08de6b Initial load
duke
parents:
diff changeset
  1731
        } catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1732
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1733
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1734
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1735
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1736
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1737
     * @see ExtendedContentHandler#endElement(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1738
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1739
    public final void endElement(String elemName) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1740
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1741
        endElement(null, null, elemName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1742
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1743
7f561c08de6b Initial load
duke
parents:
diff changeset
  1744
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1745
     * Process the attributes, which means to write out the currently
7f561c08de6b Initial load
duke
parents:
diff changeset
  1746
     * collected attributes to the writer. The attributes are not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1747
     * cleared by this method
7f561c08de6b Initial load
duke
parents:
diff changeset
  1748
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1749
     * @param writer the writer to write processed attributes to.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1750
     * @param nAttrs the number of attributes in m_attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
  1751
     * to be processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1752
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1753
     * @throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1754
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1755
    public void processAttributes(java.io.Writer writer, int nAttrs)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1756
        throws IOException,SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1757
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1758
            /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  1759
             * process the collected attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
  1760
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1761
            for (int i = 0; i < nAttrs; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1762
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1763
                processAttribute(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1764
                    writer,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1765
                    m_attributes.getQName(i),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1766
                    m_attributes.getValue(i),
7f561c08de6b Initial load
duke
parents:
diff changeset
  1767
                    m_elemContext.m_elementDesc);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1768
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1769
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1770
7f561c08de6b Initial load
duke
parents:
diff changeset
  1771
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1772
     * For the enclosing elements starting tag write out out any attributes
7f561c08de6b Initial load
duke
parents:
diff changeset
  1773
     * followed by ">"
7f561c08de6b Initial load
duke
parents:
diff changeset
  1774
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1775
     *@throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1776
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1777
    protected void closeStartTag() throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1778
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1779
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1780
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1781
7f561c08de6b Initial load
duke
parents:
diff changeset
  1782
            // finish processing attributes, time to fire off the start element event
7f561c08de6b Initial load
duke
parents:
diff changeset
  1783
            if (m_tracer != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1784
                super.fireStartElem(m_elemContext.m_elementName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1785
7f561c08de6b Initial load
duke
parents:
diff changeset
  1786
            int nAttrs = m_attributes.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1787
            if (nAttrs>0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1788
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1789
                processAttributes(m_writer, nAttrs);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1790
                // clear attributes object for re-use with next element
7f561c08de6b Initial load
duke
parents:
diff changeset
  1791
                m_attributes.clear();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1792
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1793
7f561c08de6b Initial load
duke
parents:
diff changeset
  1794
            m_writer.write('>');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1795
7f561c08de6b Initial load
duke
parents:
diff changeset
  1796
            /* whether Xalan or XSLTC, we have the prefix mappings now, so
7f561c08de6b Initial load
duke
parents:
diff changeset
  1797
             * lets determine if the current element is specified in the cdata-
7f561c08de6b Initial load
duke
parents:
diff changeset
  1798
             * section-elements list.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1799
             */
24888
2e493ac78624 8041523: Xerces Update: Serializer improvements from Xalan
joehw
parents: 23954
diff changeset
  1800
            if (m_StringOfCDATASections != null)
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1801
                m_elemContext.m_isCdataSection = isCdataSection();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1802
7f561c08de6b Initial load
duke
parents:
diff changeset
  1803
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1804
            catch(IOException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1805
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1806
                throw new SAXException(e);
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
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1811
         * This method is used when a prefix/uri namespace mapping
7f561c08de6b Initial load
duke
parents:
diff changeset
  1812
         * is indicated after the element was started with a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1813
         * startElement() and before and endElement().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1814
         * startPrefixMapping(prefix,uri) would be used before the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1815
         * startElement() call.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1816
         * @param uri the URI of the namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1817
         * @param prefix the prefix associated with the given URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1818
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1819
         * @see ExtendedContentHandler#namespaceAfterStartElement(String, String)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1820
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1821
        public void namespaceAfterStartElement(String prefix, String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1822
            throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1823
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1824
            // hack for XSLTC with finding URI for default namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1825
            if (m_elemContext.m_elementURI == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1826
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1827
                String prefix1 = getPrefixPart(m_elemContext.m_elementName);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1828
                if (prefix1 == null && EMPTYSTRING.equals(prefix))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1829
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1830
                    // the elements URI is not known yet, and it
7f561c08de6b Initial load
duke
parents:
diff changeset
  1831
                    // doesn't have a prefix, and we are currently
7f561c08de6b Initial load
duke
parents:
diff changeset
  1832
                    // setting the uri for prefix "", so we have
7f561c08de6b Initial load
duke
parents:
diff changeset
  1833
                    // the uri for the element... lets remember it
7f561c08de6b Initial load
duke
parents:
diff changeset
  1834
                    m_elemContext.m_elementURI = uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1835
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1836
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1837
            startPrefixMapping(prefix,uri,false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1838
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1839
7f561c08de6b Initial load
duke
parents:
diff changeset
  1840
    public void startDTD(String name, String publicId, String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1841
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1842
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1843
        m_inDTD = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1844
        super.startDTD(name, publicId, systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1845
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1846
7f561c08de6b Initial load
duke
parents:
diff changeset
  1847
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1848
     * Report the end of DTD declarations.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1849
     * @throws org.xml.sax.SAXException The application may raise an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1850
     * @see #startDTD
7f561c08de6b Initial load
duke
parents:
diff changeset
  1851
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1852
    public void endDTD() throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1853
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1854
        m_inDTD = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1855
        /* for ToHTMLStream the DOCTYPE is entirely output in the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1856
         * startDocumentInternal() method, so don't do anything here
7f561c08de6b Initial load
duke
parents:
diff changeset
  1857
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1858
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1859
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1860
     * This method does nothing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1861
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1862
    public void attributeDecl(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1863
        String eName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1864
        String aName,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1865
        String type,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1866
        String valueDefault,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1867
        String value)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1868
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1869
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1870
        // The internal DTD subset is not serialized by the ToHTMLStream serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  1871
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1872
7f561c08de6b Initial load
duke
parents:
diff changeset
  1873
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1874
     * This method does nothing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1875
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1876
    public void elementDecl(String name, String model) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1877
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1878
        // The internal DTD subset is not serialized by the ToHTMLStream serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  1879
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1880
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1881
     * This method does nothing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1882
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1883
    public void internalEntityDecl(String name, String value)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1884
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1885
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1886
        // The internal DTD subset is not serialized by the ToHTMLStream serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  1887
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1888
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1889
     * This method does nothing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1890
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1891
    public void externalEntityDecl(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1892
        String name,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1893
        String publicId,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1894
        String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1895
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1896
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1897
        // The internal DTD subset is not serialized by the ToHTMLStream serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  1898
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1899
7f561c08de6b Initial load
duke
parents:
diff changeset
  1900
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1901
     * This method is used to add an attribute to the currently open element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1902
     * The caller has guaranted that this attribute is unique, which means that it
7f561c08de6b Initial load
duke
parents:
diff changeset
  1903
     * not been seen before and will not be seen again.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1904
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1905
     * @param name the qualified name of the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
  1906
     * @param value the value of the attribute which can contain only
7f561c08de6b Initial load
duke
parents:
diff changeset
  1907
     * ASCII printable characters characters in the range 32 to 127 inclusive.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1908
     * @param flags the bit values of this integer give optimization information.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1909
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1910
    public void addUniqueAttribute(String name, String value, int flags)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1911
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1912
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1913
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1914
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1915
            final java.io.Writer writer = m_writer;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1916
            if ((flags & NO_BAD_CHARS) > 0 && m_htmlcharInfo.onlyQuotAmpLtGt)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1917
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1918
                // "flags" has indicated that the characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  1919
                // '>'  '<'   '&'  and '"' are not in the value and
7f561c08de6b Initial load
duke
parents:
diff changeset
  1920
                // m_htmlcharInfo has recorded that there are no other
7f561c08de6b Initial load
duke
parents:
diff changeset
  1921
                // entities in the range 0 to 127 so we write out the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1922
                // value directly
7f561c08de6b Initial load
duke
parents:
diff changeset
  1923
                writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1924
                writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1925
                writer.write("=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1926
                writer.write(value);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1927
                writer.write('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1928
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1929
            else if (
7f561c08de6b Initial load
duke
parents:
diff changeset
  1930
                (flags & HTML_ATTREMPTY) > 0
7f561c08de6b Initial load
duke
parents:
diff changeset
  1931
                    && (value.length() == 0 || value.equalsIgnoreCase(name)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1932
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1933
                writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1934
                writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1935
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1936
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1937
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1938
                writer.write(' ');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1939
                writer.write(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1940
                writer.write("=\"");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1941
                if ((flags & HTML_ATTRURL) > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1942
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1943
                    writeAttrURI(writer, value, m_specialEscapeURLs);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1944
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1945
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1946
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1947
                    writeAttrString(writer, value, this.getEncoding());
7f561c08de6b Initial load
duke
parents:
diff changeset
  1948
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1949
                writer.write('"');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1950
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1951
        } catch (IOException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1952
            throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1953
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1954
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1955
7f561c08de6b Initial load
duke
parents:
diff changeset
  1956
    public void comment(char ch[], int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1957
            throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1958
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1959
        // The internal DTD subset is not serialized by the ToHTMLStream serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
  1960
        if (m_inDTD)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1961
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1962
        super.comment(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1963
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1964
7f561c08de6b Initial load
duke
parents:
diff changeset
  1965
    public boolean reset()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1966
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1967
        boolean ret = super.reset();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1968
        if (!ret)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1969
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1970
        initToHTMLStream();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1971
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1972
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1973
7f561c08de6b Initial load
duke
parents:
diff changeset
  1974
    private void initToHTMLStream()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1975
    {
42805
857b5e6eef37 8087303: LSSerializer pretty print does not work anymore
fyuan
parents: 25868
diff changeset
  1976
        m_isprevblock = false;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
  1977
        m_inDTD = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1978
        m_omitMetaTag = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1979
        m_specialEscapeURLs = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1980
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1981
7f561c08de6b Initial load
duke
parents:
diff changeset
  1982
    static class Trie
7f561c08de6b Initial load
duke
parents:
diff changeset
  1983
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1984
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1985
         * A digital search trie for 7-bit ASCII text
7f561c08de6b Initial load
duke
parents:
diff changeset
  1986
         * The API is a subset of java.util.Hashtable
7f561c08de6b Initial load
duke
parents:
diff changeset
  1987
         * The key must be a 7-bit ASCII string
7f561c08de6b Initial load
duke
parents:
diff changeset
  1988
         * The value may be any Java Object
7f561c08de6b Initial load
duke
parents:
diff changeset
  1989
         * One can get an object stored in a trie from its key,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1990
         * but the search is either case sensitive or case
7f561c08de6b Initial load
duke
parents:
diff changeset
  1991
         * insensitive to the characters in the key, and this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1992
         * choice of sensitivity or insensitivity is made when
7f561c08de6b Initial load
duke
parents:
diff changeset
  1993
         * the Trie is created, before any objects are put in it.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1994
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1995
         * This class is a copy of the one in com.sun.org.apache.xml.internal.utils.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1996
         * It exists to cut the serializers dependancy on that package.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1997
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1998
         * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
  1999
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2000
7f561c08de6b Initial load
duke
parents:
diff changeset
  2001
        /** Size of the m_nextChar array.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2002
        public static final int ALPHA_SIZE = 128;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2003
7f561c08de6b Initial load
duke
parents:
diff changeset
  2004
        /** The root node of the tree.    */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2005
        final Node m_Root;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2006
7f561c08de6b Initial load
duke
parents:
diff changeset
  2007
        /** helper buffer to convert Strings to char arrays */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2008
        private char[] m_charBuffer = new char[0];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2009
7f561c08de6b Initial load
duke
parents:
diff changeset
  2010
        /** true if the search for an object is lower case only with the key */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2011
        private final boolean m_lowerCaseOnly;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2012
7f561c08de6b Initial load
duke
parents:
diff changeset
  2013
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2014
         * Construct the trie that has a case insensitive search.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2015
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2016
        public Trie()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2017
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2018
            m_Root = new Node();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2019
            m_lowerCaseOnly = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2020
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2021
7f561c08de6b Initial load
duke
parents:
diff changeset
  2022
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2023
         * Construct the trie given the desired case sensitivity with the key.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2024
         * @param lowerCaseOnly true if the search keys are to be loser case only,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2025
         * not case insensitive.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2026
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2027
        public Trie(boolean lowerCaseOnly)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2028
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2029
            m_Root = new Node();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2030
            m_lowerCaseOnly = lowerCaseOnly;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2031
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2032
7f561c08de6b Initial load
duke
parents:
diff changeset
  2033
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2034
         * Put an object into the trie for lookup.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2035
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2036
         * @param key must be a 7-bit ASCII string
7f561c08de6b Initial load
duke
parents:
diff changeset
  2037
         * @param value any java object.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2038
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2039
         * @return The old object that matched key, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2040
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2041
        public Object put(String key, Object value)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2042
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2043
7f561c08de6b Initial load
duke
parents:
diff changeset
  2044
            final int len = key.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2045
            if (len > m_charBuffer.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2046
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2047
                // make the biggest buffer ever needed in get(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2048
                m_charBuffer = new char[len];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2049
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2050
7f561c08de6b Initial load
duke
parents:
diff changeset
  2051
            Node node = m_Root;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2052
7f561c08de6b Initial load
duke
parents:
diff changeset
  2053
            for (int i = 0; i < len; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2054
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2055
                Node nextNode =
7f561c08de6b Initial load
duke
parents:
diff changeset
  2056
                    node.m_nextChar[Character.toLowerCase(key.charAt(i))];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2057
7f561c08de6b Initial load
duke
parents:
diff changeset
  2058
                if (nextNode != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2059
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2060
                    node = nextNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2061
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2062
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2063
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2064
                    for (; i < len; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2065
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2066
                        Node newNode = new Node();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2067
                        if (m_lowerCaseOnly)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2068
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2069
                            // put this value into the tree only with a lower case key
7f561c08de6b Initial load
duke
parents:
diff changeset
  2070
                            node.m_nextChar[Character.toLowerCase(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2071
                                key.charAt(i))] =
7f561c08de6b Initial load
duke
parents:
diff changeset
  2072
                                newNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2073
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2074
                        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2075
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2076
                            // put this value into the tree with a case insensitive key
7f561c08de6b Initial load
duke
parents:
diff changeset
  2077
                            node.m_nextChar[Character.toUpperCase(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2078
                                key.charAt(i))] =
7f561c08de6b Initial load
duke
parents:
diff changeset
  2079
                                newNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2080
                            node.m_nextChar[Character.toLowerCase(
7f561c08de6b Initial load
duke
parents:
diff changeset
  2081
                                key.charAt(i))] =
7f561c08de6b Initial load
duke
parents:
diff changeset
  2082
                                newNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2083
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2084
                        node = newNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2085
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2086
                    break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2087
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2088
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2089
7f561c08de6b Initial load
duke
parents:
diff changeset
  2090
            Object ret = node.m_Value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2091
7f561c08de6b Initial load
duke
parents:
diff changeset
  2092
            node.m_Value = value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2093
7f561c08de6b Initial load
duke
parents:
diff changeset
  2094
            return ret;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2095
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2096
7f561c08de6b Initial load
duke
parents:
diff changeset
  2097
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2098
         * Get an object that matches the key.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2099
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2100
         * @param key must be a 7-bit ASCII string
7f561c08de6b Initial load
duke
parents:
diff changeset
  2101
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2102
         * @return The object that matches the key, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2103
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2104
        public Object get(final String key)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2105
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2106
7f561c08de6b Initial load
duke
parents:
diff changeset
  2107
            final int len = key.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2108
7f561c08de6b Initial load
duke
parents:
diff changeset
  2109
            /* If the name is too long, we won't find it, this also keeps us
7f561c08de6b Initial load
duke
parents:
diff changeset
  2110
             * from overflowing m_charBuffer
7f561c08de6b Initial load
duke
parents:
diff changeset
  2111
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2112
            if (m_charBuffer.length < len)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2113
                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2114
7f561c08de6b Initial load
duke
parents:
diff changeset
  2115
            Node node = m_Root;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2116
            switch (len) // optimize the look up based on the number of chars
7f561c08de6b Initial load
duke
parents:
diff changeset
  2117
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2118
                // case 0 looks silly, but the generated bytecode runs
7f561c08de6b Initial load
duke
parents:
diff changeset
  2119
                // faster for lookup of elements of length 2 with this in
7f561c08de6b Initial load
duke
parents:
diff changeset
  2120
                // and a fair bit faster.  Don't know why.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2121
                case 0 :
7f561c08de6b Initial load
duke
parents:
diff changeset
  2122
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2123
                        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2124
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2125
7f561c08de6b Initial load
duke
parents:
diff changeset
  2126
                case 1 :
7f561c08de6b Initial load
duke
parents:
diff changeset
  2127
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2128
                        final char ch = key.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2129
                        if (ch < ALPHA_SIZE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2130
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2131
                            node = node.m_nextChar[ch];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2132
                            if (node != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2133
                                return node.m_Value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2134
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2135
                        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2136
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2137
                    //                comment out case 2 because the default is faster
7f561c08de6b Initial load
duke
parents:
diff changeset
  2138
                    //                case 2 :
7f561c08de6b Initial load
duke
parents:
diff changeset
  2139
                    //                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2140
                    //                        final char ch0 = key.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2141
                    //                        final char ch1 = key.charAt(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2142
                    //                        if (ch0 < ALPHA_SIZE && ch1 < ALPHA_SIZE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2143
                    //                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2144
                    //                            node = node.m_nextChar[ch0];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2145
                    //                            if (node != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2146
                    //                            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2147
                    //
7f561c08de6b Initial load
duke
parents:
diff changeset
  2148
                    //                                if (ch1 < ALPHA_SIZE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2149
                    //                                {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2150
                    //                                    node = node.m_nextChar[ch1];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2151
                    //                                    if (node != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2152
                    //                                        return node.m_Value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2153
                    //                                }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2154
                    //                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2155
                    //                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2156
                    //                        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2157
                    //                   }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2158
                default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  2159
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2160
                        for (int i = 0; i < len; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2161
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2162
                            // A thread-safe way to loop over the characters
7f561c08de6b Initial load
duke
parents:
diff changeset
  2163
                            final char ch = key.charAt(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2164
                            if (ALPHA_SIZE <= ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2165
                            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2166
                                // the key is not 7-bit ASCII so we won't find it here
7f561c08de6b Initial load
duke
parents:
diff changeset
  2167
                                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2168
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2169
7f561c08de6b Initial load
duke
parents:
diff changeset
  2170
                            node = node.m_nextChar[ch];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2171
                            if (node == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2172
                                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2173
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2174
7f561c08de6b Initial load
duke
parents:
diff changeset
  2175
                        return node.m_Value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2176
                    }
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
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2181
         * The node representation for the trie.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2182
         * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
  2183
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2184
        private class Node
7f561c08de6b Initial load
duke
parents:
diff changeset
  2185
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2186
7f561c08de6b Initial load
duke
parents:
diff changeset
  2187
            /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2188
             * Constructor, creates a Node[ALPHA_SIZE].
7f561c08de6b Initial load
duke
parents:
diff changeset
  2189
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2190
            Node()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2191
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2192
                m_nextChar = new Node[ALPHA_SIZE];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2193
                m_Value = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2194
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2195
7f561c08de6b Initial load
duke
parents:
diff changeset
  2196
            /** The next nodes.   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2197
            final Node m_nextChar[];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2198
7f561c08de6b Initial load
duke
parents:
diff changeset
  2199
            /** The value.   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2200
            Object m_Value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2201
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2202
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2203
         * Construct the trie from another Trie.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2204
         * Both the existing Trie and this new one share the same table for
7f561c08de6b Initial load
duke
parents:
diff changeset
  2205
         * lookup, and it is assumed that the table is fully populated and
7f561c08de6b Initial load
duke
parents:
diff changeset
  2206
         * not changing anymore.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2207
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2208
         * @param existingTrie the Trie that this one is a copy of.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2209
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2210
        public Trie(Trie existingTrie)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2211
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2212
            // copy some fields from the existing Trie into this one.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2213
            m_Root = existingTrie.m_Root;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2214
            m_lowerCaseOnly = existingTrie.m_lowerCaseOnly;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2215
7f561c08de6b Initial load
duke
parents:
diff changeset
  2216
            // get a buffer just big enough to hold the longest key in the table.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2217
            int max = existingTrie.getLongestKeyLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2218
            m_charBuffer = new char[max];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2219
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2220
7f561c08de6b Initial load
duke
parents:
diff changeset
  2221
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2222
         * Get an object that matches the key.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2223
         * This method is faster than get(), but is not thread-safe.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2224
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2225
         * @param key must be a 7-bit ASCII string
7f561c08de6b Initial load
duke
parents:
diff changeset
  2226
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2227
         * @return The object that matches the key, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2228
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2229
        public Object get2(final String key)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2230
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2231
7f561c08de6b Initial load
duke
parents:
diff changeset
  2232
            final int len = key.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2233
7f561c08de6b Initial load
duke
parents:
diff changeset
  2234
            /* If the name is too long, we won't find it, this also keeps us
7f561c08de6b Initial load
duke
parents:
diff changeset
  2235
             * from overflowing m_charBuffer
7f561c08de6b Initial load
duke
parents:
diff changeset
  2236
             */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2237
            if (m_charBuffer.length < len)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2238
                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2239
7f561c08de6b Initial load
duke
parents:
diff changeset
  2240
            Node node = m_Root;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2241
            switch (len) // optimize the look up based on the number of chars
7f561c08de6b Initial load
duke
parents:
diff changeset
  2242
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2243
                // case 0 looks silly, but the generated bytecode runs
7f561c08de6b Initial load
duke
parents:
diff changeset
  2244
                // faster for lookup of elements of length 2 with this in
7f561c08de6b Initial load
duke
parents:
diff changeset
  2245
                // and a fair bit faster.  Don't know why.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2246
                case 0 :
7f561c08de6b Initial load
duke
parents:
diff changeset
  2247
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2248
                        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2249
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2250
7f561c08de6b Initial load
duke
parents:
diff changeset
  2251
                case 1 :
7f561c08de6b Initial load
duke
parents:
diff changeset
  2252
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2253
                        final char ch = key.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2254
                        if (ch < ALPHA_SIZE)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2255
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2256
                            node = node.m_nextChar[ch];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2257
                            if (node != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2258
                                return node.m_Value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2259
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2260
                        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2261
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2262
                default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  2263
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2264
                        /* Copy string into array. This is not thread-safe because
7f561c08de6b Initial load
duke
parents:
diff changeset
  2265
                         * it modifies the contents of m_charBuffer. If multiple
7f561c08de6b Initial load
duke
parents:
diff changeset
  2266
                         * threads were to use this Trie they all would be
7f561c08de6b Initial load
duke
parents:
diff changeset
  2267
                         * using this same array (not good). So this
7f561c08de6b Initial load
duke
parents:
diff changeset
  2268
                         * method is not thread-safe, but it is faster because
7f561c08de6b Initial load
duke
parents:
diff changeset
  2269
                         * converting to a char[] and looping over elements of
7f561c08de6b Initial load
duke
parents:
diff changeset
  2270
                         * the array is faster than a String's charAt(i).
7f561c08de6b Initial load
duke
parents:
diff changeset
  2271
                         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2272
                        key.getChars(0, len, m_charBuffer, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2273
7f561c08de6b Initial load
duke
parents:
diff changeset
  2274
                        for (int i = 0; i < len; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2275
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2276
                            final char ch = m_charBuffer[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2277
                            if (ALPHA_SIZE <= ch)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2278
                            {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2279
                                // the key is not 7-bit ASCII so we won't find it here
7f561c08de6b Initial load
duke
parents:
diff changeset
  2280
                                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2281
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2282
7f561c08de6b Initial load
duke
parents:
diff changeset
  2283
                            node = node.m_nextChar[ch];
7f561c08de6b Initial load
duke
parents:
diff changeset
  2284
                            if (node == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2285
                                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2286
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2287
7f561c08de6b Initial load
duke
parents:
diff changeset
  2288
                        return node.m_Value;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2289
                    }
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
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2294
         * Get the length of the longest key used in the table.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2295
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2296
        public int getLongestKeyLength()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2297
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2298
            return m_charBuffer.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2299
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2300
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2301
}