GrokErrorHandler.java

  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) 2019 Jeremy Long. All Rights Reserved.
  17.  */
  18. package org.owasp.dependencycheck.xml.assembly;

  19. import javax.annotation.concurrent.ThreadSafe;
  20. import org.owasp.dependencycheck.utils.XmlUtils;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.xml.sax.ErrorHandler;
  24. import org.xml.sax.SAXException;
  25. import org.xml.sax.SAXParseException;

  26. /**
  27.  * An XML parsing error handler.
  28.  *
  29.  * @author Jeremy Long
  30.  */
  31. @ThreadSafe
  32. public class GrokErrorHandler implements ErrorHandler {

  33.     /**
  34.      * The logger.
  35.      */
  36.     private static final Logger LOGGER = LoggerFactory.getLogger(GrokErrorHandler.class);

  37.     /**
  38.      * Logs warnings.
  39.      *
  40.      * @param ex the warning to log
  41.      * @throws SAXException is never thrown
  42.      */
  43.     @Override
  44.     public void warning(SAXParseException ex) throws SAXException {
  45.         LOGGER.trace("", ex);
  46.     }

  47.     /**
  48.      * Handles errors.
  49.      *
  50.      * @param ex the error to handle
  51.      * @throws SAXException is always thrown
  52.      */
  53.     @Override
  54.     public void error(SAXParseException ex) throws SAXException {
  55.         throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
  56.     }

  57.     /**
  58.      * Handles fatal exceptions.
  59.      *
  60.      * @param ex a fatal exception
  61.      * @throws SAXException is always thrown
  62.      */
  63.     @Override
  64.     public void fatalError(SAXParseException ex) throws SAXException {
  65.         throw new SAXException(XmlUtils.getPrettyParseExceptionInfo(ex));
  66.     }
  67. }