KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > util > DefaultParserFeedback


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Claude Duguay
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/DefaultParserFeedback.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/01/02 16:24:58 $
10
// $Revision: 1.31 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.util;
28
29 import java.io.Serializable JavaDoc;
30
31 /**
32  * Default implementation of the HTMLParserFeedback interface.
33  * This implementation prints output to the console but users
34  * can implement their own classes to support alternate behavior.
35  *
36  * @see ParserFeedback
37  * @see FeedbackManager
38  */

39 public class DefaultParserFeedback
40     implements
41         ParserFeedback,
42         Serializable JavaDoc
43 {
44     /**
45      * Constructor argument for a quiet feedback.
46      */

47     public static final int QUIET = 0;
48
49     /**
50      * Constructor argument for a normal feedback.
51      */

52     public static final int NORMAL = 1;
53
54     /**
55      * Constructor argument for a debugging feedback.
56      */

57     public static final int DEBUG = 2;
58
59     /**
60      * Verbosity level.
61      * Corresponds to constructor arguments:
62      * <pre>
63      * DEBUG = 2;
64      * NORMAL = 1;
65      * QUIET = 0;
66      * </pre>
67      */

68     protected int mMode;
69
70     /**
71      * Construct a feedback object of the given type.
72      * @param mode The type of feedback:
73      * <pre>
74      * DEBUG - verbose debugging with stack traces
75      * NORMAL - normal messages
76      * QUIET - no messages
77      * </pre>
78      * @exception IllegalArgumentException if mode is not
79      * QUIET, NORMAL or DEBUG.
80      */

81     public DefaultParserFeedback (int mode)
82     {
83         if (mode<QUIET||mode>DEBUG)
84             throw new IllegalArgumentException JavaDoc (
85                 "illegal mode ("
86                 + mode
87                 + "), must be one of: QUIET, NORMAL, DEBUG");
88         mMode = mode;
89     }
90
91     /**
92      * Construct a NORMAL feedback object.
93      */

94     public DefaultParserFeedback ()
95     {
96         this (NORMAL);
97     }
98
99     /**
100      * Print an info message.
101      * @param message The message to print.
102      */

103     public void info (String JavaDoc message)
104     {
105         if (QUIET != mMode)
106             System.out.println ("INFO: " + message);
107     }
108
109     /**
110      * Print an warning message.
111      * @param message The message to print.
112      */

113     public void warning (String JavaDoc message)
114     {
115         if (QUIET != mMode)
116             System.out.println ("WARNING: " + message);
117     }
118
119     /**
120      * Print an error message.
121      * @param message The message to print.
122      * @param exception The exception for stack tracing.
123      */

124     public void error (String JavaDoc message, ParserException exception)
125     {
126         if (QUIET != mMode)
127         {
128             System.out.println ("ERROR: " + message);
129             if (DEBUG == mMode && (null != exception))
130                 exception.printStackTrace ();
131         }
132     }
133 }
134
135
Popular Tags