1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2005 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package com.sun.org.apache.xerces.internal.xpointer; 21 22 import java.io.PrintWriter; 23 24 import com.sun.org.apache.xerces.internal.xni.XNIException; 25 import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; 26 import com.sun.org.apache.xerces.internal.xni.parser.XMLParseException; 27 28 /** 29 * The Default XPointer error handler used by the XInclude implementation. 30 * XPointer error's are thrown so that they may be caught by the XInclude 31 * implementation and reported as resource errors. 32 * 33 */ 34 class XPointerErrorHandler implements XMLErrorHandler { 35 36 // 37 // Data 38 // 39 40 /** Print writer. */ 41 protected PrintWriter fOut; 42 43 // 44 // Constructors 45 // 46 47 /** 48 * Constructs an error handler that prints error messages to 49 * <code>System.err</code>. 50 */ 51 public XPointerErrorHandler() { 52 this(new PrintWriter(System.err)); 53 } // <init>() 54 55 /** 56 * Constructs an error handler that prints error messages to the 57 * specified <code>PrintWriter</code. 58 */ 59 public XPointerErrorHandler(PrintWriter out) { 60 fOut = out; 61 } // <init>(PrintWriter) 62 63 // 64 // ErrorHandler methods 65 // 66 67 /** Warning. */ 68 public void warning(String domain, String key, XMLParseException ex) 69 throws XNIException { 70 printError("Warning", ex); 71 } // warning(XMLParseException) 72 73 /** Error. */ 74 public void error(String domain, String key, XMLParseException ex) 75 throws XNIException { 76 printError("Error", ex); 77 //throw ex; 78 } // error(XMLParseException) 79 80 /** Fatal error. */ 81 public void fatalError(String domain, String key, XMLParseException ex) 82 throws XNIException { 83 printError("Fatal Error", ex); 84 throw ex; 85 } // fatalError(XMLParseException) 86 87 // 88 // Private methods 89 // 90 91 /** Prints the error message. */ 92 private void printError(String type, XMLParseException ex) { 93 94 fOut.print("["); 95 fOut.print(type); 96 fOut.print("] "); 97 String systemId = ex.getExpandedSystemId(); 98 if (systemId != null) { 99 int index = systemId.lastIndexOf('/'); 100 if (index != -1) 101 systemId = systemId.substring(index + 1); 102 fOut.print(systemId); 103 } 104 fOut.print(':'); 105 fOut.print(ex.getLineNumber()); 106 fOut.print(':'); 107 fOut.print(ex.getColumnNumber()); 108 fOut.print(": "); 109 fOut.print(ex.getMessage()); 110 fOut.println(); 111 fOut.flush(); 112 113 } // printError(String,SAXParseException) 114 115 } // class DefaultErrorHandler