author | martin |
Thu, 30 Oct 2014 07:31:41 -0700 | |
changeset 28059 | e576535359cc |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.text.html.parser; |
|
27 |
||
28 |
import java.util.Hashtable; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.InputStream; |
|
31 |
import java.io.InputStreamReader; |
|
32 |
import java.io.Reader; |
|
33 |
import java.io.CharArrayReader; |
|
34 |
import java.net.URL; |
|
35 |
||
36 |
/** |
|
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 | 39 |
* |
40 |
* @see DTD |
|
41 |
* @author Arthur van Hoff |
|
42 |
*/ |
|
43 |
public final |
|
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 | 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 | 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 | 58 |
public char data[]; |
59 |
||
60 |
/** |
|
61 |
* Creates an entity. |
|
62 |
* @param name the name of the entity |
|
63 |
* @param type the type of the entity |
|
64 |
* @param data the char array of data |
|
65 |
*/ |
|
66 |
public Entity(String name, int type, char data[]) { |
|
67 |
this.name = name; |
|
68 |
this.type = type; |
|
69 |
this.data = data; |
|
70 |
} |
|
71 |
||
72 |
/** |
|
73 |
* Gets the name of the entity. |
|
74 |
* @return the name of the entity, as a <code>String</code> |
|
75 |
*/ |
|
76 |
public String getName() { |
|
77 |
return name; |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Gets the type of the entity. |
|
82 |
* @return the type of the entity |
|
83 |
*/ |
|
84 |
public int getType() { |
|
85 |
return type & 0xFFFF; |
|
86 |
} |
|
87 |
||
88 |
/** |
|
89 |
* Returns <code>true</code> if it is a parameter entity. |
|
90 |
* @return <code>true</code> if it is a parameter entity |
|
91 |
*/ |
|
92 |
public boolean isParameter() { |
|
93 |
return (type & PARAMETER) != 0; |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Returns <code>true</code> if it is a general entity. |
|
98 |
* @return <code>true</code> if it is a general entity |
|
99 |
*/ |
|
100 |
public boolean isGeneral() { |
|
101 |
return (type & GENERAL) != 0; |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Returns the <code>data</code>. |
|
106 |
* @return the <code>data</code> |
|
107 |
*/ |
|
108 |
public char getData()[] { |
|
109 |
return data; |
|
110 |
} |
|
111 |
||
112 |
/** |
|
113 |
* Returns the data as a <code>String</code>. |
|
114 |
* @return the data as a <code>String</code> |
|
115 |
*/ |
|
116 |
public String getString() { |
|
117 |
return new String(data, 0, data.length); |
|
118 |
} |
|
119 |
||
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 | 122 |
|
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 | 133 |
} |
134 |
||
135 |
/** |
|
136 |
* Converts <code>nm</code> string to the corresponding |
|
137 |
* entity type. If the string does not have a corresponding |
|
138 |
* entity type, returns the type corresponding to "CDATA". |
|
139 |
* Valid entity types are: "PUBLIC", "CDATA", "SDATA", "PI", |
|
140 |
* "STARTTAG", "ENDTAG", "MS", "MD", "SYSTEM". |
|
141 |
* |
|
142 |
* @param nm the string to be converted |
|
143 |
* @return the corresponding entity type, or the type corresponding |
|
144 |
* to "CDATA", if none exists |
|
145 |
*/ |
|
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 | 148 |
return (i == null) ? CDATA : i.intValue(); |
149 |
} |
|
150 |
} |