1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.velocity.internal.util; |
21 |
|
|
22 |
|
import java.util.HashSet; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import org.slf4j.Logger; |
26 |
|
import org.slf4j.LoggerFactory; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@version |
32 |
|
|
|
|
| 60.7% |
Uncovered Elements: 149 (379) |
Complexity: 109 |
Complexity Density: 0.49 |
|
33 |
|
public class VelocityParser |
34 |
|
{ |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
public static final Set<String> VELOCITYDIRECTIVE_BEGIN = new HashSet<String>(); |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
public static final Set<String> VELOCITYDIRECTIVE_END = new HashSet<String>(); |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public static final Set<String> VELOCITYDIRECTIVE_PARAM = new HashSet<String>(); |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public static final Set<String> VELOCITYDIRECTIVE_NOPARAM = new HashSet<String>(); |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
public static final Set<String> VELOCITYDIRECTIVE_ALL = new HashSet<String>(); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(VelocityParser.class); |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
65 |
2 |
static {... |
66 |
2 |
VELOCITYDIRECTIVE_BEGIN.add("if"); |
67 |
2 |
VELOCITYDIRECTIVE_BEGIN.add("foreach"); |
68 |
2 |
VELOCITYDIRECTIVE_BEGIN.add("literal"); |
69 |
2 |
VELOCITYDIRECTIVE_BEGIN.add("macro"); |
70 |
2 |
VELOCITYDIRECTIVE_BEGIN.add("define"); |
71 |
|
|
72 |
2 |
VELOCITYDIRECTIVE_END.add("end"); |
73 |
|
|
74 |
2 |
VELOCITYDIRECTIVE_PARAM.addAll(VELOCITYDIRECTIVE_BEGIN); |
75 |
2 |
VELOCITYDIRECTIVE_PARAM.add("set"); |
76 |
2 |
VELOCITYDIRECTIVE_PARAM.add("elseif"); |
77 |
2 |
VELOCITYDIRECTIVE_PARAM.add("evaluate"); |
78 |
2 |
VELOCITYDIRECTIVE_PARAM.add("include"); |
79 |
|
|
80 |
2 |
VELOCITYDIRECTIVE_NOPARAM.addAll(VELOCITYDIRECTIVE_END); |
81 |
2 |
VELOCITYDIRECTIVE_NOPARAM.add("else"); |
82 |
2 |
VELOCITYDIRECTIVE_NOPARAM.add("break"); |
83 |
2 |
VELOCITYDIRECTIVE_NOPARAM.add("stop"); |
84 |
|
|
85 |
2 |
VELOCITYDIRECTIVE_ALL.addAll(VELOCITYDIRECTIVE_PARAM); |
86 |
2 |
VELOCITYDIRECTIVE_ALL.addAll(VELOCITYDIRECTIVE_NOPARAM); |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@param |
93 |
|
@param |
94 |
|
@param |
95 |
|
@param |
96 |
|
@return |
97 |
|
@throws |
98 |
|
|
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
99 |
43 |
public int getKeyWord(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context)... |
100 |
|
throws InvalidVelocityException |
101 |
|
{ |
102 |
43 |
int i = currentIndex; |
103 |
|
|
104 |
43 |
if (i + 1 >= array.length) { |
105 |
0 |
throw new InvalidVelocityException(); |
106 |
|
} |
107 |
|
|
108 |
43 |
if (array[i + 1] == '#') { |
109 |
|
|
110 |
3 |
i = getSimpleComment(array, currentIndex, velocityBlock, context); |
111 |
40 |
} else if (array[i + 1] == '*') { |
112 |
|
|
113 |
2 |
i = getMultilinesComment(array, currentIndex, velocityBlock, context); |
114 |
38 |
} else if (array[i + 1] == '{' || Character.isLetter(array[i + 1])) { |
115 |
|
|
116 |
36 |
i = getDirective(array, currentIndex, velocityBlock, context); |
117 |
|
} else { |
118 |
2 |
throw new InvalidVelocityException(); |
119 |
|
} |
120 |
|
|
121 |
41 |
return i; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
@param |
129 |
|
@param |
130 |
|
@param |
131 |
|
@return |
132 |
|
@throws |
133 |
|
|
|
|
| 94.3% |
Uncovered Elements: 2 (35) |
Complexity: 10 |
Complexity Density: 0.48 |
|
134 |
36 |
public int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context)... |
135 |
|
throws InvalidVelocityException |
136 |
|
{ |
137 |
36 |
int i = currentIndex + 1; |
138 |
|
|
139 |
|
|
140 |
36 |
StringBuffer directiveNameBuffer = new StringBuffer(); |
141 |
36 |
i = getDirectiveName(array, i, directiveNameBuffer, null, context); |
142 |
|
|
143 |
36 |
String directiveName = directiveNameBuffer.toString(); |
144 |
|
|
145 |
36 |
if (!VELOCITYDIRECTIVE_NOPARAM.contains(directiveName)) { |
146 |
|
|
147 |
33 |
while (i < array.length && array[i] == ' ') { |
148 |
6 |
++i; |
149 |
|
} |
150 |
|
|
151 |
27 |
if (i < array.length && array[i] == '(') { |
152 |
|
|
153 |
27 |
i = getMethodParameters(array, i, null, context); |
154 |
|
} else { |
155 |
0 |
throw new InvalidVelocityException(); |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
36 |
if (VELOCITYDIRECTIVE_ALL.contains(directiveName)) { |
160 |
31 |
if (VELOCITYDIRECTIVE_BEGIN.contains(directiveName)) { |
161 |
10 |
context.pushVelocityElement(new VelocityBlock(directiveName, VelocityBlock.VelocityType.DIRECTIVE)); |
162 |
21 |
} else if (VELOCITYDIRECTIVE_END.contains(directiveName)) { |
163 |
8 |
context.popVelocityElement(); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
31 |
i = getDirectiveEndOfLine(array, i, null, context); |
168 |
|
|
169 |
31 |
context.setType(VelocityBlock.VelocityType.DIRECTIVE); |
170 |
|
} else { |
171 |
5 |
context.setType(VelocityBlock.VelocityType.MACRO); |
172 |
|
} |
173 |
|
|
174 |
36 |
if (velocityBlock != null) { |
175 |
1 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
176 |
|
} |
177 |
|
|
178 |
36 |
return i; |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
@param |
185 |
|
@param |
186 |
|
@param |
187 |
|
@param |
188 |
|
@return |
189 |
|
@throws |
190 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 6 |
Complexity Density: 0.75 |
|
191 |
52 |
public int getVelocityIdentifier(char[] array, int currentIndex, StringBuffer velocityBlock,... |
192 |
|
VelocityParserContext context) throws InvalidVelocityException |
193 |
|
{ |
194 |
|
|
195 |
52 |
if (!Character.isLetter(array[currentIndex])) { |
196 |
1 |
throw new InvalidVelocityException(); |
197 |
|
} |
198 |
|
|
199 |
51 |
int i = currentIndex + 1; |
200 |
|
|
201 |
199 |
while (i < array.length && array[i] != '}' && isValidVelocityIdentifierChar(array[i])) { |
202 |
148 |
++i; |
203 |
|
} |
204 |
|
|
205 |
51 |
if (velocityBlock != null) { |
206 |
51 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
207 |
|
} |
208 |
|
|
209 |
51 |
return i; |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
@param |
216 |
|
@return |
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
191 |
public boolean isValidVelocityIdentifierChar(char c)... |
219 |
|
{ |
220 |
191 |
return Character.isLetterOrDigit(c) || c == '_' || c == '-'; |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@link |
226 |
|
|
227 |
|
|
228 |
|
@param |
229 |
|
@param |
230 |
|
@param |
231 |
|
@param |
232 |
|
@param |
233 |
|
@return |
234 |
|
@throws |
235 |
|
|
|
|
| 57.9% |
Uncovered Elements: 8 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
236 |
36 |
public int getDirectiveName(char[] array, int currentIndex, StringBuffer directiveName, StringBuffer velocityBlock,... |
237 |
|
VelocityParserContext context) throws InvalidVelocityException |
238 |
|
{ |
239 |
36 |
int i = currentIndex; |
240 |
|
|
241 |
36 |
if (i == array.length) { |
242 |
0 |
throw new InvalidVelocityException(); |
243 |
|
} |
244 |
|
|
245 |
36 |
if (array[i] == '{') { |
246 |
0 |
++i; |
247 |
|
} |
248 |
|
|
249 |
36 |
i = getVelocityIdentifier(array, i, directiveName, context); |
250 |
|
|
251 |
36 |
if (i < array.length && array[i] == '}') { |
252 |
0 |
++i; |
253 |
|
} |
254 |
|
|
255 |
36 |
if (velocityBlock != null) { |
256 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
257 |
|
} |
258 |
|
|
259 |
36 |
return i; |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
@param |
266 |
|
@param |
267 |
|
@param |
268 |
|
@param |
269 |
|
@return |
270 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
271 |
31 |
public int getDirectiveEndOfLine(char[] array, int currentIndex, StringBuffer velocityBlock,... |
272 |
|
VelocityParserContext context) |
273 |
|
{ |
274 |
31 |
int i = currentIndex; |
275 |
|
|
276 |
32 |
for (; i < array.length; ++i) { |
277 |
25 |
if (array[i] == '\n') { |
278 |
23 |
++i; |
279 |
23 |
break; |
280 |
2 |
} else if (!Character.isWhitespace(array[i])) { |
281 |
1 |
return currentIndex; |
282 |
|
} |
283 |
|
} |
284 |
|
|
285 |
30 |
if (velocityBlock != null) { |
286 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
287 |
|
} |
288 |
|
|
289 |
30 |
return i; |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
@param |
296 |
|
@param |
297 |
|
@param |
298 |
|
@param |
299 |
|
@return |
300 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
301 |
3 |
public int getSimpleComment(char[] array, int currentIndex, StringBuffer velocityBlock,... |
302 |
|
VelocityParserContext context) |
303 |
|
{ |
304 |
3 |
int i = currentIndex + 2; |
305 |
|
|
306 |
33 |
while (i < array.length && array[i - 1] != '\n') { |
307 |
30 |
++i; |
308 |
|
} |
309 |
|
|
310 |
3 |
if (velocityBlock != null) { |
311 |
1 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
312 |
|
} |
313 |
|
|
314 |
3 |
context.setType(VelocityBlock.VelocityType.COMMENT); |
315 |
|
|
316 |
3 |
return i; |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
@param |
323 |
|
@param |
324 |
|
@param |
325 |
|
@param |
326 |
|
@return |
327 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 5 |
Complexity Density: 0.71 |
|
328 |
2 |
public int getMultilinesComment(char[] array, int currentIndex, StringBuffer velocityBlock,... |
329 |
|
VelocityParserContext context) |
330 |
|
{ |
331 |
2 |
int i = currentIndex + 2; |
332 |
|
|
333 |
28 |
while (i < array.length && (array[i - 1] != '#' || array[i - 2] != '*')) { |
334 |
26 |
++i; |
335 |
|
} |
336 |
|
|
337 |
2 |
if (velocityBlock != null) { |
338 |
1 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
339 |
|
} |
340 |
|
|
341 |
2 |
context.setType(VelocityBlock.VelocityType.COMMENT); |
342 |
|
|
343 |
2 |
return i; |
344 |
|
} |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
@param |
350 |
|
@param |
351 |
|
@param |
352 |
|
@param |
353 |
|
@return |
354 |
|
@throws |
355 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
356 |
0 |
public int getVar(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context)... |
357 |
|
throws InvalidVelocityException |
358 |
|
{ |
359 |
0 |
return getVar(array, currentIndex, null, velocityBlock, context); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
@param |
366 |
|
@param |
367 |
|
@param |
368 |
|
@param |
369 |
|
@param |
370 |
|
@return |
371 |
|
@throws |
372 |
|
|
|
|
| 71.4% |
Uncovered Elements: 10 (35) |
Complexity: 8 |
Complexity Density: 0.38 |
|
373 |
20 |
public int getVar(char[] array, int currentIndex, StringBuffer varName, StringBuffer velocityBlock,... |
374 |
|
VelocityParserContext context) throws InvalidVelocityException |
375 |
|
{ |
376 |
20 |
if (isVarEscaped(array, currentIndex)) { |
377 |
4 |
throw new InvalidVelocityException(); |
378 |
|
} |
379 |
|
|
380 |
16 |
int i = currentIndex + 1; |
381 |
|
|
382 |
16 |
if (i == array.length) { |
383 |
0 |
throw new InvalidVelocityException(); |
384 |
|
} |
385 |
|
|
386 |
16 |
if (array[i] == '!') { |
387 |
0 |
++i; |
388 |
|
} |
389 |
|
|
390 |
16 |
if (i == array.length) { |
391 |
0 |
throw new InvalidVelocityException(); |
392 |
|
} |
393 |
|
|
394 |
16 |
boolean fullSyntax = false; |
395 |
16 |
if (array[i] == '{') { |
396 |
3 |
++i; |
397 |
3 |
fullSyntax = true; |
398 |
|
} |
399 |
|
|
400 |
16 |
if (i == array.length) { |
401 |
0 |
throw new InvalidVelocityException(); |
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
16 |
i = getVelocityIdentifier(array, i, varName, context); |
406 |
|
|
407 |
|
|
408 |
15 |
i = followVar(array, i, fullSyntax, context); |
409 |
|
|
410 |
15 |
if (velocityBlock != null) { |
411 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
412 |
|
} |
413 |
|
|
414 |
15 |
context.setType(VelocityBlock.VelocityType.VAR); |
415 |
|
|
416 |
15 |
return i; |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
@param |
423 |
|
@param |
424 |
|
@return |
425 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
426 |
20 |
private boolean isVarEscaped(char[] array, int currentIndex)... |
427 |
|
{ |
428 |
20 |
int i = currentIndex - 1; |
429 |
|
|
430 |
24 |
while (i >= 0 && array[i] == '\\') { |
431 |
4 |
--i; |
432 |
|
} |
433 |
|
|
434 |
20 |
return (currentIndex - i) % 2 == 0; |
435 |
|
} |
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
@param |
441 |
|
@param |
442 |
|
@param |
443 |
|
@param |
444 |
|
@return |
445 |
|
|
|
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 7 |
Complexity Density: 0.47 |
|
446 |
15 |
private int followVar(char[] array, int currentIndex, boolean fullSyntax, VelocityParserContext context)... |
447 |
|
{ |
448 |
15 |
int i = currentIndex; |
449 |
|
|
450 |
17 |
while (i < array.length) { |
451 |
12 |
if (fullSyntax && array[i] == '}') { |
452 |
3 |
++i; |
453 |
3 |
break; |
454 |
9 |
} else if (array[i] == '.') { |
455 |
2 |
try { |
456 |
2 |
i = getMethodOrProperty(array, i, null, context); |
457 |
|
} catch (InvalidVelocityException e) { |
458 |
0 |
LOGGER.debug("Not a valid method at char [{}]", i, e); |
459 |
0 |
break; |
460 |
|
} |
461 |
7 |
} else if (array[i] == '[') { |
462 |
0 |
i = getTableElement(array, i, null, context); |
463 |
0 |
break; |
464 |
|
} else { |
465 |
7 |
break; |
466 |
|
} |
467 |
|
} |
468 |
|
|
469 |
15 |
return i; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
@param |
476 |
|
@param |
477 |
|
@param |
478 |
|
@param |
479 |
|
@return |
480 |
|
@throws |
481 |
|
|
|
|
| 63.6% |
Uncovered Elements: 8 (22) |
Complexity: 7 |
Complexity Density: 0.58 |
|
482 |
2 |
public int getMethodOrProperty(char[] array, int currentIndex, StringBuffer velocityBlock,... |
483 |
|
VelocityParserContext context) throws InvalidVelocityException |
484 |
|
{ |
485 |
2 |
int i = currentIndex + 1; |
486 |
|
|
487 |
|
|
488 |
2 |
if (i < array.length && Character.isLetter(array[i])) { |
489 |
4 |
for (; i < array.length; ++i) { |
490 |
4 |
if (array[i] == '(') { |
491 |
0 |
i = getMethodParameters(array, i, null, context); |
492 |
0 |
break; |
493 |
4 |
} else if (!Character.isLetterOrDigit(array[i])) { |
494 |
2 |
break; |
495 |
|
} |
496 |
|
} |
497 |
|
} else { |
498 |
0 |
throw new InvalidVelocityException(); |
499 |
|
} |
500 |
|
|
501 |
2 |
if (velocityBlock != null) { |
502 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
503 |
|
} |
504 |
|
|
505 |
2 |
return i; |
506 |
|
} |
507 |
|
|
508 |
|
|
509 |
|
|
510 |
|
|
511 |
|
@param |
512 |
|
@param |
513 |
|
@param |
514 |
|
@param |
515 |
|
@return |
516 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
517 |
0 |
public int getTableElement(char[] array, int currentIndex, StringBuffer velocityBlock,... |
518 |
|
VelocityParserContext context) |
519 |
|
{ |
520 |
0 |
return getParameters(array, currentIndex, velocityBlock, ']', context); |
521 |
|
} |
522 |
|
|
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
@param |
527 |
|
@param |
528 |
|
@param |
529 |
|
@param |
530 |
|
@return |
531 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
532 |
27 |
public int getMethodParameters(char[] array, int currentIndex, StringBuffer velocityBlock,... |
533 |
|
VelocityParserContext context) |
534 |
|
{ |
535 |
27 |
return getParameters(array, currentIndex, velocityBlock, ')', context); |
536 |
|
} |
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
@link |
541 |
|
@link |
542 |
|
|
543 |
|
@param |
544 |
|
@param |
545 |
|
@param |
546 |
|
@param |
547 |
|
@param |
548 |
|
@return |
549 |
|
|
|
|
| 70% |
Uncovered Elements: 9 (30) |
Complexity: 8 |
Complexity Density: 0.44 |
|
550 |
27 |
public int getParameters(char[] array, int currentIndex, StringBuffer velocityBlock, char endingChar,... |
551 |
|
VelocityParserContext context) |
552 |
|
{ |
553 |
27 |
char beginChar = array[currentIndex]; |
554 |
|
|
555 |
27 |
int i = currentIndex + 1; |
556 |
|
|
557 |
27 |
int depth = 1; |
558 |
|
|
559 |
73 |
while (i < array.length) { |
560 |
73 |
if (array[i] == endingChar) { |
561 |
27 |
--depth; |
562 |
27 |
if (depth == 0) { |
563 |
27 |
++i; |
564 |
27 |
break; |
565 |
|
} |
566 |
46 |
} else if (array[i] == beginChar) { |
567 |
0 |
++depth; |
568 |
46 |
} else if (array[i] == '"' || array[i] == '\'') { |
569 |
0 |
i = getEscape(array, i, null, context); |
570 |
0 |
continue; |
571 |
|
} |
572 |
|
|
573 |
46 |
++i; |
574 |
|
} |
575 |
|
|
576 |
27 |
if (velocityBlock != null) { |
577 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
578 |
|
} |
579 |
|
|
580 |
27 |
return i; |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
|
@param |
585 |
|
@param |
586 |
|
@param |
587 |
|
@param |
588 |
|
@return |
589 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 8 |
Complexity Density: 0.4 |
|
590 |
0 |
public int getEscape(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context)... |
591 |
|
{ |
592 |
0 |
char escapeChar = array[currentIndex]; |
593 |
|
|
594 |
0 |
int i = currentIndex + 1; |
595 |
|
|
596 |
0 |
boolean escaped = false; |
597 |
|
|
598 |
0 |
for (; i < array.length;) { |
599 |
0 |
if (!escaped) { |
600 |
0 |
if (array[i] == '\\') { |
601 |
0 |
escaped = true; |
602 |
0 |
} else if (array[i] == '$') { |
603 |
0 |
try { |
604 |
0 |
i = getVar(array, i, null, context); |
605 |
0 |
continue; |
606 |
|
} catch (InvalidVelocityException e) { |
607 |
0 |
LOGGER.debug("Not a valid variable at char [{}]", i, e); |
608 |
|
} |
609 |
0 |
} else if (array[i] == escapeChar) { |
610 |
0 |
++i; |
611 |
0 |
break; |
612 |
|
} |
613 |
|
} else { |
614 |
0 |
escaped = false; |
615 |
|
} |
616 |
|
|
617 |
0 |
++i; |
618 |
|
} |
619 |
|
|
620 |
0 |
if (velocityBlock != null) { |
621 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
622 |
|
} |
623 |
|
|
624 |
0 |
return i; |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
@link |
629 |
|
|
630 |
|
@param |
631 |
|
@param |
632 |
|
@param |
633 |
|
@param |
634 |
|
@return |
635 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
636 |
0 |
public int getWhiteSpaces(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context)... |
637 |
|
{ |
638 |
0 |
int i = currentIndex; |
639 |
|
|
640 |
0 |
while (i < array.length && Character.isWhitespace(array[i])) { |
641 |
0 |
++i; |
642 |
|
} |
643 |
|
|
644 |
0 |
if (velocityBlock != null) { |
645 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
646 |
|
} |
647 |
|
|
648 |
0 |
return i; |
649 |
|
} |
650 |
|
|
651 |
|
|
652 |
|
|
653 |
|
|
654 |
|
@param |
655 |
|
@param |
656 |
|
@param |
657 |
|
@param |
658 |
|
@return |
659 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
660 |
0 |
public int getSpaces(char[] array, int currentIndex, StringBuffer velocityBlock,... |
661 |
|
VelocityParserContext context) |
662 |
|
{ |
663 |
0 |
int i = currentIndex; |
664 |
|
|
665 |
0 |
while (i < array.length && Character.isWhitespace(array[i])) { |
666 |
0 |
++i; |
667 |
|
} |
668 |
|
|
669 |
0 |
if (velocityBlock != null) { |
670 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
671 |
|
} |
672 |
|
|
673 |
0 |
return i; |
674 |
|
} |
675 |
|
|
676 |
|
|
677 |
|
@param |
678 |
|
@param |
679 |
|
@param |
680 |
|
@param |
681 |
|
@return |
682 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
683 |
0 |
public int getMacroParametersSeparator(char[] array, int currentIndex, StringBuffer velocityBlock,... |
684 |
|
VelocityParserContext context) |
685 |
|
{ |
686 |
0 |
int i = currentIndex; |
687 |
|
|
688 |
0 |
i = getWhiteSpaces(array, i, null, context); |
689 |
0 |
if (array[i] == ',') { |
690 |
0 |
i++; |
691 |
|
} |
692 |
0 |
i = getWhiteSpaces(array, i, null, context); |
693 |
|
|
694 |
0 |
if (velocityBlock != null) { |
695 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
696 |
|
} |
697 |
|
|
698 |
0 |
return i; |
699 |
|
} |
700 |
|
|
701 |
|
|
702 |
|
@param |
703 |
|
@param |
704 |
|
@param |
705 |
|
@param |
706 |
|
@return |
707 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 10 |
Complexity Density: 0.59 |
|
708 |
0 |
public int getMacroParameter(char[] array, int currentIndex, StringBuffer velocityBlock,... |
709 |
|
VelocityParserContext context) |
710 |
|
{ |
711 |
0 |
int i = currentIndex; |
712 |
|
|
713 |
0 |
for (; i < array.length; ++i) { |
714 |
0 |
if (array[i] == '$') { |
715 |
0 |
try { |
716 |
0 |
i = getVar(array, i, null, context); |
717 |
0 |
break; |
718 |
|
} catch (InvalidVelocityException e) { |
719 |
0 |
LOGGER.debug("Not a valid velocity variable at char [{}]", i, e); |
720 |
|
} |
721 |
0 |
} else if (array[i] == '"' || array[i] == '\'') { |
722 |
0 |
i = getEscape(array, i, null, context); |
723 |
0 |
break; |
724 |
0 |
} else if (Character.isWhitespace(array[i]) || array[i] == ',') { |
725 |
0 |
break; |
726 |
0 |
} else if (array[i] == ')') { |
727 |
0 |
break; |
728 |
|
} |
729 |
|
} |
730 |
|
|
731 |
0 |
if (velocityBlock != null) { |
732 |
0 |
velocityBlock.append(array, currentIndex, i - currentIndex); |
733 |
|
} |
734 |
|
|
735 |
0 |
return i; |
736 |
|
} |
737 |
|
} |