jdk/src/share/classes/javax/swing/text/html/parser/DTD.java
author ddehaven
Mon, 23 Jun 2014 13:05:27 -0700
changeset 25208 f7fd86906713
parent 25193 187a455af8f8
parent 25147 fd9451d440ff
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.text.html.parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
6862
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
    28
import sun.awt.AppContext;
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.BufferedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.DataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.BitSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The representation of an SGML DTD.  DTD describes a document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * syntax and is used in parsing of HTML documents.  It contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * a list of elements and their attributes as well as a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * entities defined in the DTD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see AttributeList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see ContentModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see Parser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
class DTD implements DTDConstants {
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    60
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    61
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    62
     * the name of the DTD
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    63
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public String name;
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    65
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    66
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    67
     * The vector of elements
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    68
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public Vector<Element> elements = new Vector<Element>();
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    70
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    71
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    72
     * The hash table contains the name of element and
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    73
     * the corresponding element.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    74
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public Hashtable<String,Element> elementHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        = new Hashtable<String,Element>();
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    77
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    78
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    79
     * The hash table contains an {@code Object} and the corresponding {@code Entity}
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    80
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public Hashtable<Object,Entity> entityHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        = new Hashtable<Object,Entity>();
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    83
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    84
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    85
     * The element corresponding to pcdata.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    86
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public final Element pcdata = getElement("#pcdata");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    88
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    89
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    90
     * The element corresponding to html.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    91
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public final Element html = getElement("html");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    93
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    94
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    95
     * The element corresponding to meta.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    96
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public final Element meta = getElement("meta");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    98
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
    99
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   100
     * The element corresponding to base.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   101
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public final Element base = getElement("base");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   103
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   104
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   105
     * The element corresponding to isindex.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   106
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public final Element isindex = getElement("isindex");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   108
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   109
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   110
     * The element corresponding to head.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   111
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public final Element head = getElement("head");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   113
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   114
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   115
     * The element corresponding to body.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   116
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public final Element body = getElement("body");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   118
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   119
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   120
     * The element corresponding to applet.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   121
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public final Element applet = getElement("applet");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   123
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   124
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   125
     * The element corresponding to param.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   126
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public final Element param = getElement("param");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   128
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   129
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   130
     * The element corresponding to p.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   131
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public final Element p = getElement("p");
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   133
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   134
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   135
     * The element corresponding to title.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   136
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public final Element title = getElement("title");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    final Element style = getElement("style");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    final Element link = getElement("link");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    final Element script = getElement("script");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   142
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   143
     * The version of a file
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   144
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static final int FILE_VERSION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Creates a new DTD with the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param name the name, as a <code>String</code> of the new DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    protected DTD(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        defEntity("#RE", GENERAL, '\r');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        defEntity("#RS", GENERAL, '\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        defEntity("#SPACE", GENERAL, ' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        defineElement("unknown", EMPTY, false, true, null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Gets the name of the DTD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @return the name of the DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Gets an entity by name.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   169
     * @param name  the entity name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return the <code>Entity</code> corresponding to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *   <code>name</code> <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public Entity getEntity(String name) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   174
        return entityHash.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Gets a character entity.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   179
     * @param ch  the character
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return the <code>Entity</code> corresponding to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *    <code>ch</code> character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public Entity getEntity(int ch) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   184
        return entityHash.get(Integer.valueOf(ch));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Returns <code>true</code> if the element is part of the DTD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * otherwise returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param  name the requested <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return <code>true</code> if <code>name</code> exists as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *   part of the DTD, otherwise returns <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    boolean elementExists(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return !"unknown".equals(name) && (elementHash.get(name) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Gets an element by name. A new element is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * created if the element doesn't exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param name the requested <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return the <code>Element</code> corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *   <code>name</code>, which may be newly created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public Element getElement(String name) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   208
        Element e = elementHash.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            e = new Element(name, elements.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            elements.addElement(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            elementHash.put(name, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Gets an element by index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param index the requested index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return the <code>Element</code> corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *   <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public Element getElement(int index) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   225
        return elements.elementAt(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Defines an entity.  If the <code>Entity</code> specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * by <code>name</code>, <code>type</code>, and <code>data</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * exists, it is returned; otherwise a new <code>Entity</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * is created and is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param name the name of the <code>Entity</code> as a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param type the type of the <code>Entity</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param data the <code>Entity</code>'s data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return the <code>Entity</code> requested or a new <code>Entity</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *   if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public Entity defineEntity(String name, int type, char data[]) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   241
        Entity ent = entityHash.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (ent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            ent = new Entity(name, type, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            entityHash.put(name, ent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (((type & GENERAL) != 0) && (data.length == 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                switch (type & ~GENERAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                  case CDATA:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                  case SDATA:
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   249
                      entityHash.put(Integer.valueOf(data[0]), ent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return ent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Returns the <code>Element</code> which matches the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * specified parameters.  If one doesn't exist, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * one is created and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   262
     * @param name        the name of the <code>Element</code>
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   263
     * @param type        the type of the <code>Element</code>
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   264
     * @param omitStart   <code>true</code> if start should be omitted
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   265
     * @param omitEnd     <code>true</code> if end should be omitted
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   266
     * @param content     the <code>ContentModel</code>
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   267
     * @param exclusions  the set of elements that must not occur inside the element
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   268
     * @param inclusions  the set of elements that can occur inside the element
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   269
     * @param atts        the <code>AttributeList</code> specifying the
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   270
     *                    <code>Element</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return the <code>Element</code> specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public Element defineElement(String name, int type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                       boolean omitStart, boolean omitEnd, ContentModel content,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                       BitSet exclusions, BitSet inclusions, AttributeList atts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        Element e = getElement(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        e.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        e.oStart = omitStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        e.oEnd = omitEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        e.content = content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        e.exclusions = exclusions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        e.inclusions = inclusions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        e.atts = atts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Defines attributes for an {@code Element}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param name the name of the <code>Element</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param atts the <code>AttributeList</code> specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *    <code>Element</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public void defineAttributes(String name, AttributeList atts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        Element e = getElement(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        e.atts = atts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Creates and returns a character <code>Entity</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param name the entity's name
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   302
     * @param type the entity's type
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   303
     * @param ch   the entity's value (character)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @return the new character <code>Entity</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public Entity defEntity(String name, int type, int ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        char data[] = {(char)ch};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return defineEntity(name, type, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Creates and returns an <code>Entity</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param name the entity's name
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   314
     * @param type the entity's type
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   315
     * @param str  the entity's data section
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @return the new <code>Entity</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    protected Entity defEntity(String name, int type, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int len = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        char data[] = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        str.getChars(0, len, data, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return defineEntity(name, type, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Creates and returns an <code>Element</code>.
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   327
     * @param name        the element's name
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   328
     * @param type        the element's type
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   329
     * @param omitStart   {@code true} if the element needs no starting tag
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   330
     * @param omitEnd     {@code true} if the element needs no closing tag
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   331
     * @param content     the element's content
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   332
     * @param exclusions  the elements that must be excluded from the content of the element
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   333
     * @param inclusions  the elements that can be included as the content of the element
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   334
     * @param atts        the attributes of the element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @return the new <code>Element</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    protected Element defElement(String name, int type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                       boolean omitStart, boolean omitEnd, ContentModel content,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                       String[] exclusions, String[] inclusions, AttributeList atts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        BitSet excl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (exclusions != null && exclusions.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            excl = new BitSet();
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   343
            for (String str : exclusions) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                if (str.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    excl.set(getElement(str).getIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        BitSet incl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (inclusions != null && inclusions.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            incl = new BitSet();
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   352
            for (String str : inclusions) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                if (str.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    incl.set(getElement(str).getIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return defineElement(name, type, omitStart, omitEnd, content, excl, incl, atts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   362
     * Creates and returns an <code>AttributeList</code> responding to a new attribute.
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   363
     * @param name      the attribute's name
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   364
     * @param type      the attribute's type
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   365
     * @param modifier  the attribute's modifier
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   366
     * @param value     the default value of the attribute
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   367
     * @param values    the allowed values for the attribute (multiple values could be separated by '|')
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   368
     * @param atts      the previous attribute of the element; to be placed to {@code AttributeList.next},
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   369
     *                  creating a linked list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @return the new <code>AttributeList</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   372
    protected AttributeList defAttributeList(String name, int type, int modifier,
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   373
                                             String value, String values, AttributeList atts) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   374
        Vector<String> vals = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (values != null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   376
            vals = new Vector<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            for (StringTokenizer s = new StringTokenizer(values, "|") ; s.hasMoreTokens() ;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                String str = s.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                if (str.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    vals.addElement(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return new AttributeList(name, type, modifier, value, vals, atts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Creates and returns a new content model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @param type the type of the new content model
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   390
     * @param obj  the content of the content model
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   391
     * @param next pointer to the next content model
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @return the new <code>ContentModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    protected ContentModel defContentModel(int type, Object obj, ContentModel next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return new ContentModel(type, obj, next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Returns a string representation of this DTD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @return the string representation of this DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
6862
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   407
     * The hashtable key of DTDs in AppContext.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     */
6862
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   409
    private static final Object DTD_HASH_KEY = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   411
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   412
     * Put a name and appropriate DTD to hashtable.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   413
     *
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   414
     * @param name the name of the DTD
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   415
     * @param dtd the DTD
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 24494
diff changeset
   416
     */
6862
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   417
    public static void putDTDHash(String name, DTD dtd) {
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   418
        getDtdHash().put(name, dtd);
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   419
    }
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   420
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Returns a DTD with the specified <code>name</code>.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * a DTD with that name doesn't exist, one is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * and returned.  Any uppercase characters in the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * are converted to lowercase.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param name the name of the DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @return the DTD which corresponds to <code>name</code>
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   429
     * @throws IOException if an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public static DTD getDTD(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        name = name.toLowerCase();
6862
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   433
        DTD dtd = getDtdHash().get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (dtd == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
          dtd = new DTD(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return dtd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
6862
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   440
    private static Hashtable<String, DTD> getDtdHash() {
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   441
        AppContext appContext = AppContext.getAppContext();
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   442
25193
187a455af8f8 8043549: Fix raw and unchecked lint warnings in javax.swing.text.*
darcy
parents: 24494
diff changeset
   443
        @SuppressWarnings("unchecked")
6862
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   444
        Hashtable<String, DTD> result = (Hashtable<String, DTD>) appContext.get(DTD_HASH_KEY);
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   445
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   446
        if (result == null) {
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   447
            result = new Hashtable<String, DTD>();
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   448
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   449
            appContext.put(DTD_HASH_KEY, result);
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   450
        }
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   451
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   452
        return result;
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   453
    }
f66eb6b6a6b9 6938813: Swing mutable statics
rupashka
parents: 5506
diff changeset
   454
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Recreates a DTD from an archived format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @param in  the <code>DataInputStream</code> to read from
24494
67129b9360d2 8042120: Fix doclint warnings from javax.swing.text.html.parser
yan
parents: 6862
diff changeset
   458
     * @throws IOException if an I/O error occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public void read(DataInputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (in.readInt() != FILE_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        // Read the list of names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        String[] names = new String[in.readShort()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        for (int i = 0; i < names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            names[i] = in.readUTF();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // Read the entities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        int num = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            short nameId = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            int type = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            String name = in.readUTF();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            defEntity(names[nameId], type | GENERAL, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        // Read the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        num = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            short nameId = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            int type = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            byte flags = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            ContentModel m = readContentModel(in, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            String[] exclusions = readNameArray(in, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            String[] inclusions = readNameArray(in, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            AttributeList atts = readAttributeList(in, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            defElement(names[nameId], type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                       ((flags & 0x01) != 0), ((flags & 0x02) != 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                       m, exclusions, inclusions, atts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    private ContentModel readContentModel(DataInputStream in, String[] names)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        byte flag = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        switch(flag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            case 0:             // null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            case 1: {           // content_c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                int type = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                ContentModel m = readContentModel(in, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                ContentModel next = readContentModel(in, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                return defContentModel(type, m, next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            case 2: {           // content_e
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                int type = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                Element el = getElement(names[in.readShort()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                ContentModel next = readContentModel(in, names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                return defContentModel(type, el, next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                throw new IOException("bad bdtd");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    private String[] readNameArray(DataInputStream in, String[] names)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        int num = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (num == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        String[] result = new String[num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            result[i] = names[in.readShort()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    private AttributeList readAttributeList(DataInputStream in, String[] names)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                throws IOException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        AttributeList result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        for (int num = in.readByte(); num > 0; --num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            short nameId = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            int type = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            int modifier = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            short valueId = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            String value = (valueId == -1) ? null : names[valueId];
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   547
            Vector<String> values = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            short numValues = in.readShort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            if (numValues > 0) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   550
                values = new Vector<String>(numValues);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                for (int i = 0; i < numValues; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    values.addElement(names[in.readShort()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
result = new AttributeList(names[nameId], type, modifier, value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                       values, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            // We reverse the order of the linked list by doing this, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            // that order isn't important.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
}