jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Entity.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     2
 * Copyright (c) 1998, 2008, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.CharArrayReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * An entity is described in a DTD using the ENTITY construct.
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
    38
 * It defines the type and value of the entity.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see DTD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class Entity implements DTDConstants {
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    45
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    46
     * The name of the entity.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    47
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public String name;
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    49
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    50
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    51
     * The type of the entity.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    52
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public int type;
25147
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    54
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    55
    /**
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    56
     * The char array of data.
fd9451d440ff 8046895: Fix doclint warnings in javax.swing.text.html.parser package
yan
parents: 5506
diff changeset
    57
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public char data[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Creates an entity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param name the name of the entity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param type the type of the entity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param data the char array of data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public Entity(String name, int type, char data[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.data = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Gets the name of the entity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return the name of the entity, as a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Gets the type of the entity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @return the type of the entity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return type & 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Returns <code>true</code> if it is a parameter entity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @return <code>true</code> if it is a parameter entity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public boolean isParameter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return (type & PARAMETER) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Returns <code>true</code> if it is a general entity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return <code>true</code> if it is a general entity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public boolean isGeneral() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return (type & GENERAL) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Returns the <code>data</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @return the <code>data</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public char getData()[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Returns the data as a <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return the data as a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public String getString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return new String(data, 0, data.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   121
    static Hashtable<String, Integer> entityTypes = new Hashtable<String, Integer>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    static {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   124
        entityTypes.put("PUBLIC", Integer.valueOf(PUBLIC));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   125
        entityTypes.put("CDATA", Integer.valueOf(CDATA));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   126
        entityTypes.put("SDATA", Integer.valueOf(SDATA));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   127
        entityTypes.put("PI", Integer.valueOf(PI));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   128
        entityTypes.put("STARTTAG", Integer.valueOf(STARTTAG));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   129
        entityTypes.put("ENDTAG", Integer.valueOf(ENDTAG));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   130
        entityTypes.put("MS", Integer.valueOf(MS));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   131
        entityTypes.put("MD", Integer.valueOf(MD));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   132
        entityTypes.put("SYSTEM", Integer.valueOf(SYSTEM));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Converts <code>nm</code> string to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * entity type.  If the string does not have a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * entity type, returns the type corresponding to "CDATA".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Valid entity types are: "PUBLIC", "CDATA", "SDATA", "PI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * "STARTTAG", "ENDTAG", "MS", "MD", "SYSTEM".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param nm the string to be converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return the corresponding entity type, or the type corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *   to "CDATA", if none exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static int name2type(String nm) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   147
        Integer i = entityTypes.get(nm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return (i == null) ? CDATA : i.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}