author | darcy |
Sun, 23 Mar 2014 13:49:48 -0700 | |
changeset 23697 | e556a715949f |
parent 5506 | 202f599c92aa |
child 24494 | 67129b9360d2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 1998, 2014, 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.Vector; |
|
29 |
import java.util.Hashtable; |
|
30 |
import java.util.Enumeration; |
|
31 |
import java.io.*; |
|
32 |
||
33 |
/** |
|
34 |
* This class defines the attributes of an SGML element |
|
35 |
* as described in a DTD using the ATTLIST construct. |
|
36 |
* An AttributeList can be obtained from the Element |
|
37 |
* class using the getAttributes() method. |
|
38 |
* <p> |
|
39 |
* It is actually an element in a linked list. Use the |
|
40 |
* getNext() method repeatedly to enumerate all the attributes |
|
41 |
* of an element. |
|
42 |
* |
|
43 |
* @see Element |
|
44 |
* @author Arthur Van Hoff |
|
45 |
* |
|
46 |
*/ |
|
23697 | 47 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 48 |
public final |
49 |
class AttributeList implements DTDConstants, Serializable { |
|
50 |
public String name; |
|
51 |
public int type; |
|
52 |
public Vector<?> values; |
|
53 |
public int modifier; |
|
54 |
public String value; |
|
55 |
public AttributeList next; |
|
56 |
||
57 |
AttributeList() { |
|
58 |
} |
|
59 |
||
60 |
/** |
|
61 |
* Create an attribute list element. |
|
62 |
*/ |
|
63 |
public AttributeList(String name) { |
|
64 |
this.name = name; |
|
65 |
} |
|
66 |
||
67 |
/** |
|
68 |
* Create an attribute list element. |
|
69 |
*/ |
|
70 |
public AttributeList(String name, int type, int modifier, String value, Vector<?> values, AttributeList next) { |
|
71 |
this.name = name; |
|
72 |
this.type = type; |
|
73 |
this.modifier = modifier; |
|
74 |
this.value = value; |
|
75 |
this.values = values; |
|
76 |
this.next = next; |
|
77 |
} |
|
78 |
||
79 |
/** |
|
80 |
* @return attribute name |
|
81 |
*/ |
|
82 |
public String getName() { |
|
83 |
return name; |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* @return attribute type |
|
88 |
* @see DTDConstants |
|
89 |
*/ |
|
90 |
public int getType() { |
|
91 |
return type; |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* @return attribute modifier |
|
96 |
* @see DTDConstants |
|
97 |
*/ |
|
98 |
public int getModifier() { |
|
99 |
return modifier; |
|
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* @return possible attribute values |
|
104 |
*/ |
|
105 |
public Enumeration<?> getValues() { |
|
106 |
return (values != null) ? values.elements() : null; |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* @return default attribute value |
|
111 |
*/ |
|
112 |
public String getValue() { |
|
113 |
return value; |
|
114 |
} |
|
115 |
||
116 |
/** |
|
117 |
* @return the next attribute in the list |
|
118 |
*/ |
|
119 |
public AttributeList getNext() { |
|
120 |
return next; |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* @return string representation |
|
125 |
*/ |
|
126 |
public String toString() { |
|
127 |
return name; |
|
128 |
} |
|
129 |
||
130 |
/** |
|
131 |
* Create a hashtable of attribute types. |
|
132 |
*/ |
|
1287
a04aca99c77a
6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents:
438
diff
changeset
|
133 |
static Hashtable<Object, Object> attributeTypes = new Hashtable<Object, Object>(); |
2 | 134 |
|
135 |
static void defineAttributeType(String nm, int val) { |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
136 |
Integer num = Integer.valueOf(val); |
2 | 137 |
attributeTypes.put(nm, num); |
138 |
attributeTypes.put(num, nm); |
|
139 |
} |
|
140 |
||
141 |
static { |
|
142 |
defineAttributeType("CDATA", CDATA); |
|
143 |
defineAttributeType("ENTITY", ENTITY); |
|
144 |
defineAttributeType("ENTITIES", ENTITIES); |
|
145 |
defineAttributeType("ID", ID); |
|
146 |
defineAttributeType("IDREF", IDREF); |
|
147 |
defineAttributeType("IDREFS", IDREFS); |
|
148 |
defineAttributeType("NAME", NAME); |
|
149 |
defineAttributeType("NAMES", NAMES); |
|
150 |
defineAttributeType("NMTOKEN", NMTOKEN); |
|
151 |
defineAttributeType("NMTOKENS", NMTOKENS); |
|
152 |
defineAttributeType("NOTATION", NOTATION); |
|
153 |
defineAttributeType("NUMBER", NUMBER); |
|
154 |
defineAttributeType("NUMBERS", NUMBERS); |
|
155 |
defineAttributeType("NUTOKEN", NUTOKEN); |
|
156 |
defineAttributeType("NUTOKENS", NUTOKENS); |
|
157 |
||
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
158 |
attributeTypes.put("fixed", Integer.valueOf(FIXED)); |
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
159 |
attributeTypes.put("required", Integer.valueOf(REQUIRED)); |
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
160 |
attributeTypes.put("current", Integer.valueOf(CURRENT)); |
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
161 |
attributeTypes.put("conref", Integer.valueOf(CONREF)); |
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
162 |
attributeTypes.put("implied", Integer.valueOf(IMPLIED)); |
2 | 163 |
} |
164 |
||
165 |
public static int name2type(String nm) { |
|
166 |
Integer i = (Integer)attributeTypes.get(nm); |
|
167 |
return (i == null) ? CDATA : i.intValue(); |
|
168 |
} |
|
169 |
||
170 |
public static String type2name(int tp) { |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
171 |
return (String)attributeTypes.get(Integer.valueOf(tp)); |
2 | 172 |
} |
173 |
} |