jdk/src/share/classes/javax/swing/text/html/parser/AttributeList.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 1299 027d966d5658
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.text.html.parser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class defines the attributes of an SGML element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * as described in a DTD using the ATTLIST construct.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * An AttributeList can be obtained from the Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * class using the getAttributes() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * It is actually an element in a linked list. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * getNext() method repeatedly to enumerate all the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * of an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see         Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author      Arthur Van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public final
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
class AttributeList implements DTDConstants, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public Vector<?> values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public int modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public AttributeList next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    AttributeList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Create an attribute list element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public AttributeList(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Create an attribute list element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public AttributeList(String name, int type, int modifier, String value, Vector<?> values, AttributeList next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.modifier = modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.values = values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.next = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @return attribute type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @see DTDConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @return attribute modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see DTDConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public int getModifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return modifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @return possible attribute values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public Enumeration<?> getValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return (values != null) ? values.elements() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return default attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public String getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @return the next attribute in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public AttributeList getNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Create a hashtable of attribute types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    static Hashtable attributeTypes = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    static void defineAttributeType(String nm, int val) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   135
        Integer num = Integer.valueOf(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        attributeTypes.put(nm, num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        attributeTypes.put(num, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        defineAttributeType("CDATA", CDATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        defineAttributeType("ENTITY", ENTITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        defineAttributeType("ENTITIES", ENTITIES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        defineAttributeType("ID", ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        defineAttributeType("IDREF", IDREF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        defineAttributeType("IDREFS", IDREFS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        defineAttributeType("NAME", NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        defineAttributeType("NAMES", NAMES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        defineAttributeType("NMTOKEN", NMTOKEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        defineAttributeType("NMTOKENS", NMTOKENS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        defineAttributeType("NOTATION", NOTATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        defineAttributeType("NUMBER", NUMBER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        defineAttributeType("NUMBERS", NUMBERS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        defineAttributeType("NUTOKEN", NUTOKEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        defineAttributeType("NUTOKENS", NUTOKENS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   157
        attributeTypes.put("fixed", Integer.valueOf(FIXED));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   158
        attributeTypes.put("required", Integer.valueOf(REQUIRED));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   159
        attributeTypes.put("current", Integer.valueOf(CURRENT));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   160
        attributeTypes.put("conref", Integer.valueOf(CONREF));
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   161
        attributeTypes.put("implied", Integer.valueOf(IMPLIED));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static int name2type(String nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Integer i = (Integer)attributeTypes.get(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return (i == null) ? CDATA : i.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public static String type2name(int tp) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   170
        return (String)attributeTypes.get(Integer.valueOf(tp));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
}