Feedback Mechanism

The parser has a feedback mechanism that allows you to obtain feedback about the parsing process. You can get to know if there were any errors, or any warnings, or any general information. Warnings occur when the parser has encountered dirty html, but was able to fix it and continue. Errors occur when the parser was not able to handle the html.

An understanding of the feedback mechanism is useful if you wish to perform logging, or turn off the default feedback and incorporate your own.

When you create a parser object without specifying any feedback object, the parser creates a default feedback object - DefaultHTMLParserFeedback. This works in three modes - NORMAL, QUIET and DEBUG, and when no feedback object is specified, it defaults to normal. In this mode, all information, warnings and errors are sent to standard output.

    HTMLParser parser = new HTMLParser(someUrl);

    The above code snippet shows the default configuration - the feedback object is created in the normal mode. You can turn off the messages by turning the feedback mechanism to the quiet mode. This can be done in two ways :

    HTMLParser parser = new HTMLParser(someUrl,null);
    Java2html

    or

    HTMLParser parser = new HTMLParser(someUrl,new DefaultHTMLParserFeedback(DefaultHTMLParserFeedback.QUIET));

    In this mode, there is no feedback on standard output.
    For debugging purposes, you can use the debug mode to receive all stack traces of exceptions that are thrown.

    HTMLParser parser = new HTMLParser(someUrl,new DefaultHTMLParserFeedback(DefaultHTMLParserFeedback.DEBUG));

    If you wish to add a file logger- you can write your own custom feedback class like this :

    public class FileFeedback implements HTMLParserFeedback{
      public FileFeedback(String file) {
        // .. Initialize the file for logging
      }
      public void warning(String message) {
        // .. log the warning message
      }
      public void info(String message) {
        // .. log the info message
      }
      public void error(String message) {
        // .. log the error message
      }
    }

    You can supply an object of this type to the parser in the constructor, and accordingly channel the feedback.

    Last edited on Friday, March 21, 2003 11:51:12 am.