edu.nrao.sss.html
Class HtmlAttribute

java.lang.Object
  extended by edu.nrao.sss.html.HtmlAttribute

public class HtmlAttribute
extends Object

An attribute (see HTML.Attribute) of an HTML element.

Version Info:

$Revision: 545 $
$Date: 2007-04-19 10:38:45 -0600 (Thu, 19 Apr 2007) $
$Author: dharland $

Since:
2007-03-15
Author:
David M. Harland

Constructor Summary
HtmlAttribute(HTML.Attribute attrType)
          Creates a new HTML attribute of the given type and with a value of the empty string ("").
HtmlAttribute(HTML.Attribute attrType, String attrValue)
          Creates a new HTML attribute of the given type and value.
HtmlAttribute(String attrName, String attrValue)
          Creates a new HTML attribute of the given type and value.
 
Method Summary
 boolean equals(Object o)
          Returns true if o is equal to this attribute.
 HTML.Attribute getType()
          Returns the type of this attribute.
 String getValue()
          Returns the value of this attribute.
 int hashCode()
           
static HtmlAttribute parse(String nameValueText)
          Creates and returns a new HTML attribute by parsing nameValueText.
 void setValue(String newValue)
          Sets the value of this attribute.
 String toString()
          Returns a string of the form name="value".
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HtmlAttribute

public HtmlAttribute(String attrName,
                     String attrValue)
Creates a new HTML attribute of the given type and value.

Parameters:
attrName - the name, or type, of this attribute. This value must be a valid attribute name. Validity is determined by HTML.getAttributeKey(String). A list of known attribute names may be found in HTML.Attribute.

attrValue - the value of this attribute. See setValue(String) for the rules about this parameter.

HtmlAttribute

public HtmlAttribute(HTML.Attribute attrType,
                     String attrValue)
Creates a new HTML attribute of the given type and value.

Parameters:
attrType - the type of this attribute. If this parameter is null an IllegalArgumentException will be thrown.
attrValue - the value of this attribute. See setValue(String) for the rules about this parameter.

HtmlAttribute

public HtmlAttribute(HTML.Attribute attrType)
Creates a new HTML attribute of the given type and with a value of the empty string ("").

Parameters:
attrType - the type of this attribute. If this parameter is null an IllegalArgumentException will be thrown.
Method Detail

getType

public HTML.Attribute getType()
Returns the type of this attribute.

Returns:
the type of this attribute. This value is guaranteeed to be non-null.

setValue

public final void setValue(String newValue)
Sets the value of this attribute.

Parameters:
newValue - a new value for this attribute. If this parameter is null, it will be replaced by the empty string (""). This parameter may contain single quote (') or double quote (") characters, but not both. If it does, an IllegalArgumentException will be thrown and this attribute's value will be left in its present state.

getValue

public String getValue()
Returns the value of this attribute.

Returns:
the value of this attribute. This value is guaranteeed to be non-null, but could be an empty string ("").

parse

public static HtmlAttribute parse(String nameValueText)
Creates and returns a new HTML attribute by parsing nameValueText.

Parameters:
nameValueText - the HTML form of this attribute. The expected form of the text is:
  name="value"
Values may be quoted with either single (') or double (") quotes. Leading and trailing whitespace is permitted and will be trimmed during parsing. The name must be a valid attribute name. Validity is determined by HTML.getAttributeKey(String). A list of known attribute names may be found in HTML.Attribute.

Returns:
a new HTML attribute by parsing nameValueText.
Throws:
IllegalArgumentException - if anything goes wrong during parsing.

toString

public String toString()
Returns a string of the form name="value". If value itself contains double-quote characters, the returned string will be of the form name='value'.

Overrides:
toString in class Object

equals

public boolean equals(Object o)
Returns true if o is equal to this attribute.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2009. All Rights Reserved.