001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.xerces.xpointer;
018:
019: import java.io.PrintWriter;
020:
021: import org.apache.xerces.xni.XNIException;
022: import org.apache.xerces.xni.parser.XMLErrorHandler;
023: import org.apache.xerces.xni.parser.XMLParseException;
024:
025: /**
026: * The Default XPointer error handler used by the XInclude implementation.
027: * XPointer error's are thrown so that they may be caught by the XInclude
028: * implementation and reported as resource errors.
029: *
030: * @version $Id: XPointerErrorHandler.java 447248 2006-09-18 05:25:21Z mrglavas $
031: */
032: class XPointerErrorHandler implements XMLErrorHandler {
033:
034: //
035: // Data
036: //
037:
038: /** Print writer. */
039: protected PrintWriter fOut;
040:
041: //
042: // Constructors
043: //
044:
045: /**
046: * Constructs an error handler that prints error messages to
047: * <code>System.err</code>.
048: */
049: public XPointerErrorHandler() {
050: this (new PrintWriter(System.err));
051: } // <init>()
052:
053: /**
054: * Constructs an error handler that prints error messages to the
055: * specified <code>PrintWriter</code.
056: */
057: public XPointerErrorHandler(PrintWriter out) {
058: fOut = out;
059: } // <init>(PrintWriter)
060:
061: //
062: // ErrorHandler methods
063: //
064:
065: /** Warning. */
066: public void warning(String domain, String key, XMLParseException ex)
067: throws XNIException {
068: printError("Warning", ex);
069: } // warning(XMLParseException)
070:
071: /** Error. */
072: public void error(String domain, String key, XMLParseException ex)
073: throws XNIException {
074: printError("Error", ex);
075: //throw ex;
076: } // error(XMLParseException)
077:
078: /** Fatal error. */
079: public void fatalError(String domain, String key,
080: XMLParseException ex) throws XNIException {
081: printError("Fatal Error", ex);
082: throw ex;
083: } // fatalError(XMLParseException)
084:
085: //
086: // Private methods
087: //
088:
089: /** Prints the error message. */
090: private void printError(String type, XMLParseException ex) {
091:
092: fOut.print("[");
093: fOut.print(type);
094: fOut.print("] ");
095: String systemId = ex.getExpandedSystemId();
096: if (systemId != null) {
097: int index = systemId.lastIndexOf('/');
098: if (index != -1)
099: systemId = systemId.substring(index + 1);
100: fOut.print(systemId);
101: }
102: fOut.print(':');
103: fOut.print(ex.getLineNumber());
104: fOut.print(':');
105: fOut.print(ex.getColumnNumber());
106: fOut.print(": ");
107: fOut.print(ex.getMessage());
108: fOut.println();
109: fOut.flush();
110:
111: } // printError(String,SAXParseException)
112:
113: } // class DefaultErrorHandler
|