001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package javax.swing.text.html.parser;
018:
019: import java.io.Serializable;
020: import java.util.Enumeration;
021: import java.util.Vector;
022:
023: public final class AttributeList implements DTDConstants, Serializable {
024: public String name;
025:
026: public int type;
027:
028: public Vector values;
029:
030: public int modifier;
031:
032: public String value;
033:
034: public AttributeList next;
035:
036: //TODO It need check type FIXED, IMPLIED, REQUIRED?
037: public AttributeList(final String name, final int type,
038: final int modifier, final String value,
039: final Vector values, final AttributeList next) {
040: this .name = name;
041: this .type = type;
042: this .modifier = modifier;
043: this .value = value;
044: this .values = values;
045: this .next = next;
046: }
047:
048: public static String type2name(final int type) {
049: init();
050: return type >= 0 && type < names.length ? names[type] : null;
051: }
052:
053: public static int name2type(final String name) {
054: init();
055: for (int i = 0; i < names.length; i++) {
056: if (name.equals(names[i])) {
057: return i;
058: }
059: }
060: return 1;
061: }
062:
063: static int nameToModifier(final String name) {
064: if ("#IMPLIED".equals(name)) {
065: return DTDConstants.IMPLIED;
066: } else if ("#REQUIRED".equals(name)) {
067: return DTDConstants.REQUIRED;
068: } else if ("#FIXED".equals(name)) {
069: return DTDConstants.FIXED;
070: } else {
071: return DTDConstants.DEFAULT;
072: }
073: }
074:
075: static String modifierToName(final int modifier) {
076: if (modifier == DTDConstants.IMPLIED) {
077: return "#IMPLIED";
078: } else if (modifier == DTDConstants.REQUIRED) {
079: return "#REQUIRED";
080: } else if (modifier == DTDConstants.FIXED) {
081: return "#FIXED";
082: } else {
083: return "#DEFAULT";
084: }
085: }
086:
087: public AttributeList(final String name) {
088: this .name = name;
089: }
090:
091: AttributeList() {
092: }
093:
094: public String toString() {
095: return name;
096: }
097:
098: final String paramString() {
099: //name type modifier,next.name next.type next.modifier
100: String name = this .name;
101: String type = values == null ? type2name(this .type)
102: : valuesToString();
103: String modifier = modifierToName(this .modifier);
104: modifier = "#DEFAULT".equals(modifier) ? value : modifier;
105: String result = name + " " + type + " " + modifier;
106: return next == null ? result : result + ","
107: + next.paramString();
108: }
109:
110: final String valuesToString() {
111: if (values != null) {
112: String result = "";
113: for (int i = 0; i < values.size(); i++) {
114: result += "|" + values.get(i);
115: }
116: return result.substring(1, result.length());
117: }
118: return null;
119: }
120:
121: public AttributeList getNext() {
122: return next;
123: }
124:
125: public String getValue() {
126: return value;
127: }
128:
129: public Enumeration getValues() {
130: // avoids a NullPointerException if values is null (same as RI)
131: return values == null ? null : values.elements();
132: }
133:
134: public int getModifier() {
135: return modifier;
136: }
137:
138: public int getType() {
139: return type;
140: }
141:
142: public String getName() {
143: return name;
144: }
145:
146: private static String[] names;
147:
148: private static void init() {
149: if (names == null) {
150: names = new String[] { null, "CDATA", "ENTITY", "ENTITIES",
151: "ID", "IDREF", "IDREFS", "NAME", "NAMES",
152: "NMTOKEN", "NMTOKENS", "NOTATION", "NUMBER",
153: "NUMBERS", "NUTOKEN", "NUTOKENS" };
154: }
155: }
156:
157: final boolean containsValue(final String value) {
158: return values == null ? false : values.contains(value);
159: }
160: }
|