OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [javax/] [swing/] [text/] [html/] [parser/] [AttributeList.java] - Blame information for rev 772

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 772 jeremybenn
/* AttributeList.java --
2
   Copyright (C) 2005 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
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)
9
any later version.
10
 
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.
15
 
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
19
02110-1301 USA.
20
 
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
24
combination.
25
 
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. */
37
 
38
 
39
package javax.swing.text.html.parser;
40
 
41
import gnu.javax.swing.text.html.parser.support.gnuStringIntMapper;
42
 
43
import java.io.Serializable;
44
 
45
import java.util.Enumeration;
46
import java.util.Vector;
47
 
48
/**
49
 * <p>
50
 * Stores the attribute information, obtained by parsing SGML (DTD) tag
51
 * <code>&lt;!ATTLIST .. &gt;</code></p>
52
 * <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 (.) .
61
 * </p>
62
 * <p>
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
68
 * the list.
69
 * </p>
70
 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
71
 */
72
public final class AttributeList
73
  implements DTDConstants, Serializable
74
{
75
  /** Maps between type names and they string values. */
76
  private static final gnuStringIntMapper mapper =
77
    new gnuStringIntMapper()
78
    {
79
      protected void create()
80
      {
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);
96
      }
97
    };
98
 
99
  /** Use serialVersionUID for interoperability. */
100
  private static final long serialVersionUID = -1361214058742015233L;
101
 
102
  /**
103
   * The value of ( = pointer to ) the next attribute in the linked list,
104
   * storing all attributes of some Element. Contains null for the
105
   * last attribute.
106
   */
107
  public AttributeList next;
108
 
109
  /**
110
   * The name of the attribute. The attribute names are case insensitive.
111
   */
112
  public String name;
113
 
114
  /**
115
   * The default value of this attribute. Equals to null if no default value
116
   * is specified.
117
   */
118
  public String value;
119
 
120
  /**
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.
124
   */
125
  public Vector<?> values;
126
 
127
  /**
128
   * The modifier of this attribute. This field contains one of the
129
   * following DTD constants:
130
   * <ul>
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
134
   * be changed.</li>
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>
143
   * </ul>
144
   */
145
  public int modifier;
146
 
147
  /**
148
   * The type of the attribute. The possible values of this field
149
   * (NUMBER, NAME, ID, CDATA and so on) are defined in DTDConstants.
150
   */
151
  public int type;
152
 
153
  /**
154
   * Creates the attribute with the given name, initializing other fields
155
   * to the default values ( 0 and null ).
156
   *
157
   * @param a_name The name of the attribute.
158
   */
159
  public AttributeList(String a_name)
160
  {
161
    name = a_name;
162
  }
163
 
164
  /**
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
173
   * this attribute
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.
177
   */
178
  public AttributeList(String a_name, int a_type, int a_modifier,
179
                       String a_default, Vector<?> allowed_values,
180
                       AttributeList a_next
181
                      )
182
  {
183
    this(a_name);
184
    type = a_type;
185
    modifier = a_modifier;
186
    value = a_default;
187
    values = allowed_values;
188
    next = a_next;
189
  }
190
 
191
  /**
192
   * Get the modifier of this attribute. This field contains one of the
193
   * following DTD constants:
194
   * <ul>
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
198
   * be changed.</li>
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>
207
   * </ul>
208
   */
209
  public int getModifier()
210
  {
211
    return modifier;
212
  }
213
 
214
  /**
215
   * Get the name of the attribute.
216
   * The value is returned as it was supplied to a
217
   * constructor, preserving the character case.
218
   */
219
  public String getName()
220
  {
221
    return name;
222
  }
223
 
224
  /**
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
227
   * last attribute.
228
   */
229
  public AttributeList getNext()
230
  {
231
    return next;
232
  }
233
 
234
  /**
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.
237
   */
238
  public int getType()
239
  {
240
    return type;
241
  }
242
 
243
  /**
244
   * Get the default value of this attribute.
245
   */
246
  public String getValue()
247
  {
248
    return value;
249
  }
250
 
251
  /**
252
   * Get the allowed values of this attribute.
253
   */
254
  public Enumeration<?> getValues()
255
  {
256
    return (values != null) ? values.elements() : null;
257
  }
258
 
259
  /**
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
267
   *  NUTOKENS.
268
   * @throws NullPointerException if the passed parameter is null.
269
   */
270
  public static int name2type(String typeName)
271
  {
272
    return mapper.get(typeName.toUpperCase());
273
  }
274
 
275
  /**
276
   * Returns the attribute name.
277
   */
278
  public String toString()
279
  {
280
    return name;
281
  }
282
 
283
  /**
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.
289
   */
290
  public static String type2name(int type)
291
  {
292
    return mapper.get(type);
293
  }
294
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.