1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.parse; |
16 |
|
|
17 |
|
import java.util.ArrayList; |
18 |
|
import java.util.Collections; |
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.Iterator; |
21 |
|
import java.util.List; |
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
25 |
|
import org.apache.hivemind.Location; |
26 |
|
import org.apache.hivemind.Resource; |
27 |
|
import org.apache.hivemind.impl.LocationImpl; |
28 |
|
import org.apache.oro.text.regex.MalformedPatternException; |
29 |
|
import org.apache.oro.text.regex.MatchResult; |
30 |
|
import org.apache.oro.text.regex.Pattern; |
31 |
|
import org.apache.oro.text.regex.PatternMatcher; |
32 |
|
import org.apache.oro.text.regex.Perl5Compiler; |
33 |
|
import org.apache.oro.text.regex.Perl5Matcher; |
34 |
|
import org.apache.tapestry.util.IdAllocator; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
public class TemplateParser implements ITemplateParser |
92 |
|
{ |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
public static final String LOCALIZATION_KEY_ATTRIBUTE_NAME = "key"; |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
public static final String RAW_ATTRIBUTE_NAME = "raw"; |
111 |
|
|
112 |
|
public static final String PROPERTY_NAME_PATTERN = "_?[a-zA-Z]\\w*"; |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
public static final String SIMPLE_ID_PATTERN = "^(" + PROPERTY_NAME_PATTERN + ")$"; |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
public static final String IMPLICIT_ID_PATTERN = "^(" + PROPERTY_NAME_PATTERN + ")?@(((" |
132 |
|
+ PROPERTY_NAME_PATTERN + "):)?((" + PROPERTY_NAME_PATTERN + "/)*" |
133 |
|
+ PROPERTY_NAME_PATTERN + "))$"; |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
private static final String REMOVE_ID = "$remove$"; |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
private static final String CONTENT_ID = "$content$"; |
149 |
|
|
150 |
|
private static final int IMPLICIT_ID_PATTERN_ID_GROUP = 1; |
151 |
|
|
152 |
|
private static final int IMPLICIT_ID_PATTERN_TYPE_GROUP = 2; |
153 |
|
|
154 |
|
private static final int IMPLICIT_ID_PATTERN_LIBRARY_ID_GROUP = 4; |
155 |
|
|
156 |
|
private static final int IMPLICIT_ID_PATTERN_SIMPLE_TYPE_GROUP = 5; |
157 |
|
|
158 |
1 |
private static final char[] COMMENT_START = new char[] |
159 |
|
{ '<', '!', '-', '-' }; |
160 |
|
|
161 |
1 |
private static final char[] COMMENT_END = new char[] |
162 |
|
{ '-', '-', '>' }; |
163 |
|
|
164 |
1 |
private static final char[] CLOSE_TAG = new char[] |
165 |
|
{ '<', '/' }; |
166 |
|
|
167 |
|
private static final int WAIT_FOR_ATTRIBUTE_NAME = 0; |
168 |
|
|
169 |
|
private static final int COLLECT_ATTRIBUTE_NAME = 1; |
170 |
|
|
171 |
|
private static final int ADVANCE_PAST_EQUALS = 2; |
172 |
|
|
173 |
|
private static final int WAIT_FOR_ATTRIBUTE_VALUE = 3; |
174 |
|
|
175 |
|
private static final int COLLECT_QUOTED_VALUE = 4; |
176 |
|
|
177 |
|
private static final int COLLECT_UNQUOTED_VALUE = 5; |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
1 |
private static final String[] CONVERSIONS = |
184 |
|
{ "<", "<", ">", ">", """, "\"", "&", "&" }; |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
private String _componentAttributeName; |
193 |
|
|
194 |
|
private Pattern _simpleIdPattern; |
195 |
|
|
196 |
|
private Pattern _implicitIdPattern; |
197 |
|
|
198 |
|
private PatternMatcher _patternMatcher; |
199 |
|
|
200 |
34 |
private IdAllocator _idAllocator = new IdAllocator(); |
201 |
|
|
202 |
|
private ITemplateParserDelegate _delegate; |
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
private Resource _resourceLocation; |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
private Location _templateLocation; |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
private Location _currentLocation; |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
private char[] _templateData; |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
34 |
private List _stack = new ArrayList(); |
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
private static class Tag |
239 |
|
{ |
240 |
|
|
241 |
|
String _tagName; |
242 |
|
|
243 |
|
|
244 |
|
boolean _component; |
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
boolean _ignoringBody; |
249 |
|
|
250 |
|
|
251 |
|
boolean _removeTag; |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
boolean _mustBalance; |
256 |
|
|
257 |
|
|
258 |
|
int _line; |
259 |
|
|
260 |
|
|
261 |
|
boolean _content; |
262 |
|
|
263 |
|
Tag(String tagName, int line) |
264 |
89 |
{ |
265 |
89 |
_tagName = tagName; |
266 |
89 |
_line = line; |
267 |
89 |
} |
268 |
|
|
269 |
|
boolean match(String matchTagName) |
270 |
|
{ |
271 |
68 |
return _tagName.equalsIgnoreCase(matchTagName); |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
34 |
private List _tokens = new ArrayList(); |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
private int _cursor; |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
private int _blockStart; |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
|
298 |
|
private int _line; |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
private boolean _ignoring; |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
34 |
private Map _attributes = new HashMap(); |
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
private TemplateTokenFactory _factory; |
319 |
|
|
320 |
|
public TemplateParser() |
321 |
34 |
{ |
322 |
34 |
Perl5Compiler compiler = new Perl5Compiler(); |
323 |
|
|
324 |
|
try |
325 |
|
{ |
326 |
34 |
_simpleIdPattern = compiler.compile(SIMPLE_ID_PATTERN); |
327 |
34 |
_implicitIdPattern = compiler.compile(IMPLICIT_ID_PATTERN); |
328 |
|
} |
329 |
0 |
catch (MalformedPatternException ex) |
330 |
|
{ |
331 |
0 |
throw new ApplicationRuntimeException(ex); |
332 |
34 |
} |
333 |
|
|
334 |
34 |
_patternMatcher = new Perl5Matcher(); |
335 |
34 |
} |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
public TemplateToken[] parse(char[] templateData, ITemplateParserDelegate delegate, |
352 |
|
Resource resourceLocation) throws TemplateParseException |
353 |
|
{ |
354 |
|
try |
355 |
|
{ |
356 |
34 |
beforeParse(templateData, delegate, resourceLocation); |
357 |
|
|
358 |
34 |
parse(); |
359 |
|
|
360 |
20 |
return (TemplateToken[]) _tokens.toArray(new TemplateToken[_tokens.size()]); |
361 |
|
} |
362 |
|
finally |
363 |
|
{ |
364 |
20 |
afterParse(); |
365 |
|
} |
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
protected void beforeParse(char[] templateData, ITemplateParserDelegate delegate, Resource resourceLocation) |
373 |
|
{ |
374 |
34 |
_templateData = templateData; |
375 |
34 |
_resourceLocation = resourceLocation; |
376 |
34 |
_templateLocation = new LocationImpl(resourceLocation); |
377 |
34 |
_delegate = delegate; |
378 |
34 |
_ignoring = false; |
379 |
34 |
_line = 1; |
380 |
34 |
_componentAttributeName = delegate.getComponentAttributeName(); |
381 |
34 |
} |
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
protected void afterParse() |
388 |
|
{ |
389 |
34 |
_delegate = null; |
390 |
34 |
_templateData = null; |
391 |
34 |
_resourceLocation = null; |
392 |
34 |
_templateLocation = null; |
393 |
34 |
_currentLocation = null; |
394 |
34 |
_stack.clear(); |
395 |
34 |
_tokens.clear(); |
396 |
34 |
_attributes.clear(); |
397 |
34 |
_idAllocator.clear(); |
398 |
34 |
} |
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
protected void templateParseProblem(String message, Location location, int line, int cursor) |
420 |
|
throws TemplateParseException |
421 |
|
{ |
422 |
14 |
throw new TemplateParseException(message, location); |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
|
440 |
|
|
441 |
|
|
442 |
|
protected void templateParseProblem(ApplicationRuntimeException exception, int line, int cursor) |
443 |
|
{ |
444 |
0 |
throw exception; |
445 |
|
} |
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
protected List getTokens() |
451 |
|
{ |
452 |
0 |
if (_tokens == null) |
453 |
0 |
return Collections.EMPTY_LIST; |
454 |
|
|
455 |
0 |
return _tokens; |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
private boolean lookahead(char[] match) |
463 |
|
{ |
464 |
|
try |
465 |
|
{ |
466 |
1081 |
for (int i = 0; i < match.length; i++) |
467 |
|
{ |
468 |
1007 |
if (_templateData[_cursor + i] != match[i]) |
469 |
582 |
return false; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
|
474 |
74 |
return true; |
475 |
|
} |
476 |
0 |
catch (IndexOutOfBoundsException ex) |
477 |
|
{ |
478 |
0 |
return false; |
479 |
|
} |
480 |
|
} |
481 |
|
|
482 |
|
protected void parse() throws TemplateParseException |
483 |
|
{ |
484 |
34 |
_cursor = 0; |
485 |
34 |
_blockStart = -1; |
486 |
34 |
int length = _templateData.length; |
487 |
|
|
488 |
2852 |
while (_cursor < length) |
489 |
|
{ |
490 |
2832 |
if (_templateData[_cursor] != '<') |
491 |
|
{ |
492 |
2645 |
if (_blockStart < 0 && !_ignoring) |
493 |
75 |
_blockStart = _cursor; |
494 |
|
|
495 |
2645 |
advance(); |
496 |
2645 |
continue; |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
|
|
501 |
187 |
if (lookahead(CLOSE_TAG)) |
502 |
|
{ |
503 |
63 |
closeTag(); |
504 |
60 |
continue; |
505 |
|
} |
506 |
|
|
507 |
124 |
if (lookahead(COMMENT_START)) |
508 |
|
{ |
509 |
6 |
skipComment(); |
510 |
5 |
continue; |
511 |
|
} |
512 |
|
|
513 |
|
|
514 |
|
|
515 |
118 |
startTag(); |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
|
|
523 |
20 |
addTextToken(_templateData.length - 1); |
524 |
20 |
} |
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
private void skipComment() throws TemplateParseException |
532 |
|
{ |
533 |
6 |
int length = _templateData.length; |
534 |
6 |
int startLine = _line; |
535 |
|
|
536 |
6 |
if (_blockStart < 0 && !_ignoring) |
537 |
2 |
_blockStart = _cursor; |
538 |
|
|
539 |
|
while (true) |
540 |
|
{ |
541 |
346 |
if (_cursor >= length) |
542 |
1 |
templateParseProblem(ParseMessages.commentNotEnded(startLine), new LocationImpl( |
543 |
|
_resourceLocation, startLine), startLine, _cursor); |
544 |
|
|
545 |
345 |
if (lookahead(COMMENT_END)) |
546 |
5 |
break; |
547 |
|
|
548 |
|
|
549 |
|
|
550 |
340 |
advance(); |
551 |
|
} |
552 |
|
|
553 |
5 |
_cursor += COMMENT_END.length; |
554 |
5 |
advanceOverWhitespace(); |
555 |
5 |
} |
556 |
|
|
557 |
|
private void addTextToken(int end) |
558 |
|
{ |
559 |
|
|
560 |
|
|
561 |
82 |
if (_blockStart < 0) |
562 |
5 |
return; |
563 |
|
|
564 |
77 |
if (_blockStart <= end) |
565 |
|
{ |
566 |
|
|
567 |
|
|
568 |
|
|
569 |
77 |
TemplateToken token = _factory.createTextToken( |
570 |
|
_templateData, |
571 |
|
_blockStart, |
572 |
|
end, |
573 |
|
_templateLocation); |
574 |
|
|
575 |
77 |
_tokens.add(token); |
576 |
|
} |
577 |
|
|
578 |
77 |
_blockStart = -1; |
579 |
77 |
} |
580 |
|
|
581 |
|
private void startTag() throws TemplateParseException |
582 |
|
{ |
583 |
118 |
int cursorStart = _cursor; |
584 |
118 |
int length = _templateData.length; |
585 |
118 |
String tagName = null; |
586 |
118 |
boolean endOfTag = false; |
587 |
118 |
boolean emptyTag = false; |
588 |
118 |
int startLine = _line; |
589 |
118 |
Location startLocation = new LocationImpl(_resourceLocation, startLine); |
590 |
|
|
591 |
118 |
tagBeginEvent(startLine, _cursor); |
592 |
|
|
593 |
118 |
advance(); |
594 |
|
|
595 |
|
|
596 |
|
|
597 |
548 |
while (_cursor < length) |
598 |
|
{ |
599 |
548 |
char ch = _templateData[_cursor]; |
600 |
|
|
601 |
548 |
if (ch == '/' || ch == '>' || Character.isWhitespace(ch)) |
602 |
|
{ |
603 |
118 |
tagName = new String(_templateData, cursorStart + 1, _cursor - cursorStart - 1); |
604 |
|
|
605 |
118 |
break; |
606 |
|
} |
607 |
|
|
608 |
430 |
advance(); |
609 |
430 |
} |
610 |
|
|
611 |
118 |
String attributeName = null; |
612 |
118 |
int attributeNameStart = -1; |
613 |
118 |
int attributeValueStart = -1; |
614 |
118 |
int state = WAIT_FOR_ATTRIBUTE_NAME; |
615 |
118 |
char quoteChar = 0; |
616 |
|
|
617 |
118 |
_attributes.clear(); |
618 |
|
|
619 |
|
|
620 |
|
|
621 |
1844 |
while (!endOfTag) |
622 |
|
{ |
623 |
1730 |
if (_cursor >= length) |
624 |
|
{ |
625 |
1 |
String message = (tagName == null) ? ParseMessages.unclosedUnknownTag(startLine) |
626 |
|
: ParseMessages.unclosedTag(tagName, startLine); |
627 |
|
|
628 |
1 |
templateParseProblem(message, startLocation, startLine, cursorStart); |
629 |
|
} |
630 |
|
|
631 |
1729 |
char ch = _templateData[_cursor]; |
632 |
|
|
633 |
1729 |
switch (state) |
634 |
|
{ |
635 |
|
case WAIT_FOR_ATTRIBUTE_NAME: |
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
|
640 |
316 |
if (ch == '/') |
641 |
|
{ |
642 |
22 |
emptyTag = true; |
643 |
22 |
advance(); |
644 |
22 |
break; |
645 |
|
} |
646 |
|
|
647 |
294 |
if (ch == '>') |
648 |
|
{ |
649 |
114 |
endOfTag = true; |
650 |
114 |
break; |
651 |
|
} |
652 |
|
|
653 |
180 |
if (Character.isWhitespace(ch)) |
654 |
|
{ |
655 |
95 |
advance(); |
656 |
95 |
break; |
657 |
|
} |
658 |
|
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
85 |
attributeNameStart = _cursor; |
663 |
85 |
state = COLLECT_ATTRIBUTE_NAME; |
664 |
85 |
advance(); |
665 |
85 |
break; |
666 |
|
|
667 |
|
case COLLECT_ATTRIBUTE_NAME: |
668 |
|
|
669 |
|
|
670 |
|
|
671 |
396 |
if (ch == '=' || ch == '/' || ch == '>' || Character.isWhitespace(ch)) |
672 |
|
{ |
673 |
85 |
attributeName = new String(_templateData, attributeNameStart, _cursor |
674 |
|
- attributeNameStart); |
675 |
|
|
676 |
85 |
state = ADVANCE_PAST_EQUALS; |
677 |
85 |
break; |
678 |
|
} |
679 |
|
|
680 |
|
|
681 |
|
|
682 |
311 |
advance(); |
683 |
311 |
break; |
684 |
|
|
685 |
|
case ADVANCE_PAST_EQUALS: |
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
|
691 |
87 |
if (ch == '/' || ch == '>') |
692 |
|
{ |
693 |
|
|
694 |
|
|
695 |
|
|
696 |
1 |
state = WAIT_FOR_ATTRIBUTE_NAME; |
697 |
1 |
break; |
698 |
|
} |
699 |
|
|
700 |
86 |
if (Character.isWhitespace(ch)) |
701 |
|
{ |
702 |
2 |
advance(); |
703 |
2 |
break; |
704 |
|
} |
705 |
|
|
706 |
84 |
if (ch == '=') |
707 |
|
{ |
708 |
84 |
state = WAIT_FOR_ATTRIBUTE_VALUE; |
709 |
84 |
quoteChar = 0; |
710 |
84 |
attributeValueStart = -1; |
711 |
84 |
advance(); |
712 |
84 |
break; |
713 |
|
} |
714 |
|
|
715 |
|
|
716 |
|
|
717 |
|
|
718 |
|
|
719 |
0 |
state = WAIT_FOR_ATTRIBUTE_NAME; |
720 |
0 |
break; |
721 |
|
|
722 |
|
case WAIT_FOR_ATTRIBUTE_VALUE: |
723 |
|
|
724 |
87 |
if (ch == '/' || ch == '>') |
725 |
1 |
templateParseProblem(ParseMessages.missingAttributeValue( |
726 |
|
tagName, |
727 |
|
_line, |
728 |
|
attributeName), getCurrentLocation(), _line, _cursor); |
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
86 |
if (Character.isWhitespace(ch)) |
734 |
|
{ |
735 |
3 |
advance(); |
736 |
3 |
break; |
737 |
|
} |
738 |
|
|
739 |
83 |
if (ch == '\'' || ch == '"') |
740 |
|
{ |
741 |
82 |
quoteChar = ch; |
742 |
|
|
743 |
82 |
state = COLLECT_QUOTED_VALUE; |
744 |
82 |
advance(); |
745 |
82 |
attributeValueStart = _cursor; |
746 |
82 |
attributeBeginEvent(attributeName, _line, attributeValueStart); |
747 |
82 |
break; |
748 |
|
} |
749 |
|
|
750 |
|
|
751 |
|
|
752 |
1 |
state = COLLECT_UNQUOTED_VALUE; |
753 |
1 |
attributeValueStart = _cursor; |
754 |
1 |
attributeBeginEvent(attributeName, _line, attributeValueStart); |
755 |
1 |
break; |
756 |
|
|
757 |
|
case COLLECT_QUOTED_VALUE: |
758 |
|
|
759 |
|
|
760 |
|
|
761 |
|
|
762 |
|
|
763 |
837 |
if (ch == quoteChar) |
764 |
|
{ |
765 |
82 |
String attributeValue = new String(_templateData, attributeValueStart, |
766 |
|
_cursor - attributeValueStart); |
767 |
|
|
768 |
82 |
attributeEndEvent(_cursor); |
769 |
|
|
770 |
82 |
addAttributeIfUnique(tagName, attributeName, attributeValue); |
771 |
|
|
772 |
|
|
773 |
80 |
advance(); |
774 |
80 |
state = WAIT_FOR_ATTRIBUTE_NAME; |
775 |
80 |
break; |
776 |
|
} |
777 |
|
|
778 |
755 |
advance(); |
779 |
755 |
break; |
780 |
|
|
781 |
|
case COLLECT_UNQUOTED_VALUE: |
782 |
|
|
783 |
|
|
784 |
|
|
785 |
|
|
786 |
6 |
if (ch == '/' || ch == '>' || Character.isWhitespace(ch)) |
787 |
|
{ |
788 |
1 |
String attributeValue = new String(_templateData, attributeValueStart, |
789 |
|
_cursor - attributeValueStart); |
790 |
|
|
791 |
1 |
attributeEndEvent(_cursor); |
792 |
1 |
addAttributeIfUnique(tagName, attributeName, attributeValue); |
793 |
|
|
794 |
1 |
state = WAIT_FOR_ATTRIBUTE_NAME; |
795 |
1 |
break; |
796 |
|
} |
797 |
|
|
798 |
5 |
advance(); |
799 |
|
break; |
800 |
|
} |
801 |
1726 |
} |
802 |
|
|
803 |
114 |
tagEndEvent(_cursor); |
804 |
|
|
805 |
|
|
806 |
|
|
807 |
114 |
String localizationKey = findValueCaselessly(LOCALIZATION_KEY_ATTRIBUTE_NAME, _attributes); |
808 |
114 |
String jwcId = findValueCaselessly(_componentAttributeName, _attributes); |
809 |
|
|
810 |
114 |
if (localizationKey != null && jwcId == null) |
811 |
|
{ |
812 |
8 |
if (_ignoring) |
813 |
1 |
templateParseProblem( |
814 |
|
ParseMessages.componentMayNotBeIgnored(tagName, startLine), |
815 |
|
startLocation, |
816 |
|
startLine, |
817 |
|
cursorStart); |
818 |
|
|
819 |
|
|
820 |
|
|
821 |
|
|
822 |
7 |
if (!emptyTag) |
823 |
|
{ |
824 |
5 |
Tag tag = new Tag(tagName, startLine); |
825 |
|
|
826 |
5 |
tag._component = false; |
827 |
5 |
tag._removeTag = false; |
828 |
5 |
tag._ignoringBody = true; |
829 |
5 |
tag._mustBalance = true; |
830 |
|
|
831 |
5 |
_stack.add(tag); |
832 |
|
|
833 |
|
|
834 |
|
|
835 |
5 |
_ignoring = true; |
836 |
5 |
} |
837 |
|
else |
838 |
|
{ |
839 |
|
|
840 |
2 |
advance(); |
841 |
|
|
842 |
|
} |
843 |
|
|
844 |
|
|
845 |
|
|
846 |
7 |
addTextToken(cursorStart - 1); |
847 |
|
|
848 |
7 |
boolean raw = checkBoolean(RAW_ATTRIBUTE_NAME, _attributes); |
849 |
|
|
850 |
7 |
Map attributes = filter(_attributes, new String[] { LOCALIZATION_KEY_ATTRIBUTE_NAME, RAW_ATTRIBUTE_NAME }); |
851 |
|
|
852 |
7 |
TemplateToken token = _factory.createLocalizationToken( |
853 |
|
tagName, |
854 |
|
localizationKey, |
855 |
|
raw, |
856 |
|
attributes, |
857 |
|
startLocation); |
858 |
|
|
859 |
7 |
_tokens.add(token); |
860 |
|
|
861 |
7 |
return; |
862 |
|
} |
863 |
|
|
864 |
106 |
if (jwcId != null) |
865 |
|
{ |
866 |
46 |
processComponentStart(tagName, jwcId, emptyTag, startLine, cursorStart, startLocation); |
867 |
41 |
return; |
868 |
|
} |
869 |
|
|
870 |
|
|
871 |
|
|
872 |
|
|
873 |
60 |
if (!emptyTag) |
874 |
|
{ |
875 |
60 |
Tag tag = new Tag(tagName, startLine); |
876 |
60 |
_stack.add(tag); |
877 |
|
} |
878 |
|
|
879 |
|
|
880 |
|
|
881 |
60 |
if (_blockStart < 0 && !_ignoring) |
882 |
6 |
_blockStart = cursorStart; |
883 |
|
|
884 |
60 |
advance(); |
885 |
60 |
} |
886 |
|
|
887 |
|
|
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
892 |
|
private void addAttributeIfUnique(String tagName, String attributeName, String attributeValue) |
893 |
|
throws TemplateParseException |
894 |
|
{ |
895 |
|
|
896 |
83 |
if (_attributes.containsKey(attributeName)) |
897 |
2 |
templateParseProblem( |
898 |
|
ParseMessages.duplicateTagAttribute(tagName, _line, attributeName), |
899 |
|
getCurrentLocation(), |
900 |
|
_line, |
901 |
|
_cursor); |
902 |
|
|
903 |
81 |
_attributes.put(attributeName, attributeValue); |
904 |
81 |
} |
905 |
|
|
906 |
|
|
907 |
|
|
908 |
|
|
909 |
|
|
910 |
|
|
911 |
|
|
912 |
|
|
913 |
|
|
914 |
|
|
915 |
|
|
916 |
|
protected void tagBeginEvent(int startLine, int cursorPosition) |
917 |
|
{ |
918 |
118 |
} |
919 |
|
|
920 |
|
|
921 |
|
|
922 |
|
|
923 |
|
|
924 |
|
|
925 |
|
protected void tagEndEvent(int cursorPosition) |
926 |
|
{ |
927 |
114 |
} |
928 |
|
|
929 |
|
|
930 |
|
|
931 |
|
|
932 |
|
|
933 |
|
|
934 |
|
protected void attributeBeginEvent(String attributeName, int startLine, int cursorPosition) |
935 |
|
{ |
936 |
83 |
} |
937 |
|
|
938 |
|
|
939 |
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
|
protected void attributeEndEvent(int cursorPosition) |
944 |
|
{ |
945 |
83 |
} |
946 |
|
|
947 |
|
private void processComponentStart(String tagName, String jwcId, boolean emptyTag, |
948 |
|
int startLine, int cursorStart, Location startLocation) throws TemplateParseException |
949 |
|
{ |
950 |
46 |
String componentId = jwcId; |
951 |
46 |
if (componentId.equalsIgnoreCase(CONTENT_ID)) |
952 |
|
{ |
953 |
2 |
processContentTag(tagName, startLine, cursorStart, emptyTag); |
954 |
|
|
955 |
1 |
return; |
956 |
|
} |
957 |
|
|
958 |
44 |
boolean isRemoveId = componentId.equalsIgnoreCase(REMOVE_ID); |
959 |
|
|
960 |
44 |
if (_ignoring && !isRemoveId) |
961 |
2 |
templateParseProblem( |
962 |
|
ParseMessages.componentMayNotBeIgnored(tagName, startLine), |
963 |
|
startLocation, |
964 |
|
startLine, |
965 |
|
cursorStart); |
966 |
|
|
967 |
42 |
String type = null; |
968 |
42 |
boolean allowBody = false; |
969 |
|
|
970 |
42 |
if (_patternMatcher.matches(componentId, _implicitIdPattern)) |
971 |
|
{ |
972 |
9 |
MatchResult match = _patternMatcher.getMatch(); |
973 |
|
|
974 |
9 |
componentId = match.group(IMPLICIT_ID_PATTERN_ID_GROUP); |
975 |
9 |
type = match.group(IMPLICIT_ID_PATTERN_TYPE_GROUP); |
976 |
|
|
977 |
9 |
String libraryId = match.group(IMPLICIT_ID_PATTERN_LIBRARY_ID_GROUP); |
978 |
9 |
String simpleType = match.group(IMPLICIT_ID_PATTERN_SIMPLE_TYPE_GROUP); |
979 |
|
|
980 |
|
|
981 |
|
|
982 |
|
|
983 |
|
|
984 |
|
|
985 |
|
|
986 |
|
|
987 |
|
|
988 |
|
|
989 |
|
|
990 |
9 |
if (componentId == null) |
991 |
7 |
componentId = _idAllocator.allocateId("$" + simpleType.replace('/', '$')); |
992 |
|
|
993 |
|
try |
994 |
|
{ |
995 |
9 |
allowBody = _delegate.getAllowBody(libraryId, simpleType, startLocation); |
996 |
|
} |
997 |
0 |
catch (ApplicationRuntimeException e) |
998 |
|
{ |
999 |
|
|
1000 |
0 |
templateParseProblem(e, startLine, cursorStart); |
1001 |
9 |
} |
1002 |
|
|
1003 |
9 |
} |
1004 |
|
else |
1005 |
|
{ |
1006 |
33 |
if (!isRemoveId) |
1007 |
|
{ |
1008 |
27 |
if (!_patternMatcher.matches(componentId, _simpleIdPattern)) |
1009 |
0 |
templateParseProblem( |
1010 |
|
ParseMessages.componentIdInvalid(tagName, startLine, componentId), |
1011 |
|
startLocation, |
1012 |
|
startLine, |
1013 |
|
cursorStart); |
1014 |
|
|
1015 |
27 |
if (!_delegate.getKnownComponent(componentId)) |
1016 |
1 |
templateParseProblem( |
1017 |
|
ParseMessages.unknownComponentId(tagName, startLine, componentId), |
1018 |
|
startLocation, |
1019 |
|
startLine, |
1020 |
|
cursorStart); |
1021 |
|
|
1022 |
|
try |
1023 |
|
{ |
1024 |
26 |
allowBody = _delegate.getAllowBody(componentId, startLocation); |
1025 |
|
} |
1026 |
0 |
catch (ApplicationRuntimeException e) |
1027 |
|
{ |
1028 |
|
|
1029 |
0 |
templateParseProblem(e, startLine, cursorStart); |
1030 |
26 |
} |
1031 |
|
} |
1032 |
|
} |
1033 |
|
|
1034 |
|
|
1035 |
|
|
1036 |
|
|
1037 |
|
|
1038 |
41 |
boolean ignoreBody = !emptyTag && (isRemoveId || !allowBody); |
1039 |
|
|
1040 |
41 |
if (_ignoring && ignoreBody) |
1041 |
1 |
templateParseProblem(ParseMessages.nestedIgnore(tagName, startLine), new LocationImpl( |
1042 |
|
_resourceLocation, startLine), startLine, cursorStart); |
1043 |
|
|
1044 |
40 |
if (!emptyTag) |
1045 |
23 |
pushNewTag(tagName, startLine, isRemoveId, ignoreBody); |
1046 |
|
|
1047 |
|
|
1048 |
|
|
1049 |
40 |
addTextToken(cursorStart - 1); |
1050 |
|
|
1051 |
40 |
if (!isRemoveId) |
1052 |
|
{ |
1053 |
35 |
addOpenToken(tagName, componentId, type, startLocation); |
1054 |
|
|
1055 |
35 |
if (emptyTag) |
1056 |
17 |
_tokens.add(_factory.createCloseToken(tagName, getCurrentLocation())); |
1057 |
|
} |
1058 |
|
|
1059 |
40 |
advance(); |
1060 |
40 |
} |
1061 |
|
|
1062 |
|
private void pushNewTag(String tagName, int startLine, boolean isRemoveId, boolean ignoreBody) |
1063 |
|
{ |
1064 |
23 |
Tag tag = new Tag(tagName, startLine); |
1065 |
|
|
1066 |
23 |
tag._component = !isRemoveId; |
1067 |
23 |
tag._removeTag = isRemoveId; |
1068 |
|
|
1069 |
23 |
tag._ignoringBody = ignoreBody; |
1070 |
|
|
1071 |
23 |
_ignoring = tag._ignoringBody; |
1072 |
|
|
1073 |
23 |
tag._mustBalance = true; |
1074 |
|
|
1075 |
23 |
_stack.add(tag); |
1076 |
23 |
} |
1077 |
|
|
1078 |
|
private void processContentTag(String tagName, int startLine, int cursorStart, boolean emptyTag) |
1079 |
|
throws TemplateParseException |
1080 |
|
{ |
1081 |
2 |
if (_ignoring) |
1082 |
1 |
templateParseProblem( |
1083 |
|
ParseMessages.contentBlockMayNotBeIgnored(tagName, startLine), |
1084 |
|
new LocationImpl(_resourceLocation, startLine), |
1085 |
|
startLine, |
1086 |
|
cursorStart); |
1087 |
|
|
1088 |
1 |
if (emptyTag) |
1089 |
0 |
templateParseProblem( |
1090 |
|
ParseMessages.contentBlockMayNotBeEmpty(tagName, startLine), |
1091 |
|
new LocationImpl(_resourceLocation, startLine), |
1092 |
|
startLine, |
1093 |
|
cursorStart); |
1094 |
|
|
1095 |
1 |
_tokens.clear(); |
1096 |
1 |
_blockStart = -1; |
1097 |
|
|
1098 |
1 |
Tag tag = new Tag(tagName, startLine); |
1099 |
|
|
1100 |
1 |
tag._mustBalance = true; |
1101 |
1 |
tag._content = true; |
1102 |
|
|
1103 |
1 |
_stack.clear(); |
1104 |
1 |
_stack.add(tag); |
1105 |
|
|
1106 |
1 |
advance(); |
1107 |
1 |
} |
1108 |
|
|
1109 |
|
private void addOpenToken(String tagName, String jwcId, String type, Location location) |
1110 |
|
{ |
1111 |
35 |
OpenToken token = _factory.createOpenToken(tagName, jwcId, type, location); |
1112 |
35 |
_tokens.add(token); |
1113 |
|
|
1114 |
35 |
if (_attributes.isEmpty()) |
1115 |
0 |
return; |
1116 |
|
|
1117 |
35 |
Iterator i = _attributes.entrySet().iterator(); |
1118 |
80 |
while (i.hasNext()) |
1119 |
|
{ |
1120 |
45 |
Map.Entry entry = (Map.Entry) i.next(); |
1121 |
|
|
1122 |
45 |
String key = (String) entry.getKey(); |
1123 |
|
|
1124 |
45 |
if (key.equalsIgnoreCase(_componentAttributeName)) |
1125 |
35 |
continue; |
1126 |
|
|
1127 |
10 |
String value = (String) entry.getValue(); |
1128 |
|
|
1129 |
10 |
addAttributeToToken(token, key, value); |
1130 |
10 |
} |
1131 |
35 |
} |
1132 |
|
|
1133 |
|
|
1134 |
|
|
1135 |
|
|
1136 |
|
|
1137 |
|
|
1138 |
|
|
1139 |
|
private void addAttributeToToken(OpenToken token, String name, String attributeValue) |
1140 |
|
{ |
1141 |
10 |
token.addAttribute(name, convertEntitiesToPlain(attributeValue)); |
1142 |
10 |
} |
1143 |
|
|
1144 |
|
|
1145 |
|
|
1146 |
|
|
1147 |
|
|
1148 |
|
|
1149 |
|
|
1150 |
|
|
1151 |
|
|
1152 |
|
|
1153 |
|
|
1154 |
|
|
1155 |
|
|
1156 |
|
|
1157 |
|
|
1158 |
|
private void closeTag() throws TemplateParseException |
1159 |
|
{ |
1160 |
63 |
int cursorStart = _cursor; |
1161 |
63 |
int length = _templateData.length; |
1162 |
63 |
int startLine = _line; |
1163 |
|
|
1164 |
63 |
Location startLocation = getCurrentLocation(); |
1165 |
|
|
1166 |
63 |
_cursor += CLOSE_TAG.length; |
1167 |
|
|
1168 |
63 |
int tagStart = _cursor; |
1169 |
|
|
1170 |
|
while (true) |
1171 |
|
{ |
1172 |
272 |
if (_cursor >= length) |
1173 |
1 |
templateParseProblem( |
1174 |
|
ParseMessages.incompleteCloseTag(startLine), |
1175 |
|
startLocation, |
1176 |
|
startLine, |
1177 |
|
cursorStart); |
1178 |
|
|
1179 |
271 |
char ch = _templateData[_cursor]; |
1180 |
|
|
1181 |
271 |
if (ch == '>') |
1182 |
62 |
break; |
1183 |
|
|
1184 |
209 |
advance(); |
1185 |
209 |
} |
1186 |
|
|
1187 |
62 |
String tagName = new String(_templateData, tagStart, _cursor - tagStart); |
1188 |
|
|
1189 |
62 |
int stackPos = _stack.size() - 1; |
1190 |
62 |
Tag tag = null; |
1191 |
|
|
1192 |
69 |
while (stackPos >= 0) |
1193 |
|
{ |
1194 |
68 |
tag = (Tag) _stack.get(stackPos); |
1195 |
|
|
1196 |
68 |
if (tag.match(tagName)) |
1197 |
60 |
break; |
1198 |
|
|
1199 |
8 |
if (tag._mustBalance) |
1200 |
1 |
templateParseProblem(ParseMessages.improperlyNestedCloseTag( |
1201 |
|
tagName, |
1202 |
|
startLine, |
1203 |
|
tag._tagName, |
1204 |
|
tag._line), startLocation, startLine, cursorStart); |
1205 |
|
|
1206 |
7 |
stackPos--; |
1207 |
|
} |
1208 |
|
|
1209 |
61 |
if (stackPos < 0) |
1210 |
1 |
templateParseProblem( |
1211 |
|
ParseMessages.unmatchedCloseTag(tagName, startLine), |
1212 |
|
startLocation, |
1213 |
|
startLine, |
1214 |
|
cursorStart); |
1215 |
|
|
1216 |
|
|
1217 |
|
|
1218 |
60 |
if (tag._content) |
1219 |
|
{ |
1220 |
1 |
addTextToken(cursorStart - 1); |
1221 |
|
|
1222 |
|
|
1223 |
|
|
1224 |
1 |
_cursor = length; |
1225 |
1 |
_stack.clear(); |
1226 |
1 |
return; |
1227 |
|
} |
1228 |
|
|
1229 |
|
|
1230 |
59 |
if (tag._component) |
1231 |
|
{ |
1232 |
14 |
addTextToken(cursorStart - 1); |
1233 |
|
|
1234 |
14 |
_tokens.add(_factory.createCloseToken(tagName, getCurrentLocation())); |
1235 |
|
} |
1236 |
|
else |
1237 |
|
{ |
1238 |
|
|
1239 |
|
|
1240 |
|
|
1241 |
45 |
if (_blockStart < 0 && !tag._removeTag && !_ignoring) |
1242 |
4 |
_blockStart = cursorStart; |
1243 |
|
} |
1244 |
|
|
1245 |
|
|
1246 |
|
|
1247 |
122 |
for (int i = _stack.size() - 1; i >= stackPos; i--) |
1248 |
63 |
_stack.remove(i); |
1249 |
|
|
1250 |
|
|
1251 |
|
|
1252 |
59 |
advance(); |
1253 |
|
|
1254 |
|
|
1255 |
|
|
1256 |
|
|
1257 |
|
|
1258 |
59 |
if (tag._removeTag) |
1259 |
2 |
advanceOverWhitespace(); |
1260 |
|
|
1261 |
|
|
1262 |
|
|
1263 |
|
|
1264 |
59 |
if (tag._ignoringBody) |
1265 |
6 |
_ignoring = false; |
1266 |
59 |
} |
1267 |
|
|
1268 |
|
|
1269 |
|
|
1270 |
|
|
1271 |
|
|
1272 |
|
|
1273 |
|
private void advance() |
1274 |
|
{ |
1275 |
5439 |
int length = _templateData.length; |
1276 |
|
|
1277 |
5439 |
if (_cursor >= length) |
1278 |
0 |
return; |
1279 |
|
|
1280 |
5439 |
char ch = _templateData[_cursor]; |
1281 |
|
|
1282 |
5439 |
_cursor++; |
1283 |
|
|
1284 |
5439 |
if (ch == '\n') |
1285 |
|
{ |
1286 |
278 |
_line++; |
1287 |
278 |
_currentLocation = null; |
1288 |
278 |
return; |
1289 |
|
} |
1290 |
|
|
1291 |
|
|
1292 |
|
|
1293 |
5161 |
if (ch == '\r') |
1294 |
|
{ |
1295 |
0 |
_line++; |
1296 |
0 |
_currentLocation = null; |
1297 |
|
|
1298 |
0 |
if (_cursor < length && _templateData[_cursor] == '\n') |
1299 |
0 |
_cursor++; |
1300 |
|
|
1301 |
0 |
return; |
1302 |
|
} |
1303 |
|
|
1304 |
|
|
1305 |
5161 |
} |
1306 |
|
|
1307 |
|
private void advanceOverWhitespace() |
1308 |
|
{ |
1309 |
7 |
int length = _templateData.length; |
1310 |
|
|
1311 |
18 |
while (_cursor < length) |
1312 |
|
{ |
1313 |
18 |
char ch = _templateData[_cursor]; |
1314 |
18 |
if (!Character.isWhitespace(ch)) |
1315 |
7 |
return; |
1316 |
|
|
1317 |
11 |
advance(); |
1318 |
11 |
} |
1319 |
0 |
} |
1320 |
|
|
1321 |
|
|
1322 |
|
|
1323 |
|
|
1324 |
|
|
1325 |
|
|
1326 |
|
|
1327 |
|
private Map filter(Map input, String[] removeKeys) |
1328 |
|
{ |
1329 |
7 |
if (input == null || input.isEmpty()) |
1330 |
0 |
return null; |
1331 |
|
|
1332 |
7 |
Map result = null; |
1333 |
|
|
1334 |
7 |
Iterator i = input.entrySet().iterator(); |
1335 |
|
|
1336 |
16 |
nextkey: while (i.hasNext()) |
1337 |
|
{ |
1338 |
9 |
Map.Entry entry = (Map.Entry) i.next(); |
1339 |
|
|
1340 |
9 |
String key = (String) entry.getKey(); |
1341 |
|
|
1342 |
13 |
for (int j = 0; j < removeKeys.length; j++) |
1343 |
|
{ |
1344 |
11 |
if (key.equalsIgnoreCase(removeKeys[j])) |
1345 |
7 |
continue nextkey; |
1346 |
|
} |
1347 |
|
|
1348 |
2 |
if (result == null) |
1349 |
1 |
result = new HashMap(input.size()); |
1350 |
|
|
1351 |
2 |
result.put(key, entry.getValue()); |
1352 |
2 |
} |
1353 |
|
|
1354 |
7 |
return result; |
1355 |
|
} |
1356 |
|
|
1357 |
|
|
1358 |
|
|
1359 |
|
|
1360 |
|
|
1361 |
|
|
1362 |
|
|
1363 |
|
protected String findValueCaselessly(String key, Map map) |
1364 |
|
{ |
1365 |
235 |
String result = (String) map.get(key); |
1366 |
|
|
1367 |
235 |
if (result != null) |
1368 |
51 |
return result; |
1369 |
|
|
1370 |
184 |
Iterator i = map.entrySet().iterator(); |
1371 |
261 |
while (i.hasNext()) |
1372 |
|
{ |
1373 |
80 |
Map.Entry entry = (Map.Entry) i.next(); |
1374 |
|
|
1375 |
80 |
String entryKey = (String) entry.getKey(); |
1376 |
|
|
1377 |
80 |
if (entryKey.equalsIgnoreCase(key)) |
1378 |
3 |
return (String) entry.getValue(); |
1379 |
77 |
} |
1380 |
|
|
1381 |
181 |
return null; |
1382 |
|
} |
1383 |
|
|
1384 |
|
|
1385 |
|
|
1386 |
|
|
1387 |
|
|
1388 |
|
|
1389 |
|
|
1390 |
|
|
1391 |
|
private String convertEntitiesToPlain(String input) |
1392 |
|
{ |
1393 |
10 |
int inputLength = input.length(); |
1394 |
|
|
1395 |
10 |
StringBuffer buffer = new StringBuffer(inputLength); |
1396 |
|
|
1397 |
10 |
int cursor = 0; |
1398 |
|
|
1399 |
159 |
outer: while (cursor < inputLength) |
1400 |
|
{ |
1401 |
729 |
for (int i = 0; i < CONVERSIONS.length; i += 2) |
1402 |
|
{ |
1403 |
587 |
String entity = CONVERSIONS[i]; |
1404 |
587 |
int entityLength = entity.length(); |
1405 |
587 |
String value = CONVERSIONS[i + 1]; |
1406 |
|
|
1407 |
587 |
if (cursor + entityLength > inputLength) |
1408 |
139 |
continue; |
1409 |
|
|
1410 |
448 |
if (input.substring(cursor, cursor + entityLength).equals(entity)) |
1411 |
|
{ |
1412 |
7 |
buffer.append(value); |
1413 |
7 |
cursor += entityLength; |
1414 |
7 |
continue outer; |
1415 |
|
} |
1416 |
|
} |
1417 |
|
|
1418 |
142 |
buffer.append(input.charAt(cursor)); |
1419 |
142 |
cursor++; |
1420 |
|
} |
1421 |
|
|
1422 |
10 |
return buffer.toString().trim(); |
1423 |
|
} |
1424 |
|
|
1425 |
|
|
1426 |
|
|
1427 |
|
|
1428 |
|
|
1429 |
|
|
1430 |
|
private boolean checkBoolean(String key, Map map) |
1431 |
|
{ |
1432 |
7 |
String value = findValueCaselessly(key, map); |
1433 |
|
|
1434 |
7 |
if (value == null) |
1435 |
7 |
return false; |
1436 |
|
|
1437 |
0 |
return value.equalsIgnoreCase("true"); |
1438 |
|
} |
1439 |
|
|
1440 |
|
|
1441 |
|
|
1442 |
|
|
1443 |
|
|
1444 |
|
|
1445 |
|
|
1446 |
|
|
1447 |
|
protected Location getCurrentLocation() |
1448 |
|
{ |
1449 |
97 |
if (_currentLocation == null) |
1450 |
78 |
_currentLocation = new LocationImpl(_resourceLocation, _line); |
1451 |
|
|
1452 |
97 |
return _currentLocation; |
1453 |
|
} |
1454 |
|
|
1455 |
|
public void setFactory(TemplateTokenFactory factory) |
1456 |
|
{ |
1457 |
34 |
_factory = factory; |
1458 |
34 |
} |
1459 |
|
|
1460 |
|
} |