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