• 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

91.43
/src/main/java/com/ibatis/common/xml/NodeletUtils.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.common.xml;
17

18
import java.util.Properties;
19

20
import org.w3c.dom.NamedNodeMap;
21
import org.w3c.dom.Node;
22

23
/**
24
 * The Class NodeletUtils.
25
 */
26
public class NodeletUtils {
×
27

28
  /**
29
   * Gets the boolean attribute.
30
   *
31
   * @param attribs
32
   *          the attribs
33
   * @param name
34
   *          the name
35
   * @param def
36
   *          the def
37
   *
38
   * @return the boolean attribute
39
   */
40
  public static boolean getBooleanAttribute(Properties attribs, String name, boolean def) {
41
    String value = attribs.getProperty(name);
1✔
42
    if (value == null) {
1✔
43
      return def;
1✔
44
    }
45
    return "true".equals(value);
1✔
46
  }
47

48
  /**
49
   * Gets the int attribute.
50
   *
51
   * @param attribs
52
   *          the attribs
53
   * @param name
54
   *          the name
55
   * @param def
56
   *          the def
57
   *
58
   * @return the int attribute
59
   */
60
  public static int getIntAttribute(Properties attribs, String name, int def) {
61
    String value = attribs.getProperty(name);
1✔
62
    if (value == null) {
1!
63
      return def;
×
64
    }
65
    return Integer.parseInt(value);
1✔
66
  }
67

68
  /**
69
   * Parses the attributes.
70
   *
71
   * @param n
72
   *          the n
73
   *
74
   * @return the properties
75
   */
76
  public static Properties parseAttributes(Node n) {
77
    return parseAttributes(n, null);
×
78
  }
79

80
  /**
81
   * Parses the attributes.
82
   *
83
   * @param n
84
   *          the n
85
   * @param variables
86
   *          the variables
87
   *
88
   * @return the properties
89
   */
90
  public static Properties parseAttributes(Node n, Properties variables) {
91
    Properties attributes = new Properties();
1✔
92
    NamedNodeMap attributeNodes = n.getAttributes();
1✔
93
    for (int i = 0; i < attributeNodes.getLength(); i++) {
1✔
94
      Node attribute = attributeNodes.item(i);
1✔
95
      String value = parsePropertyTokens(attribute.getNodeValue(), variables);
1✔
96
      attributes.put(attribute.getNodeName(), value);
1✔
97
    }
98
    return attributes;
1✔
99
  }
100

101
  /**
102
   * Parses the property tokens.
103
   *
104
   * @param string
105
   *          the string
106
   * @param variables
107
   *          the variables
108
   *
109
   * @return the string
110
   */
111
  public static String parsePropertyTokens(String string, Properties variables) {
112
    final String OPEN = "${";
1✔
113
    final String CLOSE = "}";
1✔
114

115
    String newString = string;
1✔
116
    if (newString != null && variables != null) {
1!
117
      int start = newString.indexOf(OPEN);
1✔
118
      int end = newString.indexOf(CLOSE);
1✔
119

120
      while (start > -1 && end > start) {
1!
121
        String prepend = newString.substring(0, start);
1✔
122
        String append = newString.substring(end + CLOSE.length());
1✔
123
        String propName = newString.substring(start + OPEN.length(), end);
1✔
124
        String propValue = variables.getProperty(propName);
1✔
125
        if (propValue == null) {
1✔
126
          newString = prepend + propName + append;
1✔
127
        } else {
128
          newString = prepend + propValue + append;
1✔
129
        }
130
        start = newString.indexOf(OPEN);
1✔
131
        end = newString.indexOf(CLOSE);
1✔
132
      }
1✔
133
    }
134
    return newString;
1✔
135
  }
136

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