View Javadoc
1   /*
2    *    Copyright 2006-2023 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    *       https://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.SAXParseException;
24  
25  public class ParserErrorHandler implements ErrorHandler {
26  
27      private final List<String> warnings;
28  
29      private final List<String> errors;
30  
31      public ParserErrorHandler(List<String> warnings, List<String> errors) {
32          super();
33          this.warnings = warnings;
34          this.errors = errors;
35      }
36  
37      @Override
38      public void warning(SAXParseException exception) {
39          warnings.add(getString("Warning.7", //$NON-NLS-1$
40                  Integer.toString(exception.getLineNumber()), exception.getMessage()));
41      }
42  
43      @Override
44      public void error(SAXParseException exception) {
45          errors.add(getString("RuntimeError.4", //$NON-NLS-1$
46                  Integer.toString(exception.getLineNumber()), exception.getMessage()));
47      }
48  
49      @Override
50      public void fatalError(SAXParseException exception) {
51          errors.add(getString("RuntimeError.4", //$NON-NLS-1$
52                  Integer.toString(exception.getLineNumber()), exception.getMessage()));
53      }
54  }