1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /** 6 * Licensed to the Apache Software Foundation (ASF) under one 7 * or more contributor license agreements. See the NOTICE file 8 * distributed with this work for additional information 9 * regarding copyright ownership. The ASF licenses this file 10 * to you under the Apache License, Version 2.0 (the 11 * "License"); you may not use this file except in compliance 12 * with the License. You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, 17 * software distributed under the License is distributed on an 18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 * KIND, either express or implied. See the License for the 20 * specific language governing permissions and limitations 21 * under the License. 22 */ 23 package com.sun.org.apache.xml.internal.security.utils; 24 25 import org.xml.sax.ErrorHandler; 26 import org.xml.sax.SAXException; 27 import org.xml.sax.SAXParseException; 28 29 /** 30 * This {@link org.xml.sax.ErrorHandler} does absolutely nothing but log 31 * the events. 32 * 33 * @author Christian Geuer-Pollmann 34 */ 35 public class IgnoreAllErrorHandler implements ErrorHandler { 36 37 /** {@link org.apache.commons.logging} logging facility */ 38 private static java.util.logging.Logger log = 39 java.util.logging.Logger.getLogger(IgnoreAllErrorHandler.class.getName()); 40 41 /** Field throwExceptions */ 42 private static final boolean warnOnExceptions = 43 System.getProperty("com.sun.org.apache.xml.internal.security.test.warn.on.exceptions", "false").equals("true"); 44 45 /** Field throwExceptions */ 46 private static final boolean throwExceptions = 47 System.getProperty("com.sun.org.apache.xml.internal.security.test.throw.exceptions", "false").equals("true"); 48 49 50 /** @inheritDoc */ 51 public void warning(SAXParseException ex) throws SAXException { 52 if (IgnoreAllErrorHandler.warnOnExceptions) { 53 log.log(java.util.logging.Level.WARNING, "", ex); 54 } 55 if (IgnoreAllErrorHandler.throwExceptions) { 56 throw ex; 57 } 58 } 59 60 61 /** @inheritDoc */ 62 public void error(SAXParseException ex) throws SAXException { 63 if (IgnoreAllErrorHandler.warnOnExceptions) { 64 log.log(java.util.logging.Level.SEVERE, "", ex); 65 } 66 if (IgnoreAllErrorHandler.throwExceptions) { 67 throw ex; 68 } 69 } 70 71 72 /** @inheritDoc */ 73 public void fatalError(SAXParseException ex) throws SAXException { 74 if (IgnoreAllErrorHandler.warnOnExceptions) { 75 log.log(java.util.logging.Level.WARNING, "", ex); 76 } 77 if (IgnoreAllErrorHandler.throwExceptions) { 78 throw ex; 79 } 80 } 81 }