Save This Page
Home » openjdk-7 » javax » swing » text » html » parser » [javadoc | source]
    1   /*
    2    * Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   package javax.swing.text.html.parser;
   27   
   28   import java.util.Hashtable;
   29   import java.util.BitSet;
   30   import java.io;
   31   
   32   /**
   33    * An element as described in a DTD using the ELEMENT construct.
   34    * This is essentiall the description of a tag. It describes the
   35    * type, content model, attributes, attribute types etc. It is used
   36    * to correctly parse a document by the Parser.
   37    *
   38    * @see DTD
   39    * @see AttributeList
   40    * @author Arthur van Hoff
   41    */
   42   public final
   43   class Element implements DTDConstants, Serializable {
   44       public int index;
   45       public String name;
   46       public boolean oStart;
   47       public boolean oEnd;
   48       public BitSet inclusions;
   49       public BitSet exclusions;
   50       public int type = ANY;
   51       public ContentModel content;
   52       public AttributeList atts;
   53   
   54       static int maxIndex = 0;
   55   
   56       /**
   57        * A field to store user data. Mostly used to store
   58        * style sheets.
   59        */
   60       public Object data;
   61   
   62       Element() {
   63       }
   64   
   65       /**
   66        * Create a new element.
   67        */
   68       Element(String name, int index) {
   69           this.name = name;
   70           this.index = index;
   71           maxIndex = Math.max(maxIndex, index);
   72       }
   73   
   74       /**
   75        * Get the name of the element.
   76        */
   77       public String getName() {
   78           return name;
   79       }
   80   
   81       /**
   82        * Return true if the start tag can be omitted.
   83        */
   84       public boolean omitStart() {
   85           return oStart;
   86       }
   87   
   88       /**
   89        * Return true if the end tag can be omitted.
   90        */
   91       public boolean omitEnd() {
   92           return oEnd;
   93       }
   94   
   95       /**
   96        * Get type.
   97        */
   98       public int getType() {
   99           return type;
  100       }
  101   
  102       /**
  103        * Get content model
  104        */
  105       public ContentModel getContent() {
  106           return content;
  107       }
  108   
  109       /**
  110        * Get the attributes.
  111        */
  112       public AttributeList getAttributes() {
  113           return atts;
  114       }
  115   
  116       /**
  117        * Get index.
  118        */
  119       public int getIndex() {
  120           return index;
  121       }
  122   
  123       /**
  124        * Check if empty
  125        */
  126       public boolean isEmpty() {
  127           return type == EMPTY;
  128       }
  129   
  130       /**
  131        * Convert to a string.
  132        */
  133       public String toString() {
  134           return name;
  135       }
  136   
  137       /**
  138        * Get an attribute by name.
  139        */
  140       public AttributeList getAttribute(String name) {
  141           for (AttributeList a = atts ; a != null ; a = a.next) {
  142               if (a.name.equals(name)) {
  143                   return a;
  144               }
  145           }
  146           return null;
  147       }
  148   
  149       /**
  150        * Get an attribute by value.
  151        */
  152       public AttributeList getAttributeByValue(String name) {
  153           for (AttributeList a = atts ; a != null ; a = a.next) {
  154               if ((a.values != null) && a.values.contains(name)) {
  155                   return a;
  156               }
  157           }
  158           return null;
  159       }
  160   
  161   
  162       static Hashtable contentTypes = new Hashtable();
  163   
  164       static {
  165           contentTypes.put("CDATA", Integer.valueOf(CDATA));
  166           contentTypes.put("RCDATA", Integer.valueOf(RCDATA));
  167           contentTypes.put("EMPTY", Integer.valueOf(EMPTY));
  168           contentTypes.put("ANY", Integer.valueOf(ANY));
  169       }
  170   
  171       public static int name2type(String nm) {
  172           Integer val = (Integer)contentTypes.get(nm);
  173           return (val != null) ? val.intValue() : 0;
  174       }
  175   }

Save This Page
Home » openjdk-7 » javax » swing » text » html » parser » [javadoc | source]