blob: f4a5cb9a73cf92277690b62dd6dd33c6047997b4 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2001 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package javax.swing.text.html.parser;
27
28import java.util.Hashtable;
29import java.io.IOException;
30import java.io.InputStream;
31import java.io.InputStreamReader;
32import java.io.Reader;
33import java.io.CharArrayReader;
34import java.net.URL;
35
36/**
37 * An entity is described in a DTD using the ENTITY construct.
38 * It defines the type and value of the the entity.
39 *
40 * @see DTD
41 * @author Arthur van Hoff
42 */
43public final
44class Entity implements DTDConstants {
45 public String name;
46 public int type;
47 public char data[];
48
49 /**
50 * Creates an entity.
51 * @param name the name of the entity
52 * @param type the type of the entity
53 * @param data the char array of data
54 */
55 public Entity(String name, int type, char data[]) {
56 this.name = name;
57 this.type = type;
58 this.data = data;
59 }
60
61 /**
62 * Gets the name of the entity.
63 * @return the name of the entity, as a <code>String</code>
64 */
65 public String getName() {
66 return name;
67 }
68
69 /**
70 * Gets the type of the entity.
71 * @return the type of the entity
72 */
73 public int getType() {
74 return type & 0xFFFF;
75 }
76
77 /**
78 * Returns <code>true</code> if it is a parameter entity.
79 * @return <code>true</code> if it is a parameter entity
80 */
81 public boolean isParameter() {
82 return (type & PARAMETER) != 0;
83 }
84
85 /**
86 * Returns <code>true</code> if it is a general entity.
87 * @return <code>true</code> if it is a general entity
88 */
89 public boolean isGeneral() {
90 return (type & GENERAL) != 0;
91 }
92
93 /**
94 * Returns the <code>data</code>.
95 * @return the <code>data</code>
96 */
97 public char getData()[] {
98 return data;
99 }
100
101 /**
102 * Returns the data as a <code>String</code>.
103 * @return the data as a <code>String</code>
104 */
105 public String getString() {
106 return new String(data, 0, data.length);
107 }
108
109
110 static Hashtable entityTypes = new Hashtable();
111
112 static {
113 entityTypes.put("PUBLIC", new Integer(PUBLIC));
114 entityTypes.put("CDATA", new Integer(CDATA));
115 entityTypes.put("SDATA", new Integer(SDATA));
116 entityTypes.put("PI", new Integer(PI));
117 entityTypes.put("STARTTAG", new Integer(STARTTAG));
118 entityTypes.put("ENDTAG", new Integer(ENDTAG));
119 entityTypes.put("MS", new Integer(MS));
120 entityTypes.put("MD", new Integer(MD));
121 entityTypes.put("SYSTEM", new Integer(SYSTEM));
122 }
123
124 /**
125 * Converts <code>nm</code> string to the corresponding
126 * entity type. If the string does not have a corresponding
127 * entity type, returns the type corresponding to "CDATA".
128 * Valid entity types are: "PUBLIC", "CDATA", "SDATA", "PI",
129 * "STARTTAG", "ENDTAG", "MS", "MD", "SYSTEM".
130 *
131 * @param nm the string to be converted
132 * @return the corresponding entity type, or the type corresponding
133 * to "CDATA", if none exists
134 */
135 public static int name2type(String nm) {
136 Integer i = (Integer)entityTypes.get(nm);
137 return (i == null) ? CDATA : i.intValue();
138 }
139}