import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import javax.swing.text.ChangedCharSetException;
import javax.swing.text.html.parser.DTD;
import javax.swing.text.html.parser.Parser;
import javax.swing.text.html.parser.TagElement;

public class Browse extends Parser {
    public Browse(DTD dtd) {
	super(dtd);
    }

    protected void handleStartTag(TagElement tag) {
// 	try {
// 	    startTag(tag);
// 	} catch (ChangedCharSetException e) {
// 	    e.printStackTrace();
// 	}
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got start tag: " + tag.getHTMLTag());
    }

    protected void handleEndTag(TagElement tag) {
//	endTag(true);
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got end tag: " + tag.getHTMLTag());
    }

    protected  void handleEmptyTag(TagElement tag) {
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got empty tag: " + tag.getHTMLTag());
    }
           
    protected  void handleComment(char[] text) {
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got comment: " + new String(text));
    }
           
    protected  void handleText(char[] text) {
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got text: " + new String(text));
    }
           
    protected  void handleTitle(char[] text) {
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got title: " + new String(text));
    }
           
    protected  void handleEOFInComment() {
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got eof in comment");
    }

    protected  void handleError(int ln, String msg) {
	System.out.println(getCurrentLine() + ":" + getCurrentPos() + ": Got error at line " + ln + ": " + msg);
    }

    public static void main(String[] args) {
	try {
	    Reader in = new BufferedReader(new FileReader(args[0]));
	    Browse b = new Browse(DTD.getDTD("HTML 4.01"));
	    b.parse(in);
	} catch(IOException e) {
	    e.printStackTrace();
	}
    }
}
