1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.tag; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import com.xpn.xwiki.XWikiException; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@version |
31 |
|
@since |
32 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
33 |
|
public final class TagParamUtils |
34 |
|
{ |
35 |
|
|
36 |
|
|
37 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
38 |
0 |
private TagParamUtils()... |
39 |
|
{ |
40 |
|
|
41 |
|
} |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@param |
49 |
|
@return |
50 |
|
@throws |
51 |
|
@throws |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
53 |
8 |
public static List<String> spacesParameterToList(String spaces) throws XWikiException... |
54 |
|
{ |
55 |
8 |
if (spaces == null) { |
56 |
1 |
throw new IllegalArgumentException("Parameter 'spaces' should not be null"); |
57 |
|
} |
58 |
7 |
return new HQLInListParser(spaces).getResults(); |
59 |
|
} |
60 |
|
|
|
|
| 93.1% |
Uncovered Elements: 4 (58) |
Complexity: 18 |
Complexity Density: 0.58 |
|
61 |
|
private static class HQLInListParser |
62 |
|
{ |
63 |
|
|
64 |
|
private final String spaces; |
65 |
|
|
66 |
|
private boolean inQuotes; |
67 |
|
private boolean commaSeen = true; |
68 |
|
private int pos; |
69 |
|
private char c; |
70 |
|
private StringBuilder space; |
71 |
|
|
72 |
|
private final List<String> results = new ArrayList<>(); |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
74 |
7 |
HQLInListParser(String spaces) throws XWikiException... |
75 |
|
{ |
76 |
7 |
this.spaces = spaces; |
77 |
7 |
parse(); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
4 |
List<String> getResults()... |
81 |
|
{ |
82 |
4 |
return results; |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 6 |
Complexity Density: 0.67 |
|
85 |
7 |
private void parse() throws XWikiException... |
86 |
|
{ |
87 |
117 |
while (pos < spaces.length()) { |
88 |
111 |
c = spaces.charAt(pos++); |
89 |
111 |
if (inQuotes) { |
90 |
88 |
handleInQuotes(); |
91 |
|
} else { |
92 |
23 |
handleOutsideQuotes(); |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
6 |
if (inQuotes) { |
97 |
1 |
throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, |
98 |
|
String.format("Missing closing quote in [%s]", spaces)); |
99 |
|
} |
100 |
5 |
if (commaSeen && !results.isEmpty()) { |
101 |
1 |
throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, |
102 |
|
String.format("Unexpected comma at end of [%s]", spaces)); |
103 |
|
} |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
106 |
88 |
private void handleInQuotes()... |
107 |
|
{ |
108 |
88 |
if (c == '\'') { |
109 |
11 |
if (pos < spaces.length() && spaces.charAt(pos) == '\'') { |
110 |
1 |
pos++; |
111 |
1 |
space.append(c); |
112 |
|
} else { |
113 |
10 |
results.add(space.toString()); |
114 |
10 |
inQuotes = false; |
115 |
10 |
commaSeen = false; |
116 |
|
} |
117 |
|
} else { |
118 |
77 |
space.append(c); |
119 |
|
} |
120 |
|
} |
121 |
|
|
|
|
| 81% |
Uncovered Elements: 4 (21) |
Complexity: 6 |
Complexity Density: 0.55 |
|
122 |
23 |
private void handleOutsideQuotes() throws XWikiException... |
123 |
|
{ |
124 |
23 |
if (c == ',') { |
125 |
7 |
if (commaSeen) { |
126 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, |
127 |
|
String.format("Unexpected comma at position %d in [%s]", pos, spaces)); |
128 |
|
} else { |
129 |
7 |
commaSeen = true; |
130 |
|
} |
131 |
16 |
} else if (c == '\'') { |
132 |
11 |
if (commaSeen) { |
133 |
11 |
inQuotes = true; |
134 |
11 |
space = new StringBuilder(); |
135 |
|
} else { |
136 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, |
137 |
|
String.format("Unexpected quote at position %d in [%s]", pos, spaces)); |
138 |
|
} |
139 |
5 |
} else if (!Character.isWhitespace(c)) { |
140 |
1 |
throw new XWikiException(XWikiException.MODULE_XWIKI_PLUGINS, XWikiException.ERROR_XWIKI_UNKNOWN, |
141 |
|
String.format("Unexpected character `%s` at position %d in [%s]", |
142 |
|
c, pos, spaces)); |
143 |
|
} |
144 |
|
} |
145 |
|
} |
146 |
|
} |