1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
/* * @(#)Element.java 1.10 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.swing.text.html.parser; import java.util.Hashtable; import java.util.BitSet; import java.io.*; /** * An element as described in a DTD using the ELEMENT construct. * This is essentiall the description of a tag. It describes the * type, content model, attributes, attribute types etc. It is used * to correctly parse a document by the Parser. * * @see DTD * @see AttributeList * @version 1.10, 11/17/05 * @author Arthur van Hoff */ public final class Element implements DTDConstants, Serializable { public int index; public String name; public boolean oStart; public boolean oEnd; public BitSet inclusions; public BitSet exclusions; public int type = ANY; public ContentModel content; public AttributeList atts; static int maxIndex = 0; /** * A field to store user data. Mostly used to store * style sheets. */ public Object data; Element() { } /** * Create a new element. */ Element(String name, int index) { this.name = name; this.index = index; maxIndex = Math.max(maxIndex, index); } /** * Get the name of the element. */ public String getName() { return name; } /** * Return true if the start tag can be omitted. */ public boolean omitStart() { return oStart; } /** * Return true if the end tag can be omitted. */ public boolean omitEnd() { return oEnd; } /** * Get type. */ public int getType() { return type; } /** * Get content model */ public ContentModel getContent() { return content; } /** * Get the attributes. */ public AttributeList getAttributes() { return atts; } /** * Get index. */ public int getIndex() { return index; } /** * Check if empty */ public boolean isEmpty() { return type == EMPTY; } /** * Convert to a string. */ public String toString() { return name; } /** * Get an attribute by name. */ public AttributeList getAttribute(String name) { for (AttributeList a = atts ; a != null ; a = a.next) { if (a.name.equals(name)) { return a; } } return null; } /** * Get an attribute by value. */ public AttributeList getAttributeByValue(String name) { for (AttributeList a = atts ; a != null ; a = a.next) { if ((a.values != null) && a.values.contains(name)) { return a; } } return null; } static Hashtable contentTypes = new Hashtable(); static { contentTypes.put("CDATA", new Integer(CDATA)); contentTypes.put("RCDATA", new Integer(RCDATA)); contentTypes.put("EMPTY", new Integer(EMPTY)); contentTypes.put("ANY", new Integer(ANY)); } public static int name2type(String nm) { Integer val = (Integer)contentTypes.get(nm); return (val != null) ? val.intValue() : 0; } }