1 /* AttributeList.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing.text.html.parser;
41 import gnu.javax.swing.text.html.parser.support.gnuStringIntMapper;
43 import java.io.Serializable;
45 import java.util.Enumeration;
46 import java.util.Vector;
50 * Stores the attribute information, obtained by parsing SGML (DTD) tag
51 * <code><!ATTLIST .. ></code></p>
53 * Elements can have a associated named properties (attributes) having the
54 * assigned values. The element start tag can have any number of attribute
55 * value pairs, separated by spaces. They can appear in any order.
56 * SGML requires you to delimit the attribute values using either double (")
57 * or single (') quotation marks. In HTML, it is possible
58 * (but not recommended) to specify the value of an attribute without
59 * quotation marks. Such attribute value may only contain
60 * letters, digits, hyphens (-) and periods (.) .
63 * The <code>AttributeList</code> defines a single attribute that additionally
64 * has a pointer referencing the possible subsequent attribute.
65 * The whole structure is just a simple linked list, storing all attributes of
66 * some <code>Element</code>.
67 * Use the <code>getNext()</code> method repeatedly to see all attributes in
70 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
72 public final class AttributeList
73 implements DTDConstants, Serializable
75 /** Maps between type names and they string values. */
76 private static final gnuStringIntMapper mapper =
77 new gnuStringIntMapper()
79 protected void create()
81 add("CDATA", DTDConstants.CDATA);
82 add("ENTITY", DTDConstants.ENTITY);
83 add("ENTITIES", DTDConstants.ENTITIES);
84 add("ID", DTDConstants.ID);
85 add("IDREF", DTDConstants.IDREF);
86 add("IDREFS", DTDConstants.IDREFS);
87 add("NAME", DTDConstants.NAME);
88 add("NAMES", DTDConstants.NAMES);
89 add("NMTOKEN", DTDConstants.NMTOKEN);
90 add("NMTOKENS", DTDConstants.NMTOKENS);
91 add("NOTATION", DTDConstants.NOTATION);
92 add("NUMBER", DTDConstants.NUMBER);
93 add("NUMBERS", DTDConstants.NUMBERS);
94 add("NUTOKEN", DTDConstants.NUTOKEN);
95 add("NUTOKENS", DTDConstants.NUTOKENS);
99 /** Use serialVersionUID for interoperability. */
100 private static final long serialVersionUID = -1361214058742015233L;
103 * The value of ( = pointer to ) the next attribute in the linked list,
104 * storing all attributes of some Element. Contains null for the
107 public AttributeList next;
110 * The name of the attribute. The attribute names are case insensitive.
115 * The default value of this attribute. Equals to null if no default value
121 * The explicit set of the allowed values of this attribute. Equals to
122 * null, if this parameter was not specified.
123 * Values, defined in DTD, are case insensitive.
125 public Vector values;
128 * The modifier of this attribute. This field contains one of the
129 * following DTD constants:
131 * <li> REQUIRED if the attribute value is always required,</li>
132 * <li> IMPLIED if the user agent must supply the default value itself,</li>
133 * <li> FIXED if the attribute value is fixed to some value and cannot
135 * <li> DEFAULT if the attribute default value has been supplied.</li>
136 * <li> CURRENT the value that at any point in the document is
137 * the last value supplied for that element. A value is required to be
138 * supplied for the first* occurrence of an element</li>
139 * <li> CONREF specifies the IDREF value of
140 * the reference to content in another location of the document.
141 * The element with this attribute is empty, the content from
142 * that another location must be used instead.</li>
148 * The type of the attribute. The possible values of this field
149 * (NUMBER, NAME, ID, CDATA and so on) are defined in DTDConstants.
154 * Creates the attribute with the given name, initializing other fields
155 * to the default values ( 0 and null ).
157 * @param a_name The name of the attribute.
159 public AttributeList(String a_name)
165 * Creates the attribute with the given properties.
166 * @param a_name The name of the attribute
167 * @param a_type The type of the attribute. The possible values are defined
168 * in <code> DTDConstants</code>.
169 * @param a_modifier The modifier of this attribute. The possible values
170 * are defined in <code> DTDConstants</code>.
171 * @param a_default The default value of this attribute
172 * @param allowed_values The explicit set of the allowed values of
174 * @param a_next The value of the subsequent instance of the AttributeList,
175 * representing the next attribute definition for the same element.
176 * Equals to null for the last attribute definition.
178 public AttributeList(String a_name, int a_type, int a_modifier,
179 String a_default, Vector allowed_values,
185 modifier = a_modifier;
187 values = allowed_values;
192 * Get the modifier of this attribute. This field contains one of the
193 * following DTD constants:
195 * <li> REQUIRED if the attribute value is always required,</li>
196 * <li> IMPLIED if the user agent must supply the default value itself,</li>
197 * <li> FIXED if the attribute value is fixed to some value and cannot
199 * <li> DEFAULT if the attribute default value has been supplied.</li>
200 * <li> CURRENT the value that at any point in the document is
201 * the last value supplied for that element. A value is required to be
202 * supplied for the first* occurrence of an element</li>
203 * <li> CONREF specifies the IDREF value of
204 * the reference to content in another location of the document.
205 * The element with this attribute is empty, the content from
206 * that another location must be used instead.</li>
209 public int getModifier()
215 * Get the name of the attribute.
216 * The value is returned as it was supplied to a
217 * constructor, preserving the character case.
219 public String getName()
225 * Get the value of ( = pointer to ) the next attribute in the linked list,
226 * storing all attributes of some Element. Contains null for the
229 public AttributeList getNext()
235 * Get the type of the attribute. The possible values of this field
236 * (NUMBER, NAME, ID, CDATA and so on) are defined in DTDConstants.
244 * Get the default value of this attribute.
246 public String getValue()
252 * Get the allowed values of this attribute.
254 public Enumeration getValues()
256 return values.elements();
260 * Converts a string value, representing a valid SGLM attribute type,
261 * into the corresponding value, defined in DTDConstants.
262 * @param typeName the name of the type (character case is ignored).
263 * @return a value from DTDConstants or DTDConstants.ANY if the
264 * string is not representing a known type. The known attribute types
265 * in this implementation are CDATA, ENTITY, ENTITIES, ID, IDREF, IDREFS,
266 * NAME, NAMES, NMTOKEN, NMTOKENS, NOTATION, NUMBER, NUMBERS, NUTOKEN and
268 * @throws NullPointerException if the passed parameter is null.
270 public static int name2type(String typeName)
272 return mapper.get(typeName.toUpperCase());
276 * Returns the attribute name.
278 public String toString()
284 * Converts a value from DTDConstants into the string representation.
285 * @param type - an integer value of the public static integer field,
286 * defined in the DTDConstants class.
287 * @return a corresponding SGML DTD keyword (UPPERCASE) or null if there
288 * are no attribute type constant having the given value.
290 public static String type2name(int type)
292 return mapper.get(type);