[Htmlparser-cvs] htmlparser/src/org/htmlparser/tags FormTag.java,1.28,1.29 ImageTag.java,1.21,1.22 L
Brought to you by:
derrickoswald
|
From: <der...@us...> - 2003-08-15 21:03:18
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags
In directory sc8-pr-cvs1:/tmp/cvs-serv3543/tags
Modified Files:
FormTag.java ImageTag.java LinkTag.java Tag.java
Log Message:
Case maintaining toHtml() output for tag attributes.
With these changes, the output of toHtml() now reflects the upper/lower case values
of the input for the contents of tags, i.e. attribute names maintain their original case.
They're still out of order from how they are parsed, but this is a first step.
Rather than adjust all the test cases right now, the ParserTestCase assertSameString()
method now checks a global flag to see if case matters when comparing strings.
As of this drop it ignores case when comparing HTML output. This will soon change.
Index: FormTag.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/FormTag.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** FormTag.java 11 Aug 2003 00:18:30 -0000 1.28
--- FormTag.java 15 Aug 2003 20:51:48 -0000 1.29
***************
*** 142,146 ****
*/
public void setFormLocation(String formURL) {
! attributes.put("ACTION",formURL);
this.formURL = formURL;
}
--- 142,146 ----
*/
public void setFormLocation(String formURL) {
! setAttribute ("ACTION", formURL);
this.formURL = formURL;
}
Index: ImageTag.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/ImageTag.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** ImageTag.java 11 Aug 2003 00:18:30 -0000 1.21
--- ImageTag.java 15 Aug 2003 20:51:48 -0000 1.22
***************
*** 68,72 ****
public void setImageURL(String imageURL) {
this.imageURL = imageURL;
! attributes.put("SRC",imageURL);
}
--- 68,72 ----
public void setImageURL(String imageURL) {
this.imageURL = imageURL;
! setAttribute ("SRC", imageURL);
}
Index: LinkTag.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/LinkTag.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** LinkTag.java 11 Aug 2003 00:18:30 -0000 1.28
--- LinkTag.java 15 Aug 2003 20:51:48 -0000 1.29
***************
*** 231,235 ****
public void setLink(String link) {
this.link = link;
! attributes.put("HREF",link);
}
--- 231,235 ----
public void setLink(String link) {
this.link = link;
! setAttribute ("HREF", link);
}
Index: Tag.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/Tag.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** Tag.java 11 Aug 2003 00:18:30 -0000 1.39
--- Tag.java 15 Aug 2003 20:51:48 -0000 1.40
***************
*** 64,68 ****
private final static String EMPTY_STRING="";
- private AttributeParser attributeParser;
private static TagParser tagParser;
/**
--- 64,67 ----
***************
*** 76,80 ****
* added by Kaarle Kaila 23.10.2001
*/
! protected Hashtable attributes=null;
/**
--- 75,79 ----
* added by Kaarle Kaila 23.10.2001
*/
! protected SpecialHashtable _attributes=null;
/**
***************
*** 177,183 ****
* @return Hashtable
*/
! private Hashtable parseAttributes(){
! attributeParser = new AttributeParser();
! return attributeParser.parseAttributes(this);
}
--- 176,181 ----
* @return Hashtable
*/
! private SpecialHashtable parseAttributes(){
! return (SpecialHashtable)(new AttributeParser()).parseAttributes(getText ());
}
***************
*** 187,192 ****
* @param name of parameter
*/
! public String getAttribute(String name){
! return (String)getAttributes().get(name.toUpperCase());
}
--- 185,205 ----
* @param name of parameter
*/
! public String getAttribute(String name)
! {
! SpecialHashtable ht;
! Object ret;
!
! ht = getAttributesEx();
! ret = ht.getRaw(name.toUpperCase());
! if (null != ret)
! {
! ret = ((String[])ret)[1];
! if (Tag.NULLVALUE == ret)
! ret = null;
! else if (Tag.NOTHING == ret)
! ret = "";
! }
!
! return ((String)ret);
}
***************
*** 197,201 ****
*/
public void setAttribute(String key, String value) {
! attributes.put(key,value);
}
--- 210,214 ----
*/
public void setAttribute(String key, String value) {
! _attributes.put(key.toUpperCase (), new String[] {key, value});
}
***************
*** 207,226 ****
*/
public String getParameter(String name){
! return (String)getAttributes().get(name.toUpperCase());
}
/**
* Gets the attributes in the tag.
* @return Returns a Hashtable of attributes
*/
! public Hashtable getAttributes() {
! if (attributes == null) {
! attributes = parseAttributes();
! }
! return attributes;
}
! public String getTagName(){
! return (String)getAttributes().get(TAGNAME);
}
--- 220,259 ----
*/
public String getParameter(String name){
! return ((String[])getAttributesEx().get(name.toUpperCase()))[1];
}
/**
* Gets the attributes in the tag.
+ * NOTE: Values of the extended hashtable are two element arrays of String,
+ * with the first element being the original name (not uppercased),
+ * and the second element being the value.
+ * @return Returns a special hashtable of attributes in two element String arrays.
+ */
+ public SpecialHashtable getAttributesEx() {
+ if (_attributes == null)
+ _attributes = parseAttributes();
+ return _attributes;
+ }
+
+ /**
+ * Gets the attributes in the tag.
* @return Returns a Hashtable of attributes
*/
! public Hashtable getAttributes()
! {
! Hashtable ret;
!
! ret = new SpecialHashtable ();
! for (Enumeration e = getAttributesEx ().keys(); e.hasMoreElements(); )
! {
! String key = (String)e.nextElement ();
! ret.put (key, ((String[])getAttributesEx().getRaw(key))[1]);
! }
!
! return (ret);
}
! public String getTagName(){
! return getParameter(TAGNAME);
}
***************
*** 329,340 ****
/**
! * Sets the parsed.
! * @param parsed The parsed to set
*/
! public void setAttributes(Hashtable attributes) {
! this.attributes = attributes;
}
/**
* Sets the nodeBegin.
* @param nodeBegin The nodeBegin to set
--- 362,392 ----
/**
! * Sets the attributes.
! * @param attributes The attribute collection to set.
*/
! public void setAttributes(Hashtable attributes)
! {
! SpecialHashtable att = new SpecialHashtable ();
! for (Enumeration e = attributes.keys (); e.hasMoreElements (); )
! {
! String key = (String)e.nextElement ();
! att.put (key, new String[] { key, (String)attributes.get (key)});
! }
! this._attributes = att;
}
/**
+ * Sets the attributes.
+ * NOTE: Values of the extended hashtable are two element arrays of String,
+ * with the first element being the original name (not uppercased),
+ * and the second element being the value.
+ * @param attributes The attribute collection to set.
+ */
+ public void setAttributesEx (SpecialHashtable attributes)
+ {
+ _attributes = attributes;
+ }
+
+ /**
* Sets the nodeBegin.
* @param nodeBegin The nodeBegin to set
***************
*** 420,431 ****
StringBuffer ret;
String key;
! String value;
String empty;
ret = new StringBuffer ();
ret.append ("<");
! ret.append (getTagName ());
empty = null;
! for (Enumeration e = attributes.keys(); e.hasMoreElements(); )
{
key = (String)e.nextElement ();
--- 472,484 ----
StringBuffer ret;
String key;
! String value[];
String empty;
ret = new StringBuffer ();
+ value = (String[])(getAttributesEx().getRaw (TAGNAME));
ret.append ("<");
! ret.append (value[1]);
empty = null;
! for (Enumeration e = getAttributesEx ().keys(); e.hasMoreElements(); )
{
key = (String)e.nextElement ();
***************
*** 437,449 ****
{
ret.append (" ");
! ret.append (key);
! value = (String)(((SpecialHashtable)getAttributes()).getRaw (key.toUpperCase ()));
! if (Tag.NULLVALUE != value)
{
ret.append ("=");
! if (!(Tag.NOTHING == value))
{
ret.append ("\"");
! ret.append (value);
ret.append ("\"");
}
--- 490,502 ----
{
ret.append (" ");
! value = (String[])(getAttributesEx().getRaw (key.toUpperCase ()));
! ret.append (value[0]);
! if (Tag.NULLVALUE != value[1])
{
ret.append ("=");
! if (!(Tag.NOTHING == value[1]))
{
ret.append ("\"");
! ret.append (value[1]);
ret.append ("\"");
}
***************
*** 507,511 ****
*/
public Hashtable getParsed() {
! return attributes;
}
--- 560,564 ----
*/
public Hashtable getParsed() {
! return getAttributes ();
}
***************
*** 519,524 ****
* @return Hashtable
*/
! public Hashtable redoParseAttributes() {
! return parseAttributes();
}
--- 572,580 ----
* @return Hashtable
*/
! public Hashtable redoParseAttributes()
! {
! _attributes = null;
! getAttributesEx ();
! return (getAttributes ());
}
|