/**
* Pull out text elements from the HTML.
*/
public void parse() throws ParserException
{
Node node;
StringBuffer buffer = new StringBuffer(4096);
// Run through an enumeration of html elements, and pick up
// only those that are plain string.
for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
{
node = e.nextNode();
if (node instanceof StringNode)
{
// Node is a plain string
// Cast it to an HTMLStringNode
StringNode stringNode = (StringNode) node;
// Retrieve the data from the object
buffer.append(stringNode.getText());
}
else if (node instanceof LinkTag)
{
// Node is a link
// Cast it to an HTMLLinkTag
LinkTag linkNode = (LinkTag) node;
// Retrieve the data from the object and print it
buffer.append(linkNode.getLinkText());
}
else if (node instanceof Tag)
{
String contents = ((Tag) node).getText();
if (contents.equals("BR") || contents.equals("P"))
buffer.append(nl);
}
else if (node instanceof EndTag)
{
String contents = ((EndTag) node).getText();
if (contents.equals("BR") || contents.equals("P"))
buffer.append(nl);
}
else if (node instanceof RemarkNode)
{
}
else
{
System.out.println();
System.out.println(node.toString());
}
}
String text = translate(buffer.toString());
sgml(text);