📄 dtd.java
字号:
/* 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 modifyit under the terms of the GNU General Public License as published bythe 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, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception 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 * <a href="http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html" * >http://www.w3.org/TR/WD-html40-970708/intro/sgmltut.html</a>. * 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. * @specnote This was made <code>final</code> in 1.5. */ public static final 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 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -