[multiple changes]
2005-04-19 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/xml/dom/html2/DomHTMLParser.java: Changed 'enum' references to become 'enumeration'. 2005-04-19 Audrius Meskauskas <audriusa@bluewin.ch> * gnu/xml/dom/html2/DomHTMLParser.java: New file. 2005-04-19 Andrew John Hughes <gnu_andrew@member.fsf.org> * gnu/javax/swing/text/html/parser/htmlAttributeSet.java: (getAttributeNames()): Replaced 'enum' with 'enumeration'. * gnu/javax/swing/text/html/parser/htmlValidator.java: (validateParameters(TagElement,htmlAttributeSet)): Replaced 'enum' with 'enumeration'. (validateAttribute(TagElement,htmlAttributeSet,Enumeration,Enumeration)): Likewise. 2005-04-19 Audrius Meskauskas <audriusa@bluewin.ch> * javax/swing/text/html/parser/Entity.java (getType): New method. * javax/swing/text/html/parser/DocumentParser.java: Inherit from javax.swing.text.html.parser.Parser. 2005-04-19 Chris Burdess <dog@gnu.org> * gnu/xml/dom/html2/DomHTMLDocument.java: Fixed element creation and check for HTML/XHTML namespace. 2005-04-19 Audrius Meskauskas <audriusa@bluewin.ch> * javax/swing/text/html/parser/Parser.java, javax/swing/text/html/parser/Entity.java: Inheriting from DTDConstants. * javax/swing/text/html/parser/AttributeList.java (getValues): Changed return type. * javax/swing/text/html/parser/DocumentParser (parse): Adding the callback parameter that receives the parsing events. 2005-04-19 Chris Burdess <dog@gnu.org> * gnu/xml/dom/DomImpl.java, gnu/xml/dom/html2/DomHTMLAnchorElement.java, gnu/xml/dom/html2/DomHTMLDocument.java, gnu/xml/dom/html2/DomHTMLElement.java, gnu/xml/dom/html2/DomHTMLFormElement.java, gnu/xml/dom/html2/DomHTMLFrameElement.java, gnu/xml/dom/html2/DomHTMLIFrameElement.java, gnu/xml/dom/html2/DomHTMLImpl.java, gnu/xml/dom/html2/DomHTMLInputElement.java, gnu/xml/dom/html2/DomHTMLObjectElement.java, gnu/xml/dom/html2/DomHTMLOptionElement.java, gnu/xml/dom/html2/DomHTMLSelectElement.java, gnu/xml/dom/html2/DomHTMLTableCellElement.java, gnu/xml/dom/html2/DomHTMLTableElement.java, gnu/xml/dom/html2/DomHTMLTableRowElement.java, gnu/xml/dom/html2/DomHTMLTableSectionElement.java, gnu/xml/dom/html2/DomHTMLTextAreaElement.java: JAXP integration, UI events, and tree utility functions. 2005-04-19 Michael Koch <konqueror@gmx.de> * gnu/javax/swing/text/html/parser/HTML_401F.java, gnu/javax/swing/text/html/parser/gnuDTD.java, gnu/javax/swing/text/html/parser/models/node.java: Reworked import statements. 2005-04-19 Audrius Meskauskas, Lithuania <AudriusA@Bioinformatics.org> * javax/swing/text/html/HTMLDocument.java: New file. 2005-04-19 Michael Koch <konqueror@gmx.de> * javax/swing/text/html/HTMLFrameHyperlinkEvent.java: Reformatted. * javax/swing/text/html/parser/AttributeList.java: Fixed order of modifiers. (AttributeList): Made final. * javax/swing/text/html/parser/ContentModel.java: Fixed html characters in javadocs. * javax/swing/text/html/parser/DTD.java (DTD): Don't implement java.io.Serializable directly. (getElement): Simplified. * javax/swing/text/html/parser/DTDConstants.java: Reformatted file. * javax/swing/text/html/parser/Element.java: Fixed order of modifiers. * javax/swing/text/html/parser/Parser.java: Reformatted. Don't use fully-qualified class names. * javax/swing/text/html/parser/ParserDelegator.java: Fixed order of modifiers. * javax/swing/text/rtf/RTFParser.java: Re-ordered import statements. * javax/swing/text/rtf/RTFScanner.java: Removed unused import statement. 2005-04-19 Chris Burdess <dog@gnu.org> * gnu/xml/dom/html2/DomHTMLButtonElement.java, gnu/xml/dom/html2/DomHTMLCollection.java, gnu/xml/dom/html2/DomHTMLDocument.java, gnu/xml/dom/html2/DomHTMLElement.java: Extensions for new element types. * gnu/xml/dom/html2/DomHTMLDListElement.java, gnu/xml/dom/html2/DomHTMLDirectoryElement.java, gnu/xml/dom/html2/DomHTMLDivElement.java, gnu/xml/dom/html2/DomHTMLFieldSetElement.java, gnu/xml/dom/html2/DomHTMLFontElement.java, gnu/xml/dom/html2/DomHTMLFormElement.java, gnu/xml/dom/html2/DomHTMLFrameElement.java, gnu/xml/dom/html2/DomHTMLFrameSetElement.java, gnu/xml/dom/html2/DomHTMLHRElement.java, gnu/xml/dom/html2/DomHTMLHeadElement.java, gnu/xml/dom/html2/DomHTMLHeadingElement.java, gnu/xml/dom/html2/DomHTMLHtmlElement.java, gnu/xml/dom/html2/DomHTMLIFrameElement.java, gnu/xml/dom/html2/DomHTMLImageElement.java, gnu/xml/dom/html2/DomHTMLInputElement.java, gnu/xml/dom/html2/DomHTMLIsIndexElement.java, gnu/xml/dom/html2/DomHTMLLIElement.java, gnu/xml/dom/html2/DomHTMLLabelElement.java, gnu/xml/dom/html2/DomHTMLLegendElement.java, gnu/xml/dom/html2/DomHTMLLinkElement.java, gnu/xml/dom/html2/DomHTMLMapElement.java, gnu/xml/dom/html2/DomHTMLMenuElement.java, gnu/xml/dom/html2/DomHTMLMetaElement.java, gnu/xml/dom/html2/DomHTMLModElement.java, gnu/xml/dom/html2/DomHTMLOListElement.java, gnu/xml/dom/html2/DomHTMLObjectElement.java, gnu/xml/dom/html2/DomHTMLOptGroupElement.java, gnu/xml/dom/html2/DomHTMLOptionElement.java, gnu/xml/dom/html2/DomHTMLParagraphElement.java, gnu/xml/dom/html2/DomHTMLParamElement.java, gnu/xml/dom/html2/DomHTMLPreElement.java, gnu/xml/dom/html2/DomHTMLQuoteElement.java, gnu/xml/dom/html2/DomHTMLScriptElement.java, gnu/xml/dom/html2/DomHTMLSelectElement.java, gnu/xml/dom/html2/DomHTMLStyleElement.java, gnu/xml/dom/html2/DomHTMLTableCaptionElement.java, gnu/xml/dom/html2/DomHTMLTableCellElement.java, gnu/xml/dom/html2/DomHTMLTableColElement.java, gnu/xml/dom/html2/DomHTMLTableElement.java, gnu/xml/dom/html2/DomHTMLTableRowElement.java, gnu/xml/dom/html2/DomHTMLTableSectionElement.java, gnu/xml/dom/html2/DomHTMLTextAreaElement.java, gnu/xml/dom/html2/DomHTMLTitleElement.java, gnu/xml/dom/html2/DomHTMLUListElement.java: New files. 2005-04-19 Audrius Meskauskas <audriusa@bluewin.ch> * javax/swing/text/ChangedCharSetException.java, javax/swing/text/html/HTMLEditorKit.java, javax/swing/text/html/HTMLFrameHyperlinkEvent.java, javax/swing/text/html/parser/AttributeList.java, javax/swing/text/html/parser/ContentModel.java, javax/swing/text/html/parser/DocumentParser.java, javax/swing/text/html/parser/DTD.java, javax/swing/text/html/parser/DTDConstants.java, javax/swing/text/html/parser/Element.java, javax/swing/text/html/parser/Entity.java, javax/swing/text/html/parser/Parser.java, javax/swing/text/html/parser/TagElement.java, gnu/javax/swing/text/html/package.html, gnu/javax/swing/text/html/parser/gnuDTD.java, gnu/javax/swing/text/html/parser/HTML_401F.java, gnu/javax/swing/text/html/parser/htmlAttributeSet.java, gnu/javax/swing/text/html/parser/htmlValidator.java, gnu/javax/swing/text/html/parser/package.html, gnu/javax/swing/text/html/parser/models/list.java, gnu/javax/swing/text/html/parser/models/node.java, gnu/javax/swing/text/html/parser/models/noTagModel.java, gnu/javax/swing/text/html/parser/models/package.html, gnu/javax/swing/text/html/parser/models/PCDATAonly_model.java, gnu/javax/swing/text/html/parser/models/TableRowContentModel.java, gnu/javax/swing/text/html/parser/models/transformer.java, gnu/javax/swing/text/html/parser/support/gnuStringIntMapper.java, gnu/javax/swing/text/html/parser/support/package.html, gnu/javax/swing/text/html/parser/support/parameterDefaulter.java, gnu/javax/swing/text/html/parser/support/Parser.java, gnu/javax/swing/text/html/parser/support/textPreProcessor.java, gnu/javax/swing/text/html/parser/support/low/Buffer.java, gnu/javax/swing/text/html/parser/support/low/Constants.java, gnu/javax/swing/text/html/parser/support/low/Location.java, gnu/javax/swing/text/html/parser/support/low/node.java, gnu/javax/swing/text/html/parser/support/low/package.html, gnu/javax/swing/text/html/parser/support/low/ParseException.java, gnu/javax/swing/text/html/parser/support/low/pattern.java, gnu/javax/swing/text/html/parser/support/low/Queue.java, gnu/javax/swing/text/html/parser/support/low/ReaderTokenizer.java: New files. * javax/swing/text/html/HTML.java, javax/swing/text/html/parser/ParserDelegator.java: New files (replacing). * javax/swing/text/html/package.html, javax/swing/text/html/parser/package.html: Documenting the packages. 2005-04-19 Chris Burdess <dog@gnu.org> * gnu/xml/dom/html2/DomHTMLAnchorElement.java, gnu/xml/dom/html2/DomHTMLAppletElement.java, gnu/xml/dom/html2/DomHTMLAreaElement.java, gnu/xml/dom/html2/DomHTMLBaseElement.java, gnu/xml/dom/html2/DomHTMLBaseFontElement.java, gnu/xml/dom/html2/DomHTMLBodyElement.java, gnu/xml/dom/html2/DomHTMLBRElement.java, gnu/xml/dom/html2/DomHTMLButtonElement.java, gnu/xml/dom/html2/DomHTMLCollection.java, gnu/xml/dom/html2/DomHTMLDocument.java, gnu/xml/dom/html2/DomHTMLElement.java: New files. 2005-04-19 Michael Koch <konqueror@gmx.de> * Makefile.am: Added new files. * Makefile.in: Regenerated. From-SVN: r98406
This commit is contained in:
parent
c5f083efc5
commit
18e479e213
104 changed files with 22587 additions and 27 deletions
607
libjava/javax/swing/text/html/parser/DTD.java
Executable file
607
libjava/javax/swing/text/html/parser/DTD.java
Executable file
|
@ -0,0 +1,607 @@
|
|||
/* DTD.java --
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package javax.swing.text.html.parser;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.BitSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* <p>Representation or the SGML DTD document.
|
||||
* Provides basis for describing a syntax of the
|
||||
* HTML documents. The fields of this class are NOT initialized in
|
||||
* constructor. You need to do this separately before passing this data
|
||||
* structure to the HTML parser. The subclasses with the fields, pre-
|
||||
* initialized, for example, for HTML 4.01, can be available only between
|
||||
* the implementation specific classes
|
||||
* ( for example, {@link gnu.javax.swing.text.html.parser.HTML_401F }
|
||||
* in this implementation).</p>
|
||||
* <p>
|
||||
* If you need more information about SGML DTD documents,
|
||||
* the author suggests to read SGML tutorial on
|
||||
* {@link http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html}.
|
||||
* We also recommend Goldfarb C.F (1991) <i>The SGML Handbook</i>,
|
||||
* Oxford University Press, 688 p, ISBN: 0198537379.
|
||||
* </p>
|
||||
* <p>
|
||||
* Warning: the html, head and other tag fields will only be automatically
|
||||
* assigned if the VM has the correctly implemented reflection mechanism.
|
||||
* As these fields are not used anywhere in the implementation, not
|
||||
* exception will be thrown in the opposite case.
|
||||
* </p>
|
||||
*
|
||||
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
|
||||
*/
|
||||
public class DTD
|
||||
implements DTDConstants
|
||||
{
|
||||
/**
|
||||
* The version of the persistent data format.
|
||||
*/
|
||||
public static int FILE_VERSION = 1;
|
||||
|
||||
/**
|
||||
* The table of existing available DTDs.
|
||||
*/
|
||||
static Hashtable dtdHash = new Hashtable();
|
||||
|
||||
/**
|
||||
* The applet element for this DTD.
|
||||
*/
|
||||
public Element applet;
|
||||
|
||||
/**
|
||||
* The base element for this DTD.
|
||||
*/
|
||||
public Element base;
|
||||
|
||||
/**
|
||||
* The body element for this DTD.
|
||||
*/
|
||||
public Element body;
|
||||
|
||||
/**
|
||||
* The head element for this DTD.
|
||||
*/
|
||||
public Element head;
|
||||
|
||||
/**
|
||||
* The html element for this DTD.
|
||||
*/
|
||||
public Element html;
|
||||
|
||||
/**
|
||||
* The isindex element of for this DTD.
|
||||
*/
|
||||
public Element isindex;
|
||||
|
||||
/**
|
||||
* The meta element for this DTD.
|
||||
*/
|
||||
public Element meta;
|
||||
|
||||
/**
|
||||
* The p element for this DTD.
|
||||
*/
|
||||
public Element p;
|
||||
|
||||
/**
|
||||
* The param element for this DTD.
|
||||
*/
|
||||
public Element param;
|
||||
|
||||
/**
|
||||
* The pcdata for this DTD.
|
||||
*/
|
||||
public Element pcdata;
|
||||
|
||||
/**
|
||||
* The title element for this DTD.
|
||||
*/
|
||||
public Element title;
|
||||
|
||||
/**
|
||||
* The element for accessing all DTD elements by name.
|
||||
*/
|
||||
public Hashtable elementHash = new Hashtable();
|
||||
|
||||
/**
|
||||
* The entity table for accessing all DTD entities by name.
|
||||
*/
|
||||
public Hashtable entityHash = new Hashtable();
|
||||
|
||||
/**
|
||||
* The name of this DTD.
|
||||
*/
|
||||
public String name;
|
||||
|
||||
/**
|
||||
* Contains all elements in this DTD. The
|
||||
* javax.swing.text.html.parser.Element#index field of all elements
|
||||
* in this vector is set to the element position in this vector.
|
||||
*/
|
||||
public Vector elements = new Vector();
|
||||
|
||||
/** Create a new DTD with the specified name. */
|
||||
protected DTD(String a_name)
|
||||
{
|
||||
name = a_name;
|
||||
}
|
||||
|
||||
/** Get this DTD by name. The current implementation
|
||||
* only looks in the internal table of DTD documents. If no corresponding
|
||||
* entry is found, the new entry is created, placed into
|
||||
* the table and returned. */
|
||||
public static DTD getDTD(String name)
|
||||
throws IOException
|
||||
{
|
||||
DTD d = (DTD) dtdHash.get(name);
|
||||
|
||||
if (d == null)
|
||||
{
|
||||
d = new DTD(name);
|
||||
dtdHash.put(d.name, d);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element by the element name. If the element is not yet
|
||||
* defined, it is newly created and placed into the element table.
|
||||
* If the element name matches (ingoring case) a public non static
|
||||
* element field in this class, this field is assigned to the value
|
||||
* of the newly created element.
|
||||
*/
|
||||
public Element getElement(String element_name)
|
||||
{
|
||||
return newElement(element_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element by the value of its
|
||||
* {@link javax.swing.text.html.parser.Element#index} field.
|
||||
*/
|
||||
public Element getElement(int index)
|
||||
{
|
||||
return (Element) elements.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity with the given identifier.
|
||||
* @param id that can be returned by
|
||||
* {@link javax.swing.text.html.parser.Entity#name2type(String an_entity)}
|
||||
* @return The entity from this DTD or null if there is no entity with
|
||||
* such id or such entity is not present in the table of this instance.
|
||||
*/
|
||||
public Entity getEntity(int id)
|
||||
{
|
||||
String name = Entity.mapper.get(id);
|
||||
|
||||
if (name != null)
|
||||
return (Entity) entityHash.get(name);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the named entity by its name.
|
||||
*/
|
||||
public Entity getEntity(String entity_name)
|
||||
{
|
||||
return (Entity) entityHash.get(entity_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this instance of DTD
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates, adds into the entity table and returns the
|
||||
* character entity like <code>&lt;</code>
|
||||
* (means '<code><</code>' );
|
||||
* @param name The entity name (without heading & and closing ;)
|
||||
* @param type The entity type
|
||||
* @param character The entity value (single character)
|
||||
* @return The created entity
|
||||
*/
|
||||
public Entity defEntity(String name, int type, int character)
|
||||
{
|
||||
Entity e = newEntity(name, type);
|
||||
e.data = new char[] { (char) character };
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the attributes for the element with the given name.
|
||||
* If the element is not exist, it is created.
|
||||
* @param forElement
|
||||
* @param attributes
|
||||
*/
|
||||
public void defineAttributes(String forElement, AttributeList attributes)
|
||||
{
|
||||
Element e = (Element) elementHash.get(forElement.toLowerCase());
|
||||
|
||||
if (e == null)
|
||||
e = newElement(forElement);
|
||||
|
||||
e.atts = attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the element and adds it to the element table. Sets the
|
||||
* <code>Element.index</code> field to the value, unique for this
|
||||
* instance of DTD. If the element with the given name already exists,
|
||||
* replaces all other its settings by the method argument values.
|
||||
* @param name the name of the element
|
||||
* @param type the type of the element
|
||||
* @param headless true if the element needs no starting tag
|
||||
* (should not occur in HTML).
|
||||
* @param tailless true if the element needs no ending tag (like
|
||||
* <code><hr></code>
|
||||
* @param content the element content
|
||||
* @param exclusions the set of elements that must not occur inside
|
||||
* this element. The <code>Element.index</code> value defines which
|
||||
* bit in this bitset corresponds to that element.
|
||||
* @param inclusions the set of elements that can occur inside this
|
||||
* element. the <code>Element.index</code> value defines which
|
||||
* bit in this bitset corresponds to that element.
|
||||
* @param attributes the element attributes.
|
||||
* @return the newly defined element.
|
||||
*/
|
||||
public Element defineElement(String name, int type, boolean headless,
|
||||
boolean tailless, ContentModel content,
|
||||
BitSet exclusions, BitSet inclusions,
|
||||
AttributeList attributes
|
||||
)
|
||||
{
|
||||
Element e = newElement(name);
|
||||
e.type = type;
|
||||
e.oStart = headless;
|
||||
e.oEnd = tailless;
|
||||
e.content = content;
|
||||
e.exclusions = exclusions;
|
||||
e.inclusions = inclusions;
|
||||
e.atts = attributes;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates, intializes and adds to the entity table the new
|
||||
* entity.
|
||||
* @param name the name of the entity
|
||||
* @param type the type of the entity
|
||||
* @param data the data section of the entity
|
||||
* @return the created entity
|
||||
*/
|
||||
public Entity defineEntity(String name, int type, char[] data)
|
||||
{
|
||||
Entity e = newEntity(name, type);
|
||||
e.data = data;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/** Place this DTD into the DTD table. */
|
||||
public static void putDTDHash(String name, DTD dtd)
|
||||
{
|
||||
dtdHash.put(name, dtd);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Reads DTD from an archived format. This format is not standardized
|
||||
* and differs between implementations.</p><p> This implementation
|
||||
* reads and defines all entities and elements using
|
||||
* ObjectInputStream. The elements and entities can be written into the
|
||||
* stream in any order. The objects other than elements and entities
|
||||
* are ignored.</p>
|
||||
* @param stream A data stream to read from.
|
||||
* @throws java.io.IOException If one is thrown by the input stream
|
||||
*/
|
||||
public void read(DataInputStream stream)
|
||||
throws java.io.IOException
|
||||
{
|
||||
ObjectInputStream oi = new ObjectInputStream(stream);
|
||||
Object def;
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
def = oi.readObject();
|
||||
if (def instanceof Element)
|
||||
{
|
||||
Element e = (Element) def;
|
||||
elementHash.put(e.name.toLowerCase(), e);
|
||||
assignField(e);
|
||||
}
|
||||
else if (def instanceof Entity)
|
||||
{
|
||||
Entity e = (Entity) def;
|
||||
entityHash.put(e.name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException ex)
|
||||
{
|
||||
throw new IOException(ex.getMessage());
|
||||
}
|
||||
catch (EOFException ex)
|
||||
{
|
||||
// ok EOF
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this instance of DTD.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns new attribute (not an attribute list).
|
||||
* @param name the name of this attribute
|
||||
* @param type the type of this attribute (FIXED, IMPLIED or
|
||||
* REQUIRED from <code>DTDConstants</code>).
|
||||
* @param modifier the modifier of this attribute
|
||||
* @param default_value the default value of this attribute
|
||||
* @param allowed_values the allowed values of this attribute. The multiple
|
||||
* possible values in this parameter are supposed to be separated by
|
||||
* '|', same as in SGML DTD <code><!ATTLIST </code>tag. This parameter
|
||||
* can be null if no list of allowed values is specified.
|
||||
* @param atts the previous attribute of this element. This is
|
||||
* placed to the field
|
||||
* {@link javax.swing.text.html.parser.AttributeList#next },
|
||||
* creating a linked list.
|
||||
* @return
|
||||
*/
|
||||
protected AttributeList defAttributeList(String name, int type, int modifier,
|
||||
String default_value,
|
||||
String allowed_values,
|
||||
AttributeList atts
|
||||
)
|
||||
{
|
||||
AttributeList al = new AttributeList(name);
|
||||
al.modifier = modifier;
|
||||
al.value = default_value;
|
||||
al.next = atts;
|
||||
|
||||
if (allowed_values != null)
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(allowed_values, " \t|");
|
||||
Vector v = new Vector(st.countTokens());
|
||||
|
||||
while (st.hasMoreTokens())
|
||||
v.add(st.nextToken());
|
||||
|
||||
al.values = v;
|
||||
}
|
||||
|
||||
return al;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new content model.
|
||||
* @param type specifies the BNF operation for this content model.
|
||||
* The valid operations are documented in the
|
||||
* {@link javax.swing.text.html.parser.ContentModel#type }.
|
||||
* @param content the content of this content model
|
||||
* @param next if the content model is specified by BNF-like
|
||||
* expression, contains the rest of this expression.
|
||||
* @return The newly created content model.
|
||||
*/
|
||||
protected ContentModel defContentModel(int type, Object content,
|
||||
ContentModel next
|
||||
)
|
||||
{
|
||||
ContentModel model = new ContentModel();
|
||||
model.type = type;
|
||||
model.next = next;
|
||||
model.content = content;
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a new element and adds it to the element table.
|
||||
* If the element alredy exists,
|
||||
* overrides it settings with the specified values.
|
||||
* @param name the name of the new element
|
||||
* @param type the type of the element
|
||||
* @param headless true if the element needs no starting tag
|
||||
* @param tailless true if the element needs no closing tag
|
||||
* @param content the element content.
|
||||
* @param exclusions the elements that must be excluded from the
|
||||
* content of this element, in all levels of the hierarchy.
|
||||
* @param inclusions the elements that can be included as the
|
||||
* content of this element.
|
||||
* @param attributes the element attributes.
|
||||
* @return the created or updated element.
|
||||
*/
|
||||
protected Element defElement(String name, int type, boolean headless,
|
||||
boolean tailless, ContentModel content,
|
||||
String[] exclusions, String[] inclusions,
|
||||
AttributeList attributes
|
||||
)
|
||||
{
|
||||
// compute the bit sets
|
||||
BitSet exclude = bitSet(exclusions);
|
||||
BitSet include = bitSet(inclusions);
|
||||
|
||||
Element e =
|
||||
defineElement(name, type, headless, tailless, content, exclude, include,
|
||||
attributes
|
||||
);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates, intializes and adds to the entity table the new
|
||||
* entity.
|
||||
* @param name the name of the entity
|
||||
* @param type the type of the entity
|
||||
* @param data the data section of the entity
|
||||
* @return the created entity
|
||||
*/
|
||||
protected Entity defEntity(String name, int type, String data)
|
||||
{
|
||||
Entity e = newEntity(name, type);
|
||||
e.data = data.toCharArray();
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
private void assignField(Element e)
|
||||
{
|
||||
String element_name = e.name;
|
||||
try
|
||||
{
|
||||
// Assign the field via reflection.
|
||||
Field f = getClass().getField(element_name.toLowerCase());
|
||||
if ((f.getModifiers() & Modifier.PUBLIC) != 0)
|
||||
if ((f.getModifiers() & Modifier.STATIC) == 0)
|
||||
if (f.getType().isAssignableFrom(e.getClass()))
|
||||
f.set(this, e);
|
||||
}
|
||||
catch (IllegalAccessException ex)
|
||||
{
|
||||
unexpected(ex);
|
||||
}
|
||||
catch (NoSuchFieldException ex)
|
||||
{
|
||||
// This is ok.
|
||||
}
|
||||
|
||||
// Some virtual machines may still lack the proper
|
||||
// implementation of reflection. As the tag fields
|
||||
// are not used anywhere in this implementation,
|
||||
// (and this class is also rarely used by the end user),
|
||||
// it may be better not to crash everything by throwing an error
|
||||
// for each case when the HTML parsing is required.
|
||||
catch (Throwable t)
|
||||
{
|
||||
// This VM has no reflection mechanism implemented!
|
||||
if (t instanceof OutOfMemoryError)
|
||||
throw (Error) t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the bit set for this array of elements.
|
||||
* The unknown elements are automatically defined and added
|
||||
* to the element table.
|
||||
* @param elements
|
||||
* @return
|
||||
*/
|
||||
private BitSet bitSet(String[] elements)
|
||||
{
|
||||
BitSet b = new BitSet();
|
||||
|
||||
for (int i = 0; i < elements.length; i++)
|
||||
{
|
||||
Element e = getElement(elements [ i ]);
|
||||
|
||||
if (e == null)
|
||||
e = newElement(elements [ i ]);
|
||||
|
||||
b.set(e.index);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the element with the given name in the element table.
|
||||
* If not find, create a new element with this name and add to the
|
||||
* table.
|
||||
* @param name the name of the element
|
||||
* @return the found or created element.
|
||||
*/
|
||||
private Element newElement(String name)
|
||||
{
|
||||
Element e = (Element) elementHash.get(name.toLowerCase());
|
||||
|
||||
if (e == null)
|
||||
{
|
||||
e = new Element();
|
||||
e.name = name;
|
||||
e.index = elements.size();
|
||||
elements.add(e);
|
||||
elementHash.put(e.name.toLowerCase(), e);
|
||||
assignField(e);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and adds to the element table the entity with an
|
||||
* unitialized data section. Used internally.
|
||||
* @param name the name of the entity
|
||||
* @param type the type of the entity, a bitwise combination
|
||||
* of GENERAL, PARAMETER, SYSTEM and PUBLIC.
|
||||
* @throws an error if the parameter is both GENERAL and PARAMETER
|
||||
* of both PUBLIC and SYSTEM.
|
||||
* @return the created entity
|
||||
*/
|
||||
private Entity newEntity(String name, int type)
|
||||
{
|
||||
Entity e = new Entity(name, type, null);
|
||||
entityHash.put(e.name, e);
|
||||
return e;
|
||||
}
|
||||
|
||||
private void unexpected(Exception ex)
|
||||
{
|
||||
throw new Error("This should never happen, report a bug", ex);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue