jdk/test/javax/xml/jaxp/testng/validation/8037819/SpecialCaseErrorHandler.java
changeset 27129 98b357b2e8a6
parent 27128 d1480cb49283
parent 27116 64a78dd93766
child 27130 41df50e7303d
equal deleted inserted replaced
27128:d1480cb49283 27129:98b357b2e8a6
     1 /*
       
     2  * Licensed to the Apache Software Foundation (ASF) under one or more
       
     3  * contributor license agreements.  See the NOTICE file distributed with
       
     4  * this work for additional information regarding copyright ownership.
       
     5  * The ASF licenses this file to You under the Apache License, Version 2.0
       
     6  * (the "License"); you may not use this file except in compliance with
       
     7  * the License.  You may obtain a copy of the License at
       
     8  *
       
     9  *      http://www.apache.org/licenses/LICENSE-2.0
       
    10  *
       
    11  * Unless required by applicable law or agreed to in writing, software
       
    12  * distributed under the License is distributed on an "AS IS" BASIS,
       
    13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14  * See the License for the specific language governing permissions and
       
    15  * limitations under the License.
       
    16  */
       
    17 
       
    18 import java.util.HashMap;
       
    19 
       
    20 import org.xml.sax.ErrorHandler;
       
    21 import org.xml.sax.SAXException;
       
    22 import org.xml.sax.SAXParseException;
       
    23 
       
    24 public class SpecialCaseErrorHandler implements ErrorHandler {
       
    25     public static final boolean DEBUG = false;
       
    26 
       
    27     private HashMap<String, Boolean> errors;
       
    28 
       
    29     public SpecialCaseErrorHandler(String[] specialCases) {
       
    30         errors = new HashMap<>();
       
    31         for (int i = 0; i < specialCases.length; ++i) {
       
    32             errors.put(specialCases[i], Boolean.FALSE);
       
    33         }
       
    34     }
       
    35 
       
    36     public void reset() {
       
    37         errors.keySet().stream().forEach((error) -> {
       
    38             errors.put(error, Boolean.FALSE);
       
    39         });
       
    40     }
       
    41 
       
    42     @Override
       
    43     public void warning(SAXParseException arg0) throws SAXException {
       
    44         if (DEBUG) {
       
    45             System.err.println(arg0.getMessage());
       
    46         }
       
    47     }
       
    48 
       
    49     @Override
       
    50     public void error(SAXParseException arg0) throws SAXException {
       
    51         if (DEBUG) {
       
    52             System.err.println(arg0.getMessage());
       
    53         }
       
    54         errors.keySet().stream().filter((error) -> (arg0.getMessage().startsWith(error))).forEach((error) -> {
       
    55             errors.put(error, Boolean.TRUE);
       
    56         });
       
    57     }
       
    58 
       
    59     public void fatalError(SAXParseException arg0) throws SAXException {
       
    60         throw arg0;
       
    61     }
       
    62 
       
    63     public boolean specialCaseFound(String key) {
       
    64         return ((Boolean) errors.get(key)).booleanValue();
       
    65     }
       
    66 }