View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
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  package org.mybatis.generator.config.xml;
17  
18  import static org.mybatis.generator.internal.util.messages.Messages.getString;
19  
20  import java.util.List;
21  
22  import org.xml.sax.ErrorHandler;
23  import org.xml.sax.SAXException;
24  import org.xml.sax.SAXParseException;
25  
26  /**
27   * The Class ParserErrorHandler.
28   *
29   * @author Jeff Butler
30   */
31  public class ParserErrorHandler implements ErrorHandler {
32      
33      /** The warnings. */
34      private List<String> warnings;
35  
36      /** The errors. */
37      private List<String> errors;
38  
39      /**
40       * Instantiates a new parser error handler.
41       *
42       * @param warnings
43       *            the warnings
44       * @param errors
45       *            the errors
46       */
47      public ParserErrorHandler(List<String> warnings, List<String> errors) {
48          super();
49          this.warnings = warnings;
50          this.errors = errors;
51      }
52  
53      /*
54       * (non-Javadoc)
55       * 
56       * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
57       */
58      public void warning(SAXParseException exception) throws SAXException {
59          warnings.add(getString("Warning.7", //$NON-NLS-1$
60                  Integer.toString(exception.getLineNumber()), exception
61                          .getMessage()));
62      }
63  
64      /*
65       * (non-Javadoc)
66       * 
67       * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
68       */
69      public void error(SAXParseException exception) throws SAXException {
70          errors.add(getString("RuntimeError.4", //$NON-NLS-1$
71                  Integer.toString(exception.getLineNumber()), exception
72                          .getMessage()));
73      }
74  
75      /*
76       * (non-Javadoc)
77       * 
78       * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
79       */
80      public void fatalError(SAXParseException exception) throws SAXException {
81          errors.add(getString("RuntimeError.4", //$NON-NLS-1$
82                  Integer.toString(exception.getLineNumber()), exception
83                          .getMessage()));
84      }
85  }