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