View Javadoc
1   /*
2    * This file is part of dependency-check-core.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.xml.suppression;
19  
20  import javax.annotation.concurrent.ThreadSafe;
21  import org.owasp.dependencycheck.utils.XmlUtils;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.xml.sax.ErrorHandler;
25  import org.xml.sax.SAXException;
26  import org.xml.sax.SAXParseException;
27  
28  /**
29   * An XML parsing error handler.
30   *
31   * @author Jeremy Long
32   */
33  @ThreadSafe
34  public class SuppressionErrorHandler implements ErrorHandler {
35  
36      /**
37       * The logger.
38       */
39      private static final Logger LOGGER = LoggerFactory.getLogger(SuppressionErrorHandler.class);
40  
41      /**
42       * Logs warnings.
43       *
44       * @param ex the warning to log
45       * @throws SAXException is never thrown
46       */
47      @Override
48      public void warning(SAXParseException ex) throws SAXException {
49          LOGGER.trace("", ex);
50      }
51  
52      /**
53       * Handles errors.
54       *
55       * @param ex the error to handle
56       * @throws SAXException is always thrown
57       */
58      @Override
59      public void error(SAXParseException ex) throws SAXException {
60          throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
61      }
62  
63      /**
64       * Handles fatal exceptions.
65       *
66       * @param ex a fatal exception
67       * @throws SAXException is always thrown
68       */
69      @Override
70      public void fatalError(SAXParseException ex) throws SAXException {
71          throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
72      }
73  }