Java Reference
In-Depth Information
Implementing ParseHTML
In this section we will examine how the ParseHTML class is implemented. The
ParseHTML class makes use of the PeekableInputStream class, which was dis-
cussed in the last section. The ParseHTML class is shown in Listing 6.2.
Listing 6.2: Parsing HTML (ParseHTML.java)
package com.heatonresearch.httprecipes.html;
import java.io.*;
import java.util.*;
public class ParseHTML
{
/*
* A mapping of certain HTML encoded values(i.e.  )
* to their actual character values.
*/
private static Map<String, Character> charMap;
/**
* The stream that we are parsing from.
*/
private PeekableInputStream source;
/**
* The current HTML tag. Access this property if the read
* function returns 0.
*/
private HTMLTag tag = new HTMLTag();
private String lockedEndTag;
/**
* The constructor should be passed an InputStream that we
* will parse from.
*
* @param is
* An InputStream to parse from.
*/
public ParseHTML(InputStream is)
{
this.source = new PeekableInputStream(is);
if (charMap == null)
Search WWH ::




Custom Search