1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.util; |
17 |
|
|
18 |
|
import java.util.HashSet; |
19 |
|
import java.util.Map; |
20 |
|
import java.util.Set; |
21 |
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 11 |
Complexity Density: 0.48 |
|
22 |
|
public class MessageUtils { |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
@param |
27 |
|
|
28 |
|
@param |
29 |
|
|
30 |
|
@return |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
32 |
0
|
public static String interpolate(String message, String... data) {... |
33 |
0
|
if (message != null) { |
34 |
0
|
for (int i = 0; i < data.length; i++) { |
35 |
0
|
message = message.replaceAll("\\$\\{" + i + "\\}", "" + escape(data[i])); |
36 |
|
} |
37 |
|
} |
38 |
0
|
return message; |
39 |
|
} |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@param |
45 |
|
|
46 |
|
@param |
47 |
|
|
48 |
|
@return |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
50 |
0
|
public static String interpolate(String message, Map<String, Object> data) {... |
51 |
0
|
if (message != null && data != null) { |
52 |
0
|
Set<String> fields = findFields(message); |
53 |
0
|
for (String s : fields) { |
54 |
0
|
if(data.get(s) != null){ |
55 |
0
|
message = message.replaceAll("\\$\\{" + s + "\\}", "" + escape(data.get(s).toString())); |
56 |
|
} |
57 |
|
} |
58 |
|
} |
59 |
0
|
return message; |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
@param |
67 |
|
@param |
68 |
|
@return |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
70 |
0
|
public static String interpolate(String message, String parameter, Object value){... |
71 |
0
|
message = message.replaceAll("\\$\\{" + parameter + "\\}", "" + escape(value.toString())); |
72 |
0
|
return message; |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@param |
79 |
|
@return |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
81 |
0
|
private static String escape(String input) {... |
82 |
0
|
char[] toEscape = {'\\', '$', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}'}; |
83 |
0
|
for (char c : toEscape) { |
84 |
0
|
input = input.replaceAll("\\" + c, "\\\\\\" + c); |
85 |
|
} |
86 |
0
|
return input; |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@param |
93 |
|
|
94 |
|
@return |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
96 |
0
|
public static Set<String> findFields(String input) {... |
97 |
0
|
Set<String> result = new HashSet<String>(); |
98 |
0
|
int begin = input.indexOf("${"); |
99 |
0
|
while (begin != -1) { |
100 |
0
|
int end = input.indexOf("}", begin); |
101 |
0
|
result.add(input.substring(begin + 2, end)); |
102 |
0
|
begin = input.indexOf("${", end); |
103 |
|
} |
104 |
0
|
return result; |
105 |
|
} |
106 |
|
|
107 |
|
} |