edu.nrao.sss.html
Class HtmlAnchor

java.lang.Object
  extended by edu.nrao.sss.html.HtmlElement
      extended by edu.nrao.sss.html.HtmlAnchor

public class HtmlAnchor
extends HtmlElement

An HTML anchor (HTML.Tag.A).

Version Info:

$Revision: 1360 $
$Date: 2008-06-19 14:08:48 -0600 (Thu, 19 Jun 2008) $
$Author: dharland $

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

Field Summary
 
Fields inherited from class edu.nrao.sss.html.HtmlElement
NBSP_HTML, NBSP_TEXT, NBSP_UNICODE
 
Constructor Summary
HtmlAnchor()
          Creates a new, unnamed, empty anchor.
HtmlAnchor(String name, String href, String display)
          Creates a new HTML anchor with the given properties.
 
Method Summary
 String getDisplayText()
          Returns the text to display for this anchor.
 String getName()
          Returns the name of this anchor, if any.
 String getUrlText()
          Returns the HREF value for this anchor, if any.
 boolean hasName()
          Returns true if this anchor has a non-null value for the HTML.Attribute.NAME type.
 boolean hasUrlText()
          Return true if this anchor has a non-null value for the HTML.Attribute.HREF type.
 boolean isSimple()
          Returns true if this is a simple element.
static HtmlAnchor parse(String anchorTag)
          Creates and returns a new HTML anchor by parsing anchorTag.
 void setDisplayText(String text)
          Sets the text to display for this anchor.
 
Methods inherited from class edu.nrao.sss.html.HtmlElement
addAttribute, copyAttributesOf, getAttribute, getAttributes, getAttributeValue, getTag, removeAllAttributes, removeAttribute, writeHtmlTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HtmlAnchor

public HtmlAnchor()
Creates a new, unnamed, empty anchor.


HtmlAnchor

public HtmlAnchor(String name,
                  String href,
                  String display)
Creates a new HTML anchor with the given properties. The text form of this anchor is:
 <a name="name" href="href">display</a>
 

Parameters:
name - the name of this anchor. If this parameter is null, this anchor will have no name.
href - the HTML link associated with this anchor. If this parameter is null, this anchor will have no link.
display - the text displayed on an HTML page for this anchor. If this parameter is null, it will be converted to the empty string ("").
Method Detail

parse

public static HtmlAnchor parse(String anchorTag)
Creates and returns a new HTML anchor by parsing anchorTag.

Parameters:
anchorTag - the HTML form of this anchor. The expected form of the text is:
  <a name="name" href='absolute or relative URL'>display text</a>
The anchor name can be "a" or "A"; you may even mix the capitalization in a single tag (<A ...>...</a>). Values may be quoted with either single (') or double (") quotes. Leading and trailing whitespace is permitted and will be trimmed during parsing.

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

isSimple

public boolean isSimple()
Description copied from class: HtmlElement
Returns true if this is a simple element. A simple element is one that may not have content, such as the line break (<br/>) element.

Specified by:
isSimple in class HtmlElement
Returns:
true if this is a simple element.

setDisplayText

public void setDisplayText(String text)
Sets the text to display for this anchor.

Parameters:
text - the text to display for this anchor. If this parameter is null, it will be replaced by the empty string ("").

getDisplayText

public String getDisplayText()
Returns the text to display for this anchor.

Returns:
the text to display for this anchor. This value is guaranteed to be non-null, but it could be the empty string ("").

hasName

public boolean hasName()
Returns true if this anchor has a non-null value for the HTML.Attribute.NAME type.

Returns:
true if this anchor has a non-null name.

getName

public String getName()
Returns the name of this anchor, if any. If this anchor has no name, null is returned. This is a convenience method equivalent to the call getAttributeValue(HTML.Attribute.NAME).

Returns:
the name of this anchor, or null if this anchor has no name.

hasUrlText

public boolean hasUrlText()
Return true if this anchor has a non-null value for the HTML.Attribute.HREF type.

Returns:
true if this anchor has a non-null name.

getUrlText

public String getUrlText()
Returns the HREF value for this anchor, if any. If this anchor has no such value, null is returned. This is a convenience method equivalent to the call getAttributeValue(HTML.Attribute.NAME). Beware that the text returned may be only a relative URL, not the entire URL.

Returns:
the href value of this anchor, or null if this anchor has no such value.


Copyright © 2009. All Rights Reserved.