[Htmlparser-cvs] htmlparser/src/org/htmlparser/util SpecialHashtable.java,NONE,1.1 ParserUtils.java,
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-10-02 23:49:05
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util In directory sc8-pr-cvs1:/tmp/cvs-serv28867/util Modified Files: ParserUtils.java Added Files: SpecialHashtable.java Log Message: Moved SpecialHashTable to util. Fixed some attribute bugs and some test cases. --- NEW FILE: SpecialHashtable.java --- // HTMLParser Library v1_4_20030921 - A java-based parser for HTML // Copyright (C) Dec 31, 2000 Somik Raha // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library 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 // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // For any questions or suggestions, you can write to me at : // Email :so...@in... // // Postal Address : // Somik Raha // Extreme Programmer & Coach // Industrial Logic Corporation // 2583 Cedar Street, Berkeley, // CA 94708, USA // Website : http://www.industriallogic.com package org.htmlparser.util; import java.util.Hashtable; /** * Acts like a regular HashTable, except some values are translated in get(String). * Specifically, <code>Tag.NULLVALUE</code> is translated to <code>null</code> and * <code>Tag.NOTHING</code> is translated to <code>""</code>. * This is done for backwards compatibility, users are expecting a HashTable, * but Tag.toHTML needs to know when there is no attribute value (<<TAG ATTRIBUTE>) * and when the value was not present (<<TAG ATTRIBUTE=>). */ public class SpecialHashtable extends Hashtable { /** * Special key for the tag name. */ public final static String TAGNAME = "$<TAGNAME>$"; /** * Special value for a null attribute value. */ public final static String NULLVALUE = "$<NULL>$"; /** * Special value for an empty attribute value. */ public final static String NOTHING = "$<NOTHING>$"; /** * Constructs a new, empty hashtable with a default initial capacity (11) * and load factor, which is 0.75. */ public SpecialHashtable () { super (); } /** * Constructs a new, empty hashtable with the specified initial capacity * and default load factor, which is 0.75. */ public SpecialHashtable (int initialCapacity) { super (initialCapacity); } /** * Constructs a new, empty hashtable with the specified initial capacity * and the specified load factor. */ public SpecialHashtable (int initialCapacity, float loadFactor) { super (initialCapacity, loadFactor); } /** * Returns the value to which the specified key is mapped in this hashtable. * This is translated to provide backwards compatibility. * @return The translated value of the attribute. <em>This will be * <code>null</code> if the attribute is a stand-alone attribute.</em> */ public Object get (Object key) { Object ret; ret = getRaw (key); if (NULLVALUE == ret) ret = null; else if (NOTHING == ret) ret = ""; return (ret); } /** * Returns the raw (untranslated) value to which the specified key is * mapped in this hashtable. */ public Object getRaw (Object key) { return (super.get (key)); } } Index: ParserUtils.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/ParserUtils.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** ParserUtils.java 28 Sep 2003 15:33:59 -0000 1.31 --- ParserUtils.java 2 Oct 2003 23:48:54 -0000 1.32 *************** *** 40,44 **** public static String toString(Tag tag) { ! String tagName = tag.getAttribute(Tag.TAGNAME); Hashtable attrs = tag.getAttributes(); --- 40,44 ---- public static String toString(Tag tag) { ! String tagName = tag.getRawTagName (); Hashtable attrs = tag.getAttributes(); *************** *** 50,54 **** String key = (String) e.nextElement(); String value = (String) attrs.get(key); ! if (!key.equalsIgnoreCase(Tag.TAGNAME) && value.length() > 0) lString.append(key).append(" : ").append(value).append("\n"); } --- 50,54 ---- String key = (String) e.nextElement(); String value = (String) attrs.get(key); ! if (!key.equalsIgnoreCase(SpecialHashtable.TAGNAME) && value.length() > 0) lString.append(key).append(" : ").append(value).append("\n"); } |