/ org.htmlparser / src / org / htmlparser / util / SpecialHashtable.java
SpecialHashtable.java
  1  // HTMLParser Library $Name: v1_6_20060319 $ - A java-based parser for HTML
  2  // http://sourceforge.org/projects/htmlparser
  3  // Copyright (C) 2004 Derrick Oswald
  4  //
  5  // Revision Control Information
  6  //
  7  // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/SpecialHashtable.java,v $
  8  // $Author: derrickoswald $
  9  // $Date: 2004/01/02 16:24:58 $
 10  // $Revision: 1.5 $
 11  //
 12  // This library is free software; you can redistribute it and/or
 13  // modify it under the terms of the GNU Lesser General Public
 14  // License as published by the Free Software Foundation; either
 15  // version 2.1 of the License, or (at your option) any later version.
 16  //
 17  // This library is distributed in the hope that it will be useful,
 18  // but WITHOUT ANY WARRANTY; without even the implied warranty of
 19  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 20  // Lesser General Public License for more details.
 21  //
 22  // You should have received a copy of the GNU Lesser General Public
 23  // License along with this library; if not, write to the Free Software
 24  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 25  //
 26  
 27  package org.htmlparser.util;
 28  
 29  import java.util.Hashtable;
 30  
 31  /**
 32   * Acts like a regular HashTable, except some values are translated in get(String).
 33   * Specifically, <code>Tag.NULLVALUE</code> is translated to <code>null</code> and
 34   * <code>Tag.NOTHING</code> is translated to <code>""</code>.
 35   * This is done for backwards compatibility, users are expecting a HashTable,
 36   * but Tag.toHTML needs to know when there is no attribute value (&lt;<TAG ATTRIBUTE&gt;)
 37   * and when the value was not present (&lt;<TAG ATTRIBUTE=&gt;).
 38   */
 39  public class SpecialHashtable extends Hashtable
 40  {
 41      /**
 42       * Special key for the tag name.
 43       */
 44      public final static String TAGNAME = "$<TAGNAME>$";
 45  
 46      /**
 47       * Special value for a null attribute value.
 48       */
 49      public final static String NULLVALUE = "$<NULL>$";
 50  
 51      /**
 52       * Special value for an empty attribute value.
 53       */
 54      public final static String NOTHING = "$<NOTHING>$";
 55  
 56      /**
 57       * Constructs a new, empty hashtable with a default initial capacity (11)
 58       * and load factor, which is 0.75.
 59       */
 60      public SpecialHashtable ()
 61      {
 62          super ();
 63      }
 64  
 65      /**
 66       * Constructs a new, empty hashtable with the specified initial capacity
 67       * and default load factor, which is 0.75.
 68       */
 69      public SpecialHashtable (int initialCapacity)
 70      {
 71          super (initialCapacity);
 72      }
 73  
 74      /**
 75       * Constructs a new, empty hashtable with the specified initial capacity
 76       * and the specified load factor.
 77       */
 78      public SpecialHashtable (int initialCapacity, float loadFactor)
 79      {
 80          super (initialCapacity, loadFactor);
 81      }
 82  
 83      /**
 84       * Returns the value to which the specified key is mapped in this hashtable.
 85       * This is translated to provide backwards compatibility.
 86       * @return The translated value of the attribute. <em>This will be
 87       * <code>null</code> if the attribute is a stand-alone attribute.</em>
 88       */
 89      public Object get (Object key)
 90      {
 91          Object ret;
 92  
 93          ret = getRaw (key);
 94          if (NULLVALUE == ret)
 95              ret = null;
 96          else if (NOTHING == ret)
 97              ret = "";
 98  
 99          return (ret);
100      }
101  
102      /**
103       * Returns the raw (untranslated) value to which the specified key is
104       * mapped in this hashtable.
105       */
106      public Object getRaw (Object key)
107      {
108          return (super.get (key));
109      }
110  }