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 */ 23package com.sun.org.apache.xml.internal.security.utils; 24 25import org.xml.sax.ErrorHandler; 26import org.xml.sax.SAXException; 27import 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 */ 35public class IgnoreAllErrorHandler implements ErrorHandler { 36 37 /** {@link org.apache.commons.logging} logging facility */ 38 private static final java.util.logging.Logger log = 39 java.util.logging.Logger.getLogger(IgnoreAllErrorHandler.class.getName()); 40 41 /** Field throwExceptions */ 42 private static final boolean warnOnExceptions = getProperty( 43 "com.sun.org.apache.xml.internal.security.test.warn.on.exceptions"); 44 45 /** Field throwExceptions */ 46 private static final boolean throwExceptions = getProperty( 47 "com.sun.org.apache.xml.internal.security.test.throw.exceptions"); 48 49 private static boolean getProperty(String name) { 50 return java.security.AccessController.doPrivileged( 51 new java.security.PrivilegedAction<Boolean>() { 52 53 @Override 54 public Boolean run() { 55 return Boolean.getBoolean(name); 56 } 57 }); 58 } 59 60 /** @inheritDoc */ 61 @Override 62 public void warning(SAXParseException ex) throws SAXException { 63 if (IgnoreAllErrorHandler.warnOnExceptions) { 64 log.log(java.util.logging.Level.WARNING, "", ex); 65 } 66 if (IgnoreAllErrorHandler.throwExceptions) { 67 throw ex; 68 } 69 } 70 71 72 /** @inheritDoc */ 73 @Override 74 public void error(SAXParseException ex) throws SAXException { 75 if (IgnoreAllErrorHandler.warnOnExceptions) { 76 log.log(java.util.logging.Level.SEVERE, "", ex); 77 } 78 if (IgnoreAllErrorHandler.throwExceptions) { 79 throw ex; 80 } 81 } 82 83 84 /** @inheritDoc */ 85 @Override 86 public void fatalError(SAXParseException ex) throws SAXException { 87 if (IgnoreAllErrorHandler.warnOnExceptions) { 88 log.log(java.util.logging.Level.WARNING, "", ex); 89 } 90 if (IgnoreAllErrorHandler.throwExceptions) { 91 throw ex; 92 } 93 } 94} 95