public abstract class AbstractNode extends java.lang.Object implements Node, java.io.Serializable
Page, the
starting and ending position in the page, the parent and the list of
children.| 构造器和说明 |
|---|
AbstractNode(Page page,
int start,
int end)
Create an abstract node with the page positions given.
|
| 限定符和类型 | 方法和说明 |
|---|---|
abstract void |
accept(NodeVisitor visitor)
Visit this node.
|
java.lang.Object |
clone()
Clone this object.
|
void |
collectInto(NodeList list,
NodeFilter filter)
Collect this node and its child nodes (if-applicable) into the collectionList parameter, provided the node
satisfies the filtering criteria.
|
void |
doSemanticAction()
Perform the meaning of this tag.
|
NodeList |
getChildren()
Get the children of this node.
|
int |
getEndPosition()
Gets the ending position of the node.
|
Node |
getFirstChild()
Get the first child of this node.
|
Node |
getLastChild()
Get the last child of this node.
|
Node |
getNextSibling()
Get the next sibling to this node.
|
Page |
getPage()
Get the page this node came from.
|
Node |
getParent()
Get the parent of this node.
|
Node |
getPreviousSibling()
Get the previous sibling to this node.
|
int |
getStartPosition()
Gets the starting position of the node.
|
java.lang.String |
getText()
Returns the text of the node.
|
void |
setChildren(NodeList children)
Set the children of this node.
|
void |
setEndPosition(int position)
Sets the ending position of the node.
|
void |
setPage(Page page)
Set the page this node came from.
|
void |
setParent(Node node)
Sets the parent of this node.
|
void |
setStartPosition(int position)
Sets the starting position of the node.
|
void |
setText(java.lang.String text)
Sets the string contents of the node.
|
java.lang.String |
toHtml()
Return the HTML for this node.
|
abstract java.lang.String |
toHtml(boolean verbatim)
Return the HTML for this node.
|
abstract java.lang.String |
toPlainTextString()
Returns a string representation of the node.
|
abstract java.lang.String |
toString()
Return a string representation of the node.
|
public AbstractNode(Page page, int start, int end)
page - The page this tag was read from.start - The starting offset of this node within the page.end - The ending offset of this node within the page.public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
public abstract java.lang.String toPlainTextString()
Node node;
for (Enumeration e = parser.elements (); e.hasMoreElements (); )
{
node = (Node)e.nextElement();
System.out.println (node.toPlainTextString ());
// or do whatever processing you wish with the plain text string
}
toPlainTextString 在接口中 Nodepublic java.lang.String toHtml()
public abstract java.lang.String toHtml(boolean verbatim)
public abstract java.lang.String toString()
System.out.println(node)
public void collectInto(NodeList list, NodeFilter filter)
This mechanism allows powerful filtering code to be written very easily,
without bothering about collection of embedded tags separately.
e.g. when we try to get all the links on a page, it is not possible to
get it at the top-level, as many tags (like form tags), can contain
links embedded in them. We could get the links out by checking if the
current node is a CompositeTag, and going through its children.
So this method provides a convenient way to do this.
Using collectInto(), programs get a lot shorter. Now, the code to extract all links from a page would look like:
NodeList collectionList = new NodeList();
NodeFilter filter = new TagNameFilter ("A");
for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
e.nextNode().collectInto(collectionList, filter);
Thus, collectionList will hold all the link nodes, irrespective of how
deep the links are embedded.Another way to accomplish the same objective is:
NodeList collectionList = new NodeList();
NodeFilter filter = new TagClassFilter (LinkTag.class);
for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
e.nextNode().collectInto(collectionList, filter);
This is slightly less specific because the LinkTag class may be
registered for more than one node name, e.g. <LINK> tags too.collectInto 在接口中 Nodelist - The node list to collect acceptable nodes into.filter - The filter to determine which nodes are retained.public Page getPage()
getPage 在接口中 NodeNode.setPage(org.htmlparser.lexer.Page)public void setPage(Page page)
setPage 在接口中 Nodepage - The page that supplied this node.Node.getPage()public int getStartPosition()
getStartPosition 在接口中 NodeNode.setStartPosition(int)public void setStartPosition(int position)
setStartPosition 在接口中 Nodeposition - The new start position.Node.getStartPosition()public int getEndPosition()
getEndPosition 在接口中 NodeNode.setEndPosition(int)public void setEndPosition(int position)
setEndPosition 在接口中 Nodeposition - The new end position.Node.getEndPosition()public abstract void accept(NodeVisitor visitor)
public Node getParent()
CompositeTag.getParent 在接口中 Nodenull otherwise.Node.setParent(org.htmlparser.Node)public void setParent(Node node)
setParent 在接口中 Nodenode - The node that contains this node. Must be a CompositeTag.Node.getParent()public NodeList getChildren()
getChildren 在接口中 Nodenull otherwise.Node.setChildren(org.htmlparser.util.NodeList)public void setChildren(NodeList children)
setChildren 在接口中 Nodechildren - The new list of children this node contains.Node.getChildren()public Node getFirstChild()
getFirstChild 在接口中 Nodenull otherwise.public Node getLastChild()
getLastChild 在接口中 Nodenull otherwise.public Node getPreviousSibling()
getPreviousSibling 在接口中 Nodenull otherwise.public Node getNextSibling()
getNextSibling 在接口中 Nodenull otherwise.public java.lang.String getText()
getText 在接口中 Nodenull.Node.setText(java.lang.String)public void setText(java.lang.String text)
setText 在接口中 Nodetext - The new text for the node.Node.getText()public void doSemanticAction()
throws ParserException
doSemanticAction 在接口中 NodeParserException - Not used. Provides for subclasses
that may want to indicate an exceptional condition.