Java Reference
In-Depth Information
* Process an individual option tag. Store the state name
* and code to a list.
* @param name The name of the option.
* @param value The value of the option.
*/
private void processOption(String name, String value)
{
StringBuilder result = new StringBuilder();
result.append('\"');
result.append(name);
result.append("\",\"");
result.append(value);
result.append('\"');
System.out.println(result.toString());
}
/**
* Process the specified URL and parse an option list.
* @param url The URL to process.
* @param optionList Which option list to process, zero for
* the first one.
* @throws IOException Thrown if the page cannot be read.
*/
public void process(URL url, int optionList) throws IOException
{
String value = "";
InputStream is = url.openStream();
ParseHTML parse = new ParseHTML(is);
StringBuilder buffer = new StringBuilder();
int ch;
while ((ch = parse.read()) != -1)
{
if (ch == 0)
{
HTMLTag tag = parse.getTag();
if (tag.getName().equalsIgnoreCase("a"))
{
value = tag.getAttributeValue("href");
URL u = new URL(url, value.toString());
value = u.toString();
buffer.setLength(0);
} else if (tag.getName().equalsIgnoreCase("/a"))
{
processOption(buffer.toString(), value);
}
Search WWH ::




Custom Search