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

mybatis / ibatis-2 / 730

28 Dec 2025 10:16PM UTC coverage: 65.615% (+0.5%) from 65.146%
730

push

github

web-flow
Update README.md

1602 of 2802 branches covered (57.17%)

5053 of 7701 relevant lines covered (65.61%)

0.66 hits per line

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

89.29
/src/main/java/com/ibatis/sqlmap/engine/builder/xml/SqlMapClasspathEntityResolver.java
1
/*
2
 * Copyright 2004-2025 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("https://ibatis.apache.org/dtd/sql-map-config-2.dtd".toUpperCase(Locale.ROOT), SQL_MAP_CONFIG_DTD);
1✔
46
    doctypeMap.put("-//ibatis.apache.org//DTD SQL Map Config 2.0//EN".toUpperCase(Locale.ROOT), SQL_MAP_CONFIG_DTD);
1✔
47

48
    doctypeMap.put("https://ibatis.apache.org/dtd/sql-map-2.dtd".toUpperCase(Locale.ROOT), SQL_MAP_DTD);
1✔
49
    doctypeMap.put("-//ibatis.apache.org//DTD SQL Map 2.0//EN".toUpperCase(Locale.ROOT), SQL_MAP_DTD);
1✔
50
  }
1✔
51

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

68
    if (publicId != null) {
1✔
69
      publicId = publicId.toUpperCase(Locale.ROOT);
1✔
70
    }
71
    if (systemId != null) {
1✔
72
      systemId = systemId.toUpperCase(Locale.ROOT);
1✔
73
    }
74

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

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

112
}
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