• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / ibatis-2 / #341

08 Sep 2023 11:16PM UTC coverage: 64.938% (+0.03%) from 64.913%
#341

push

github

web-flow
Merge pull request #183 from hazendaz/master

fixes #174, update GHA, maven wrapper, fix EOL markers, do not use star imports

5047 of 7772 relevant lines covered (64.94%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.63
/src/main/java/com/ibatis/sqlmap/engine/builder/xml/SqlMapClasspathEntityResolver.java
1
/*
2
 * Copyright 2004-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 com.ibatis.sqlmap.engine.builder.xml;
17

18
import com.ibatis.common.resources.Resources;
19

20
import java.io.IOException;
21
import java.io.InputStream;
22
import java.util.HashMap;
23
import java.util.Locale;
24
import java.util.Map;
25

26
import org.xml.sax.EntityResolver;
27
import org.xml.sax.InputSource;
28
import org.xml.sax.SAXException;
29

30
/**
31
 * Offline entity resolver for the iBATIS DTDs.
32
 */
33
public class SqlMapClasspathEntityResolver implements EntityResolver {
1✔
34

35
  /** The Constant SQL_MAP_CONFIG_DTD. */
36
  private static final String SQL_MAP_CONFIG_DTD = "com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd";
37

38
  /** The Constant SQL_MAP_DTD. */
39
  private static final String SQL_MAP_DTD = "com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd";
40

41
  /** The Constant doctypeMap. */
42
  private static final Map doctypeMap = new HashMap();
1✔
43

44
  static {
45
    doctypeMap.put("http://www.ibatis.com/dtd/sql-map-config-2.dtd".toUpperCase(Locale.ROOT), SQL_MAP_CONFIG_DTD);
1✔
46
    doctypeMap.put("http://ibatis.apache.org/dtd/sql-map-config-2.dtd".toUpperCase(Locale.ROOT), SQL_MAP_CONFIG_DTD);
1✔
47
    doctypeMap.put("-//iBATIS.com//DTD SQL Map Config 2.0//EN".toUpperCase(Locale.ROOT), SQL_MAP_CONFIG_DTD);
1✔
48
    doctypeMap.put("-//ibatis.apache.org//DTD SQL Map Config 2.0//EN".toUpperCase(Locale.ROOT), SQL_MAP_CONFIG_DTD);
1✔
49

50
    doctypeMap.put("http://www.ibatis.com/dtd/sql-map-2.dtd".toUpperCase(Locale.ROOT), SQL_MAP_DTD);
1✔
51
    doctypeMap.put("http://ibatis.apache.org/dtd/sql-map-2.dtd".toUpperCase(Locale.ROOT), SQL_MAP_DTD);
1✔
52
    doctypeMap.put("-//iBATIS.com//DTD SQL Map 2.0//EN".toUpperCase(Locale.ROOT), SQL_MAP_DTD);
1✔
53
    doctypeMap.put("-//ibatis.apache.org//DTD SQL Map 2.0//EN".toUpperCase(Locale.ROOT), SQL_MAP_DTD);
1✔
54
  }
1✔
55

56
  /**
57
   * Converts a public DTD into a local one
58
   *
59
   * @param publicId
60
   *          Unused but required by EntityResolver interface
61
   * @param systemId
62
   *          The DTD that is being requested
63
   *
64
   * @return The InputSource for the DTD
65
   *
66
   * @throws SAXException
67
   *           If anything goes wrong
68
   */
69
  public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
70

71
    if (publicId != null)
1✔
72
      publicId = publicId.toUpperCase(Locale.ROOT);
1✔
73
    if (systemId != null)
1✔
74
      systemId = systemId.toUpperCase(Locale.ROOT);
1✔
75

76
    InputSource source = null;
1✔
77
    try {
78
      String path = (String) doctypeMap.get(publicId);
1✔
79
      source = getInputSource(path, source);
1✔
80
      if (source == null) {
1✔
81
        path = (String) doctypeMap.get(systemId);
1✔
82
        source = getInputSource(path, source);
1✔
83
      }
84
    } catch (Exception e) {
×
85
      throw new SAXException(e.toString());
×
86
    }
1✔
87
    return source;
1✔
88
  }
89

90
  /**
91
   * Gets the input source.
92
   *
93
   * @param path
94
   *          the path
95
   * @param source
96
   *          the source
97
   *
98
   * @return the input source
99
   */
100
  private InputSource getInputSource(String path, InputSource source) {
101
    if (path != null) {
1✔
102
      InputStream in = null;
1✔
103
      try {
104
        in = Resources.getResourceAsStream(path);
1✔
105
        source = new InputSource(in);
1✔
106
      } catch (IOException e) {
×
107
        // ignore, null is ok
108
      }
1✔
109
    }
110
    return source;
1✔
111
  }
112

113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc