org.htmlparser.tags

Class LinkTag

Implemented Interfaces:
Cloneable, Node, Serializable, Tag

public class LinkTag
extends CompositeTag

Identifies a link tag.

Field Summary

protected String
mLink
The URL where the link points to

Fields inherited from class org.htmlparser.tags.CompositeTag

mDefaultCompositeScanner, mEndTag

Fields inherited from class org.htmlparser.nodes.TagNode

breakTags, mAttributes, mDefaultScanner

Fields inherited from class org.htmlparser.nodes.AbstractNode

children, mPage, nodeBegin, nodeEnd, parent

Constructor Summary

LinkTag()
Constructor creates an LinkTag object, which basically stores the location where the link points to, and the text it contains.

Method Summary

String
extractLink()
Extract the link from the HREF attribute.
String
getAccessKey()
Get the ACCESSKEY attribute, if any.
String[]
getEndTagEnders()
Return the set of end tag names that cause this tag to finish.
String[]
getEnders()
Return the set of tag names that cause this tag to finish.
String[]
getIds()
Return the set of names handled by this tag.
String
getLink()
Returns the url as a string, to which this link points.
String
getLinkText()
Returns the text contained inside this link tag.
boolean
isFTPLink()
Tests if the link is an FTP link.
boolean
isHTTPLikeLink()
Tests if the link is an HTTP link or one of its variations (HTTPS, etc.).
boolean
isHTTPLink()
Tests if the link is an HTTP link.
boolean
isHTTPSLink()
Tests if the link is an HTTPS link.
boolean
isIRCLink()
Tests if the link is an IRC link.
boolean
isJavascriptLink()
Tests if the link is javascript
boolean
isMailLink()
Is this a mail address
void
setJavascriptLink(boolean newJavascriptLink)
Set the link as a javascript link.
void
setLink(String link)
Set the HREF attribute.
void
setMailLink(boolean newMailLink)
Insert the method's description here.
String
toString()
Return the contents of this link node as a string suitable for debugging.

Methods inherited from class org.htmlparser.tags.CompositeTag

accept, childAt, children, collectInto, digupStringNode, elements, findPositionOf, findPositionOf, findPositionOf, getChild, getChildCount, getChildrenAsNodeArray, getChildrenHTML, getEndTag, getStringText, getText, putChildrenInto, putEndTagInto, removeChild, searchByName, searchFor, searchFor, searchFor, searchFor, setEndTag, toHtml, toPlainTextString, toString, toString

Methods inherited from class org.htmlparser.nodes.TagNode

accept, breaksFlow, getAttribute, getAttributeEx, getAttributesEx, getEndTag, getEndTagEnders, getEnders, getEndingLineNumber, getIds, getRawTagName, getStartingLineNumber, getTagBegin, getTagEnd, getTagName, getText, getThisScanner, isEmptyXmlTag, isEndTag, removeAttribute, setAttribute, setAttribute, setAttribute, setAttributeEx, setAttributesEx, setEmptyXmlTag, setEndTag, setTagBegin, setTagEnd, setTagName, setText, setThisScanner, toHtml, toPlainTextString, toString

Methods inherited from class org.htmlparser.nodes.AbstractNode

accept, clone, collectInto, doSemanticAction, getChildren, getEndPosition, getFirstChild, getLastChild, getNextSibling, getPage, getParent, getPreviousSibling, getStartPosition, getText, setChildren, setEndPosition, setPage, setParent, setStartPosition, setText, toHtml, toHtml, toPlainTextString, toString

Field Details

mLink

protected String mLink
The URL where the link points to

Constructor Details

LinkTag

public LinkTag()
Constructor creates an LinkTag object, which basically stores the location where the link points to, and the text it contains.

In order to get the contents of the link tag, use the method children(), which returns an enumeration of nodes encapsulated within the link.

The following code will get all the images inside a link tag.

 Node node ;
 ImageTag imageTag;
 for (Enumeration e=linkTag.children();e.hasMoreElements();) {
      node = (Node)e.nextElement();
      if (node instanceof ImageTag) {
          imageTag = (ImageTag)node;
          // Process imageTag
      }
 }
 

Method Details

extractLink

public String extractLink()
Extract the link from the HREF attribute.
Returns:
The URL from the HREF attibute. This is absolute if the tag has a valid page.

getAccessKey

public String getAccessKey()
Get the ACCESSKEY attribute, if any.
Returns:
The value of the ACCESSKEY attribute, or null if the attribute doesn't exist.

getEndTagEnders

public String[] getEndTagEnders()
Return the set of end tag names that cause this tag to finish.
Specified by:
getEndTagEnders in interface Tag
Overrides:
getEndTagEnders in interface TagNode
Returns:
The names of following end tags that stop further scanning.

getEnders

public String[] getEnders()
Return the set of tag names that cause this tag to finish.
Specified by:
getEnders in interface Tag
Overrides:
getEnders in interface TagNode
Returns:
The names of following tags that stop further scanning.

getIds

public String[] getIds()
Return the set of names handled by this tag.
Specified by:
getIds in interface Tag
Overrides:
getIds in interface TagNode
Returns:
The names to be matched that create tags of this type.

getLink

public String getLink()
Returns the url as a string, to which this link points. This string has had the "mailto:" and "javascript:" protocol stripped off the front (if those predicates return true) but not for other protocols. Don't ask me why, it's a legacy thing.
Returns:
The URL for this A tag.

getLinkText

public String getLinkText()
Returns the text contained inside this link tag.
Returns:
The textual contents between the pair.

isFTPLink

public boolean isFTPLink()
Tests if the link is an FTP link.
Returns:
flag indicating if this link is an FTP link

isHTTPLikeLink

public boolean isHTTPLikeLink()
Tests if the link is an HTTP link or one of its variations (HTTPS, etc.).
Returns:
flag indicating if this link is an HTTP link or one of its variations (HTTPS, etc.)

isHTTPLink

public boolean isHTTPLink()
Tests if the link is an HTTP link.
Returns:
flag indicating if this link is an HTTP link

isHTTPSLink

public boolean isHTTPSLink()
Tests if the link is an HTTPS link.
Returns:
flag indicating if this link is an HTTPS link

isIRCLink

public boolean isIRCLink()
Tests if the link is an IRC link.
Returns:
flag indicating if this link is an IRC link

isJavascriptLink

public boolean isJavascriptLink()
Tests if the link is javascript
Returns:
flag indicating if the link is a javascript code

isMailLink

public boolean isMailLink()
Is this a mail address
Returns:
boolean true/false

setJavascriptLink

public void setJavascriptLink(boolean newJavascriptLink)
Set the link as a javascript link.
Parameters:
newJavascriptLink - flag indicating if the link is a javascript code

setLink

public void setLink(String link)
Set the HREF attribute.
Parameters:
link - The new value of the HREF attribute.

setMailLink

public void setMailLink(boolean newMailLink)
Insert the method's description here. Creation date: (8/3/2001 1:49:31 AM)
Parameters:
newMailLink - boolean

toString

public String toString()
Return the contents of this link node as a string suitable for debugging.
Specified by:
toString in interface Node
Overrides:
toString in interface CompositeTag
Returns:
A string representation of this node.

HTML Parser is an open source library released under LGPL. SourceForge.net