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
.BitSet
;
49 * Stores the element information, obtained by parsing SGML DTD
50 * tag <code><!ELEMENT .. ></code>. This class has no public
51 * constructor and can only be instantiated using the
52 * {@link javax.swing.text.html.parser.DTD } methods</p>
54 * <p>SGML defines elements that represent structures or
55 * behavior. An element typically consists of a start tag, content, and an
56 * end tag. Hence the elements are not tags. The HTML 4.0 definition specifies
57 * that some elements are not required to have the end tags. Also, some
58 * HTML elements (like <code><hr></code>) have no content. Element names
59 * are case sensitive.</p>
60 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
62 public final class Element
63 implements DTDConstants
, Serializable
66 * Package level mapper between type names and they string values.
68 static final gnuStringIntMapper mapper
=
69 new gnuStringIntMapper()
71 protected void create()
73 add("CDATA", DTDConstants
.CDATA
);
74 add("RCDATA", DTDConstants
.RCDATA
);
75 add("EMPTY", DTDConstants
.EMPTY
);
76 add("ANY", DTDConstants
.ANY
);
80 /** Use serialVersionUID for interoperability. */
81 private static final long serialVersionUID
= -6717939384601675586L;
84 * The element attributes.
86 public AttributeList atts
;
89 * Contains refernces to elements that must NOT occur inside this element,
90 * at any level of hierarchy.
92 public BitSet exclusions
;
95 * Contains refernces to elements that must CAN occur inside this element,
96 * at any level of hierarchy.
98 public BitSet inclusions
;
101 * The content model, defining elements, entities and DTD text
102 * that may/may not occur inside this element.
104 public ContentModel content
;
107 * A field to store additional user data for this Element.
117 * True is this element need not to have the closing tag, false
118 * otherwise. The HTML 4.0 definition specifies
119 * that some elements (like <code><hr></code>are
120 * not required to have the end tags.
125 * True is this element need not to have the starting tag, false
126 * otherwise. The HTML 4.0 definition specifies
127 * that some elements (like <code><head></code> or
128 * <code><body></code>) are
129 * not required to have the start tags.
132 public boolean oStart
;
135 * This field contains the unique integer identifier of this Element,
136 * used to refer the element (more exactly, the element flag)
137 * in <code>inclusions</code> and <code>exclusions</code> bit set.
142 * The element type, containing value, defined in DTDConstants.
143 * In this implementation, the element type can be
144 * CDATA, RCDATA, EMPTY or ANY.
149 * The default constructor must have package level access in this
150 * class. Use DTD.defineElement(..) to create an element when required.
154 // Nothing to do here.
158 * Converts the string representation of the element type
159 * into its unique integer identifier, defined in DTDConstants.
160 * @param a_type A name of the type
161 * @return DTDConstants.CDATA, DTDConstants.RCDATA, DTDConstants.EMPTY,
162 * DTDConstants.ANY or null if the type name is not
163 * "CDATA", "RCDATA", "EMPTY" or "ANY". This function is case sensitive.
164 * @throws NullPointerException if <code>a_type</code> is null.
166 public static int name2type(String a_type
)
168 return mapper
.get(a_type
);
172 * Get the element attribute by name.
173 * @param attribute the attribute name, case insensitive.
174 * @return the correspoding attribute of this element. The class,
175 * for storing as attribute list, as a single attribute, is used to
176 * store a single attribute in this case.
177 * @throws NullPointerException if the attribute name is null.
179 public AttributeList
getAttribute(String attribute
)
181 AttributeList a
= atts
;
183 while (a
!= null && !attribute
.equalsIgnoreCase(a
.name
))
190 * Get the element attribute by its value.
191 * @param a_value the attribute value, case insensitive.
192 * @return the correspoding attribute of this element. The class,
193 * for storing as attribute list, as a single attribute, is used to
194 * store a single attribute in this case. If there are several
195 * attributes with the same value, there is no garranty, which one
198 public AttributeList
getAttributeByValue(String a_value
)
200 AttributeList a
= atts
;
216 if (a
.value
!= null && a_value
.equalsIgnoreCase(a
.value
))
227 * Get all attributes of this document as an attribute list.
228 * @return The attribute list.
230 public AttributeList
getAttributes()
236 * Get the content model, defining elements, entities and DTD text
237 * that may/may not occur inside this element.
239 public ContentModel
getContent()
245 * Returns true for the element with no content.
246 * Empty elements are defined with the SGML DTD keyword "EMPTY".
247 * @return true if content model field (content) method is equal to
248 * null or its method empty() returns true.
250 public boolean isEmpty()
252 return content
== null || content
.empty();
256 * Get the unique integer identifier of this Element,
257 * used to refer the element (more exactly, the element flag)
258 * in <code>inclusions</code> and <code>exclusions</code> bit set.
259 * WARNING: This value may not be the same between different
262 public int getIndex()
268 * Get the element name.
270 public String
getName()
276 * Get the element type.
277 * @return one of the values, defined DTDConstants.
278 * In this implementation, the element type can be
279 * CDATA, RCDATA, EMPTY or ANY.
287 * True is this element need not to have the starting tag, false
288 * otherwise.s element need not to have the closing tag, false
289 * otherwise. The HTML 4.0 definition specifies
290 * that some elements (like <code><hr></code>are
291 * not required to have the end tags.
293 public boolean omitEnd()
299 * True is this element need not to have the closing tag, false
300 * otherwise. The HTML 4.0 definition specifies
301 * that some elements (like <code><head></code> or
302 * <code><body></code>) are
303 * not required to have the start tags.
305 public boolean omitStart()
311 * Returns the name of this element.
313 public String
toString()