KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > xpointer > XPointerErrorHandler


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.sun.org.apache.xerces.internal.xpointer;
17
18 import java.io.PrintWriter JavaDoc;
19
20 import com.sun.org.apache.xerces.internal.xni.XNIException;
21 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler;
22 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException;
23
24 /**
25  * The Default XPointer error handler used by the XInclude implementation.
26  * XPointer error's are thrown so that they may be caught by the XInclude
27  * implementation and reported as resource errors.
28  *
29  * @version $Id: XPointerErrorHandler.java,v 1.1.4.1 2005/09/08 05:25:44 sunithareddy Exp $
30  */

31 class XPointerErrorHandler implements XMLErrorHandler {
32
33     //
34
// Data
35
//
36

37     /** Print writer. */
38     protected PrintWriter JavaDoc fOut;
39
40     //
41
// Constructors
42
//
43

44     /**
45      * Constructs an error handler that prints error messages to
46      * <code>System.err</code>.
47      */

48     public XPointerErrorHandler() {
49         this(new PrintWriter JavaDoc(System.err));
50     } // <init>()
51

52     /**
53      * Constructs an error handler that prints error messages to the
54      * specified <code>PrintWriter</code.
55      */

56     public XPointerErrorHandler(PrintWriter JavaDoc out) {
57         fOut = out;
58     } // <init>(PrintWriter)
59

60     //
61
// ErrorHandler methods
62
//
63

64     /** Warning. */
65     public void warning(String JavaDoc domain, String JavaDoc key, XMLParseException ex)
66             throws XNIException {
67         printError("Warning", ex);
68     } // warning(XMLParseException)
69

70     /** Error. */
71     public void error(String JavaDoc domain, String JavaDoc key, XMLParseException ex)
72             throws XNIException {
73         printError("Error", ex);
74         //throw ex;
75
} // error(XMLParseException)
76

77     /** Fatal error. */
78     public void fatalError(String JavaDoc domain, String JavaDoc key, XMLParseException ex)
79             throws XNIException {
80         printError("Fatal Error", ex);
81         throw ex;
82     } // fatalError(XMLParseException)
83

84     //
85
// Private methods
86
//
87

88     /** Prints the error message. */
89     private void printError(String JavaDoc type, XMLParseException ex) {
90
91         fOut.print("[");
92         fOut.print(type);
93         fOut.print("] ");
94         String JavaDoc systemId = ex.getExpandedSystemId();
95         if (systemId != null) {
96             int index = systemId.lastIndexOf('/');
97             if (index != -1)
98                 systemId = systemId.substring(index + 1);
99             fOut.print(systemId);
100         }
101         fOut.print(':');
102         fOut.print(ex.getLineNumber());
103         fOut.print(':');
104         fOut.print(ex.getColumnNumber());
105         fOut.print(": ");
106         fOut.print(ex.getMessage());
107         fOut.println();
108         fOut.flush();
109
110     } // printError(String,SAXParseException)
111

112 } // class DefaultErrorHandler
113
Popular Tags