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