KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > sax > Feedback


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/sax/Feedback.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/18 21:31:22 $
10
// $Revision: 1.2 $
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.sax;
28
29 import org.xml.sax.ErrorHandler JavaDoc;
30 import org.xml.sax.Locator JavaDoc;
31 import org.xml.sax.SAXParseException JavaDoc;
32
33 import org.htmlparser.util.ParserException;
34 import org.htmlparser.util.ParserFeedback;
35 import org.xml.sax.SAXException JavaDoc;
36
37 /**
38  * Mediates between the feedback mechanism of the htmlparser and an error handler.
39  */

40 public class Feedback
41     implements
42         ParserFeedback
43 {
44     /**
45      * The error handler to call back on.
46      */

47     protected ErrorHandler JavaDoc mErrorHandler;
48
49     /**
50      * The locator for tag positions.
51      */

52     protected Locator mLocator;
53
54     /**
55      * Create a feedback/error handler mediator.
56      * @param handler The callback object.
57      * @param locator A locator for error locations.
58      */

59     public Feedback (ErrorHandler JavaDoc handler, Locator locator)
60     {
61         mErrorHandler = handler;
62         mLocator = locator;
63     }
64
65     /**
66      * Information message.
67      * <em>Just eats the info message.</em>
68      * @param message {@inheritDoc}
69      */

70     public void info (String JavaDoc message)
71     {
72         // swallow
73
}
74
75     /**
76      * Warning message.
77      * Calls {@link ErrorHandler#warning(SAXParseException) ErrorHandler.warning}.
78      * @param message {@inheritDoc}
79      */

80     public void warning (String JavaDoc message)
81     {
82         try
83         {
84             mErrorHandler.warning (
85                 new SAXParseException JavaDoc (message, mLocator));
86         }
87         catch (SAXException JavaDoc se)
88         {
89             se.printStackTrace ();
90         }
91     }
92
93     /**
94      * Error message.
95      * Calls {@link ErrorHandler#error(SAXParseException) ErrorHandler.error}.
96      * @param message {@inheritDoc}
97      */

98     public void error (String JavaDoc message, ParserException e)
99     {
100         try
101         {
102             mErrorHandler.error (
103                 new SAXParseException JavaDoc (message, mLocator, e));
104         }
105         catch (SAXException JavaDoc se)
106         {
107             se.printStackTrace ();
108         }
109     }
110 }
111
Popular Tags