1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.parse; |
16 |
|
|
17 |
|
import org.apache.commons.logging.Log; |
18 |
|
import org.apache.commons.logging.LogFactory; |
19 |
|
import org.apache.hivemind.*; |
20 |
|
import org.apache.hivemind.impl.DefaultErrorHandler; |
21 |
|
import org.apache.hivemind.impl.LocationImpl; |
22 |
|
import org.apache.hivemind.parse.AbstractParser; |
23 |
|
import org.apache.tapestry.INamespace; |
24 |
|
import org.apache.tapestry.Tapestry; |
25 |
|
import org.apache.tapestry.bean.BindingBeanInitializer; |
26 |
|
import org.apache.tapestry.bean.LightweightBeanInitializer; |
27 |
|
import org.apache.tapestry.binding.BindingConstants; |
28 |
|
import org.apache.tapestry.binding.BindingSource; |
29 |
|
import org.apache.tapestry.coerce.ValueConverter; |
30 |
|
import org.apache.tapestry.spec.*; |
31 |
|
import org.apache.tapestry.util.IPropertyHolder; |
32 |
|
import org.apache.tapestry.util.RegexpMatcher; |
33 |
|
import org.apache.tapestry.util.xml.DocumentParseException; |
34 |
|
import org.apache.tapestry.util.xml.InvalidStringException; |
35 |
|
import org.xml.sax.InputSource; |
36 |
|
import org.xml.sax.SAXException; |
37 |
|
import org.xml.sax.SAXParseException; |
38 |
|
|
39 |
|
import javax.xml.parsers.SAXParser; |
40 |
|
import javax.xml.parsers.SAXParserFactory; |
41 |
|
import java.io.BufferedInputStream; |
42 |
|
import java.io.IOException; |
43 |
|
import java.io.InputStream; |
44 |
|
import java.net.URL; |
45 |
|
import java.util.HashMap; |
46 |
|
import java.util.Iterator; |
47 |
|
import java.util.Map; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
public class SpecificationParser extends AbstractParser implements ISpecificationParser |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
public static final String ASSET_NAME_PATTERN = "(\\$template)|(" + Tapestry.SIMPLE_PROPERTY_NAME_PATTERN + ")"; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public static final String BEAN_NAME_PATTERN = Tapestry.SIMPLE_PROPERTY_NAME_PATTERN; |
74 |
|
|
75 |
|
public static final String IDENTIFIER_PATTERN = "_?[a-zA-Z]\\w*"; |
76 |
|
|
77 |
|
public static final String EXTENDED_IDENTIFIER_PATTERN = "_?[a-zA-Z](\\w|-)*"; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
public static final String COMPONENT_ALIAS_PATTERN = "^(" + IDENTIFIER_PATTERN + "/)*" |
89 |
|
+ IDENTIFIER_PATTERN + "$"; |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
public static final String COMPONENT_ID_PATTERN = Tapestry.SIMPLE_PROPERTY_NAME_PATTERN; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
public static final String COMPONENT_TYPE_PATTERN = "^(" + IDENTIFIER_PATTERN + ":)?" + "(" |
109 |
|
+ IDENTIFIER_PATTERN + "/)*" + IDENTIFIER_PATTERN + "$"; |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
public static final String EXTENDED_PROPERTY_NAME_PATTERN = "^" + EXTENDED_IDENTIFIER_PATTERN |
120 |
|
+ "(\\." + EXTENDED_IDENTIFIER_PATTERN + ")*$"; |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
public static final String EXTENSION_NAME_PATTERN = EXTENDED_PROPERTY_NAME_PATTERN; |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
public static final String LIBRARY_ID_PATTERN = Tapestry.SIMPLE_PROPERTY_NAME_PATTERN; |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
public static final String PAGE_NAME_PATTERN = "^" + IDENTIFIER_PATTERN + "(/" + EXTENDED_IDENTIFIER_PATTERN + ")*$"; |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
public static final String PARAMETER_NAME_PATTERN = Tapestry.SIMPLE_PROPERTY_NAME_PATTERN; |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
public static final String PROPERTY_NAME_PATTERN = Tapestry.SIMPLE_PROPERTY_NAME_PATTERN; |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
public static final String SERVICE_NAME_PATTERN = EXTENDED_PROPERTY_NAME_PATTERN; |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
public static final String TAPESTRY_DTD_3_0_PUBLIC_ID = "-//Apache Software Foundation//Tapestry Specification 3.0//EN"; |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
public static final String TAPESTRY_DTD_4_0_PUBLIC_ID = "-//Apache Software Foundation//Tapestry Specification 4.0//EN"; |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
public static final String TAPESTRY_DTD_4_1_PUBLIC_ID = "-//Apache Software Foundation//Tapestry Specification 4.1//EN"; |
190 |
|
|
191 |
|
private static final int STATE_ALLOW_DESCRIPTION = 2000; |
192 |
|
|
193 |
|
private static final int STATE_ALLOW_PROPERTY = 2001; |
194 |
|
|
195 |
|
private static final int STATE_APPLICATION_SPECIFICATION_INITIAL = 1002; |
196 |
|
|
197 |
|
private static final int STATE_BEAN = 4; |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
private static final int STATE_BINDING_3_0 = 7; |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
private static final int STATE_BINDING = 100; |
206 |
|
|
207 |
|
private static final int STATE_COMPONENT = 6; |
208 |
|
|
209 |
|
private static final int STATE_COMPONENT_SPECIFICATION = 1; |
210 |
|
|
211 |
|
private static final int STATE_COMPONENT_SPECIFICATION_INITIAL = 1000; |
212 |
|
|
213 |
|
private static final int STATE_CONFIGURE = 14; |
214 |
|
|
215 |
|
private static final int STATE_DESCRIPTION = 2; |
216 |
|
|
217 |
|
private static final int STATE_EXTENSION = 13; |
218 |
|
|
219 |
|
private static final int STATE_LIBRARY_SPECIFICATION = 12; |
220 |
|
|
221 |
|
private static final int STATE_LIBRARY_SPECIFICATION_INITIAL = 1003; |
222 |
|
|
223 |
|
private static final int STATE_LISTENER_BINDING = 8; |
224 |
|
|
225 |
|
private static final int STATE_NO_CONTENT = 3000; |
226 |
|
|
227 |
|
private static final int STATE_PAGE_SPECIFICATION = 11; |
228 |
|
|
229 |
|
private static final int STATE_PAGE_SPECIFICATION_INITIAL = 1001; |
230 |
|
|
231 |
|
private static final int STATE_META = 3; |
232 |
|
|
233 |
|
private static final int STATE_PROPERTY = 10; |
234 |
|
|
235 |
|
private static final int STATE_SET = 5; |
236 |
|
|
237 |
|
|
238 |
|
private static final int STATE_STATIC_BINDING = 9; |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
64 |
private final Map _conversionMap = new HashMap(); |
246 |
|
|
247 |
|
|
248 |
|
private final Log _log; |
249 |
|
|
250 |
|
|
251 |
|
private final ErrorHandler _errorHandler; |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
private boolean _dtd40; |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
private Map _attributes; |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
private String _elementName; |
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
private final SpecFactory _factory; |
276 |
|
|
277 |
64 |
private RegexpMatcher _matcher = new RegexpMatcher(); |
278 |
|
|
279 |
|
private SAXParser _parser; |
280 |
|
|
281 |
64 |
private SAXParserFactory _parserFactory = SAXParserFactory.newInstance(); |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
private final ClassResolver _resolver; |
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
private BindingSource _bindingSource; |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
|
private Object _rootObject; |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
private ValueConverter _valueConverter; |
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
{ |
310 |
|
|
311 |
64 |
_conversionMap.put("true", Boolean.TRUE); |
312 |
64 |
_conversionMap.put("t", Boolean.TRUE); |
313 |
64 |
_conversionMap.put("1", Boolean.TRUE); |
314 |
64 |
_conversionMap.put("y", Boolean.TRUE); |
315 |
64 |
_conversionMap.put("yes", Boolean.TRUE); |
316 |
64 |
_conversionMap.put("on", Boolean.TRUE); |
317 |
64 |
_conversionMap.put("aye", Boolean.TRUE); |
318 |
|
|
319 |
64 |
_conversionMap.put("false", Boolean.FALSE); |
320 |
64 |
_conversionMap.put("f", Boolean.FALSE); |
321 |
64 |
_conversionMap.put("0", Boolean.FALSE); |
322 |
64 |
_conversionMap.put("off", Boolean.FALSE); |
323 |
64 |
_conversionMap.put("no", Boolean.FALSE); |
324 |
64 |
_conversionMap.put("n", Boolean.FALSE); |
325 |
64 |
_conversionMap.put("nay", Boolean.FALSE); |
326 |
|
|
327 |
64 |
_conversionMap.put("none", BeanLifecycle.NONE); |
328 |
64 |
_conversionMap.put("request", BeanLifecycle.REQUEST); |
329 |
64 |
_conversionMap.put("page", BeanLifecycle.PAGE); |
330 |
64 |
_conversionMap.put("render", BeanLifecycle.RENDER); |
331 |
|
|
332 |
64 |
_parserFactory.setNamespaceAware(false); |
333 |
64 |
_parserFactory.setValidating(true); |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
public SpecificationParser(ClassResolver resolver) |
340 |
|
{ |
341 |
63 |
this(new DefaultErrorHandler(), LogFactory.getLog(SpecificationParser.class), |
342 |
|
resolver, new SpecFactory()); |
343 |
62 |
} |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
public SpecificationParser(ErrorHandler errorHandler, Log log, ClassResolver resolver, |
349 |
|
SpecFactory factory) |
350 |
64 |
{ |
351 |
64 |
_errorHandler = errorHandler; |
352 |
64 |
_log = log; |
353 |
64 |
_resolver = resolver; |
354 |
64 |
_factory = factory; |
355 |
64 |
} |
356 |
|
|
357 |
|
protected void begin(String elementName, Map attributes) |
358 |
|
{ |
359 |
240 |
_elementName = elementName; |
360 |
240 |
_attributes = attributes; |
361 |
|
|
362 |
240 |
switch (getState()) |
363 |
|
{ |
364 |
|
case STATE_COMPONENT_SPECIFICATION_INITIAL: |
365 |
|
|
366 |
27 |
beginComponentSpecificationInitial(); |
367 |
26 |
break; |
368 |
|
|
369 |
|
case STATE_PAGE_SPECIFICATION_INITIAL: |
370 |
|
|
371 |
15 |
beginPageSpecificationInitial(); |
372 |
15 |
break; |
373 |
|
|
374 |
|
case STATE_APPLICATION_SPECIFICATION_INITIAL: |
375 |
|
|
376 |
13 |
beginApplicationSpecificationInitial(); |
377 |
13 |
break; |
378 |
|
|
379 |
|
case STATE_LIBRARY_SPECIFICATION_INITIAL: |
380 |
|
|
381 |
7 |
beginLibrarySpecificationInitial(); |
382 |
7 |
break; |
383 |
|
|
384 |
|
case STATE_COMPONENT_SPECIFICATION: |
385 |
|
|
386 |
44 |
beginComponentSpecification(); |
387 |
38 |
break; |
388 |
|
|
389 |
|
case STATE_PAGE_SPECIFICATION: |
390 |
|
|
391 |
23 |
beginPageSpecification(); |
392 |
23 |
break; |
393 |
|
|
394 |
|
case STATE_ALLOW_DESCRIPTION: |
395 |
|
|
396 |
1 |
beginAllowDescription(); |
397 |
1 |
break; |
398 |
|
|
399 |
|
case STATE_ALLOW_PROPERTY: |
400 |
|
|
401 |
3 |
allowMetaData(); |
402 |
3 |
break; |
403 |
|
|
404 |
|
case STATE_BEAN: |
405 |
|
|
406 |
13 |
beginBean(); |
407 |
13 |
break; |
408 |
|
|
409 |
|
case STATE_COMPONENT: |
410 |
|
|
411 |
19 |
beginComponent(); |
412 |
19 |
break; |
413 |
|
|
414 |
|
case STATE_LIBRARY_SPECIFICATION: |
415 |
|
|
416 |
48 |
beginLibrarySpecification(); |
417 |
43 |
break; |
418 |
|
|
419 |
|
case STATE_EXTENSION: |
420 |
|
|
421 |
27 |
beginExtension(); |
422 |
27 |
break; |
423 |
|
|
424 |
|
default: |
425 |
|
|
426 |
0 |
unexpectedElement(_elementName); |
427 |
|
} |
428 |
228 |
} |
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
435 |
|
private void beginAllowDescription() |
436 |
|
{ |
437 |
1 |
if (_elementName.equals("description")) |
438 |
|
{ |
439 |
1 |
enterDescription(); |
440 |
1 |
return; |
441 |
|
} |
442 |
|
|
443 |
0 |
unexpectedElement(_elementName); |
444 |
0 |
} |
445 |
|
|
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
private void allowMetaData() |
452 |
|
{ |
453 |
21 |
if (_dtd40) |
454 |
|
{ |
455 |
2 |
if (_elementName.equals("meta")) |
456 |
|
{ |
457 |
2 |
enterMeta(); |
458 |
2 |
return; |
459 |
|
} |
460 |
|
} |
461 |
19 |
else if (_elementName.equals("property")) |
462 |
|
{ |
463 |
19 |
enterProperty30(); |
464 |
19 |
return; |
465 |
|
} |
466 |
|
|
467 |
0 |
unexpectedElement(_elementName); |
468 |
0 |
} |
469 |
|
|
470 |
|
private void beginApplicationSpecificationInitial() |
471 |
|
{ |
472 |
13 |
expectElement("application"); |
473 |
|
|
474 |
13 |
String name = getAttribute("name"); |
475 |
13 |
String engineClassName = getAttribute("engine-class"); |
476 |
|
|
477 |
13 |
IApplicationSpecification as = _factory.createApplicationSpecification(); |
478 |
|
|
479 |
13 |
as.setName(name); |
480 |
|
|
481 |
13 |
if (HiveMind.isNonBlank(engineClassName)) |
482 |
0 |
as.setEngineClassName(engineClassName); |
483 |
|
|
484 |
13 |
_rootObject = as; |
485 |
|
|
486 |
13 |
push(_elementName, as, STATE_LIBRARY_SPECIFICATION); |
487 |
13 |
} |
488 |
|
|
489 |
|
private void beginBean() |
490 |
|
{ |
491 |
13 |
if (_elementName.equals("set")) |
492 |
|
{ |
493 |
3 |
enterSet(); |
494 |
3 |
return; |
495 |
|
} |
496 |
|
|
497 |
10 |
if (_elementName.equals("set-property")) |
498 |
|
{ |
499 |
2 |
enterSetProperty30(); |
500 |
2 |
return; |
501 |
|
} |
502 |
|
|
503 |
8 |
if (_elementName.equals("set-message-property")) |
504 |
|
{ |
505 |
1 |
enterSetMessage30(); |
506 |
1 |
return; |
507 |
|
} |
508 |
|
|
509 |
7 |
if (_elementName.equals("description")) |
510 |
|
{ |
511 |
2 |
enterDescription(); |
512 |
2 |
return; |
513 |
|
} |
514 |
|
|
515 |
5 |
allowMetaData(); |
516 |
5 |
} |
517 |
|
|
518 |
|
private void beginComponent() |
519 |
|
{ |
520 |
|
|
521 |
|
|
522 |
19 |
if (_elementName.equals("binding")) |
523 |
|
{ |
524 |
7 |
enterBinding(); |
525 |
7 |
return; |
526 |
|
} |
527 |
|
|
528 |
12 |
if (_elementName.equals("static-binding")) |
529 |
|
{ |
530 |
6 |
enterStaticBinding30(); |
531 |
6 |
return; |
532 |
|
} |
533 |
|
|
534 |
6 |
if (_elementName.equals("message-binding")) |
535 |
|
{ |
536 |
1 |
enterMessageBinding30(); |
537 |
1 |
return; |
538 |
|
} |
539 |
|
|
540 |
5 |
if (_elementName.equals("inherited-binding")) |
541 |
|
{ |
542 |
0 |
enterInheritedBinding30(); |
543 |
0 |
return; |
544 |
|
} |
545 |
|
|
546 |
5 |
if (_elementName.equals("listener-binding")) |
547 |
|
{ |
548 |
1 |
enterListenerBinding(); |
549 |
1 |
return; |
550 |
|
} |
551 |
|
|
552 |
4 |
allowMetaData(); |
553 |
4 |
} |
554 |
|
|
555 |
|
private void beginComponentSpecification() |
556 |
|
{ |
557 |
44 |
if (_elementName.equals("reserved-parameter")) |
558 |
|
{ |
559 |
0 |
enterReservedParameter(); |
560 |
0 |
return; |
561 |
|
} |
562 |
|
|
563 |
44 |
if (_elementName.equals("parameter")) |
564 |
|
{ |
565 |
14 |
enterParameter(); |
566 |
13 |
return; |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
30 |
beginPageSpecification(); |
573 |
25 |
} |
574 |
|
|
575 |
|
private void beginComponentSpecificationInitial() |
576 |
|
{ |
577 |
27 |
expectElement("component-specification"); |
578 |
|
|
579 |
26 |
IComponentSpecification cs = _factory.createComponentSpecification(); |
580 |
|
|
581 |
26 |
cs.setAllowBody(getBooleanAttribute("allow-body", true)); |
582 |
26 |
cs.setAllowInformalParameters(getBooleanAttribute("allow-informal-parameters", true)); |
583 |
26 |
cs.setDeprecated(getBooleanAttribute("deprecated", false)); |
584 |
|
|
585 |
26 |
String className = getAttribute("class"); |
586 |
|
|
587 |
26 |
if (className != null) |
588 |
7 |
cs.setComponentClassName(className); |
589 |
|
|
590 |
26 |
cs.setSpecificationLocation(getResource()); |
591 |
|
|
592 |
26 |
_rootObject = cs; |
593 |
|
|
594 |
26 |
push(_elementName, cs, STATE_COMPONENT_SPECIFICATION); |
595 |
26 |
} |
596 |
|
|
597 |
|
private void beginExtension() |
598 |
|
{ |
599 |
27 |
if (_elementName.equals("configure")) |
600 |
|
{ |
601 |
24 |
enterConfigure(); |
602 |
24 |
return; |
603 |
|
} |
604 |
|
|
605 |
3 |
allowMetaData(); |
606 |
3 |
} |
607 |
|
|
608 |
|
private void beginLibrarySpecification() |
609 |
|
{ |
610 |
48 |
if (_elementName.equals("description")) |
611 |
|
{ |
612 |
1 |
enterDescription(); |
613 |
1 |
return; |
614 |
|
} |
615 |
|
|
616 |
47 |
if (_elementName.equals("page")) |
617 |
|
{ |
618 |
19 |
enterPage(); |
619 |
18 |
return; |
620 |
|
} |
621 |
|
|
622 |
28 |
if (_elementName.equals("component-type")) |
623 |
|
{ |
624 |
10 |
enterComponentType(); |
625 |
9 |
return; |
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
|
|
630 |
18 |
if (_elementName.equals("service")) |
631 |
|
{ |
632 |
0 |
enterService30(); |
633 |
0 |
return; |
634 |
|
} |
635 |
|
|
636 |
18 |
if (_elementName.equals("library")) |
637 |
|
{ |
638 |
5 |
enterLibrary(); |
639 |
3 |
return; |
640 |
|
} |
641 |
|
|
642 |
13 |
if (_elementName.equals("extension")) |
643 |
|
{ |
644 |
9 |
enterExtension(); |
645 |
8 |
return; |
646 |
|
} |
647 |
|
|
648 |
4 |
allowMetaData(); |
649 |
4 |
} |
650 |
|
|
651 |
|
private void beginLibrarySpecificationInitial() |
652 |
|
{ |
653 |
7 |
expectElement("library-specification"); |
654 |
|
|
655 |
7 |
ILibrarySpecification ls = _factory.createLibrarySpecification(); |
656 |
|
|
657 |
7 |
_rootObject = ls; |
658 |
|
|
659 |
7 |
push(_elementName, ls, STATE_LIBRARY_SPECIFICATION); |
660 |
7 |
} |
661 |
|
|
662 |
|
private void beginPageSpecification() |
663 |
|
{ |
664 |
53 |
if (_elementName.equals("component")) |
665 |
|
{ |
666 |
23 |
enterComponent(); |
667 |
19 |
return; |
668 |
|
} |
669 |
|
|
670 |
30 |
if (_elementName.equals("bean")) |
671 |
|
{ |
672 |
8 |
enterBean(); |
673 |
8 |
return; |
674 |
|
} |
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
22 |
if (_elementName.equals("property-specification") |
680 |
|
|| (_dtd40 && _elementName.equals("property"))) |
681 |
|
{ |
682 |
8 |
enterProperty(); |
683 |
8 |
return; |
684 |
|
} |
685 |
|
|
686 |
14 |
if (_elementName.equals("inject")) |
687 |
|
{ |
688 |
2 |
enterInject(); |
689 |
2 |
return; |
690 |
|
} |
691 |
|
|
692 |
|
|
693 |
|
|
694 |
12 |
if (_elementName.equals("asset")) |
695 |
|
{ |
696 |
1 |
enterAsset(); |
697 |
1 |
return; |
698 |
|
} |
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
11 |
if (_elementName.equals("context-asset")) |
705 |
|
{ |
706 |
2 |
enterContextAsset30(); |
707 |
2 |
return; |
708 |
|
} |
709 |
|
|
710 |
9 |
if (_elementName.equals("private-asset")) |
711 |
|
{ |
712 |
4 |
enterPrivateAsset30(); |
713 |
3 |
return; |
714 |
|
} |
715 |
|
|
716 |
5 |
if (_elementName.equals("external-asset")) |
717 |
|
{ |
718 |
2 |
enterExternalAsset30(); |
719 |
2 |
return; |
720 |
|
|
721 |
|
} |
722 |
|
|
723 |
3 |
if (_elementName.equals("description")) |
724 |
|
{ |
725 |
1 |
enterDescription(); |
726 |
1 |
return; |
727 |
|
} |
728 |
|
|
729 |
2 |
allowMetaData(); |
730 |
2 |
} |
731 |
|
|
732 |
|
private void beginPageSpecificationInitial() |
733 |
|
{ |
734 |
15 |
expectElement("page-specification"); |
735 |
|
|
736 |
15 |
IComponentSpecification cs = _factory.createComponentSpecification(); |
737 |
|
|
738 |
15 |
String className = getAttribute("class"); |
739 |
|
|
740 |
15 |
if (className != null) |
741 |
0 |
cs.setComponentClassName(className); |
742 |
|
|
743 |
15 |
cs.setSpecificationLocation(getResource()); |
744 |
15 |
cs.setPageSpecification(true); |
745 |
|
|
746 |
15 |
_rootObject = cs; |
747 |
|
|
748 |
15 |
push(_elementName, cs, STATE_PAGE_SPECIFICATION); |
749 |
15 |
} |
750 |
|
|
751 |
|
|
752 |
|
|
753 |
|
|
754 |
|
private void close(InputStream stream) |
755 |
|
{ |
756 |
|
try |
757 |
|
{ |
758 |
64 |
if (stream != null) |
759 |
17 |
stream.close(); |
760 |
|
} |
761 |
0 |
catch (IOException ex) |
762 |
|
{ |
763 |
|
|
764 |
64 |
} |
765 |
64 |
} |
766 |
|
|
767 |
|
private void copyBindings(String sourceComponentId, IComponentSpecification cs, |
768 |
|
IContainedComponent target) |
769 |
|
{ |
770 |
3 |
IContainedComponent source = cs.getComponent(sourceComponentId); |
771 |
3 |
if (source == null) |
772 |
1 |
throw new DocumentParseException(ParseMessages.unableToCopy(sourceComponentId), |
773 |
|
getLocation()); |
774 |
|
|
775 |
2 |
Iterator i = source.getBindingNames().iterator(); |
776 |
6 |
while (i.hasNext()) |
777 |
|
{ |
778 |
4 |
String bindingName = (String) i.next(); |
779 |
4 |
IBindingSpecification binding = source.getBinding(bindingName); |
780 |
4 |
target.setBinding(bindingName, binding); |
781 |
4 |
} |
782 |
|
|
783 |
2 |
target.setType(source.getType()); |
784 |
2 |
} |
785 |
|
|
786 |
|
protected void end(String elementName) |
787 |
|
{ |
788 |
211 |
_elementName = elementName; |
789 |
|
|
790 |
211 |
switch (getState()) |
791 |
|
{ |
792 |
|
case STATE_DESCRIPTION: |
793 |
|
|
794 |
5 |
endDescription(); |
795 |
5 |
break; |
796 |
|
|
797 |
|
case STATE_META: |
798 |
|
|
799 |
21 |
endProperty(); |
800 |
21 |
break; |
801 |
|
|
802 |
|
case STATE_SET: |
803 |
|
|
804 |
5 |
endSetProperty(); |
805 |
5 |
break; |
806 |
|
|
807 |
|
case STATE_BINDING_3_0: |
808 |
|
|
809 |
4 |
endBinding30(); |
810 |
3 |
break; |
811 |
|
|
812 |
|
case STATE_BINDING: |
813 |
|
|
814 |
3 |
endBinding(); |
815 |
3 |
break; |
816 |
|
|
817 |
|
case STATE_STATIC_BINDING: |
818 |
|
|
819 |
6 |
endStaticBinding(); |
820 |
5 |
break; |
821 |
|
|
822 |
|
case STATE_PROPERTY: |
823 |
|
|
824 |
8 |
endPropertySpecification(); |
825 |
8 |
break; |
826 |
|
|
827 |
|
case STATE_LIBRARY_SPECIFICATION: |
828 |
|
|
829 |
15 |
endLibrarySpecification(); |
830 |
15 |
break; |
831 |
|
|
832 |
|
case STATE_CONFIGURE: |
833 |
|
|
834 |
24 |
endConfigure(); |
835 |
24 |
break; |
836 |
|
|
837 |
|
default: |
838 |
|
break; |
839 |
|
} |
840 |
|
|
841 |
|
|
842 |
|
|
843 |
209 |
pop(); |
844 |
209 |
} |
845 |
|
|
846 |
|
private void endBinding30() |
847 |
|
{ |
848 |
4 |
BindingSetter bs = (BindingSetter) peekObject(); |
849 |
|
|
850 |
4 |
String expression = getExtendedValue(bs.getValue(), "expression", true); |
851 |
|
|
852 |
3 |
IBindingSpecification spec = _factory.createBindingSpecification(); |
853 |
|
|
854 |
3 |
spec.setType(BindingType.PREFIXED); |
855 |
3 |
spec.setValue(BindingConstants.OGNL_PREFIX + ":" + expression); |
856 |
|
|
857 |
3 |
bs.apply(spec); |
858 |
3 |
} |
859 |
|
|
860 |
|
private void endConfigure() |
861 |
|
{ |
862 |
24 |
ExtensionConfigurationSetter setter = (ExtensionConfigurationSetter) peekObject(); |
863 |
|
|
864 |
24 |
String finalValue = getExtendedValue(setter.getValue(), "value", true); |
865 |
|
|
866 |
24 |
setter.apply(finalValue); |
867 |
24 |
} |
868 |
|
|
869 |
|
private void endDescription() |
870 |
|
{ |
871 |
5 |
DescriptionSetter setter = (DescriptionSetter) peekObject(); |
872 |
|
|
873 |
5 |
String description = peekContent(); |
874 |
|
|
875 |
5 |
setter.apply(description); |
876 |
5 |
} |
877 |
|
|
878 |
|
private void endLibrarySpecification() |
879 |
|
{ |
880 |
15 |
ILibrarySpecification spec = (ILibrarySpecification) peekObject(); |
881 |
|
|
882 |
15 |
spec.setSpecificationLocation(getResource()); |
883 |
|
|
884 |
15 |
spec.instantiateImmediateExtensions(); |
885 |
15 |
} |
886 |
|
|
887 |
|
private void endProperty() |
888 |
|
{ |
889 |
21 |
PropertyValueSetter pvs = (PropertyValueSetter) peekObject(); |
890 |
|
|
891 |
21 |
String finalValue = getExtendedValue(pvs.getPropertyValue(), "value", true); |
892 |
|
|
893 |
21 |
pvs.applyValue(finalValue); |
894 |
21 |
} |
895 |
|
|
896 |
|
private void endPropertySpecification() |
897 |
|
{ |
898 |
8 |
IPropertySpecification ps = (IPropertySpecification) peekObject(); |
899 |
|
|
900 |
8 |
String initialValue = getExtendedValue(ps.getInitialValue(), "initial-value", false); |
901 |
|
|
902 |
|
|
903 |
|
|
904 |
|
|
905 |
8 |
if (initialValue != null && !_dtd40) |
906 |
2 |
initialValue = BindingConstants.OGNL_PREFIX + ":" + initialValue; |
907 |
|
|
908 |
8 |
ps.setInitialValue(initialValue); |
909 |
8 |
} |
910 |
|
|
911 |
|
private void endSetProperty() |
912 |
|
{ |
913 |
5 |
BeanSetPropertySetter bs = (BeanSetPropertySetter) peekObject(); |
914 |
|
|
915 |
5 |
String finalValue = getExtendedValue(bs.getBindingReference(), "expression", true); |
916 |
|
|
917 |
5 |
bs.applyBindingReference(finalValue); |
918 |
5 |
} |
919 |
|
|
920 |
|
private void endStaticBinding() |
921 |
|
{ |
922 |
6 |
BindingSetter bs = (BindingSetter) peekObject(); |
923 |
|
|
924 |
6 |
String literalValue = getExtendedValue(bs.getValue(), "value", true); |
925 |
|
|
926 |
5 |
IBindingSpecification spec = _factory.createBindingSpecification(); |
927 |
|
|
928 |
5 |
spec.setType(BindingType.PREFIXED); |
929 |
5 |
spec.setValue(BindingConstants.LITERAL_PREFIX + ":" + literalValue); |
930 |
|
|
931 |
5 |
bs.apply(spec); |
932 |
5 |
} |
933 |
|
|
934 |
|
private void enterAsset(String pathAttributeName, String prefix) |
935 |
|
{ |
936 |
9 |
String name = getValidatedAttribute("name", ASSET_NAME_PATTERN, "invalid-asset-name"); |
937 |
8 |
String path = getAttribute(pathAttributeName); |
938 |
8 |
String propertyName = getValidatedAttribute( |
939 |
|
"property", |
940 |
|
PROPERTY_NAME_PATTERN, |
941 |
|
"invalid-property-name"); |
942 |
|
|
943 |
8 |
IAssetSpecification ia = _factory.createAssetSpecification(); |
944 |
|
|
945 |
8 |
ia.setPath(prefix == null ? path : prefix + path); |
946 |
8 |
ia.setPropertyName(propertyName); |
947 |
|
|
948 |
8 |
IComponentSpecification cs = (IComponentSpecification) peekObject(); |
949 |
|
|
950 |
8 |
cs.addAsset(name, ia); |
951 |
|
|
952 |
8 |
push(_elementName, ia, STATE_ALLOW_PROPERTY); |
953 |
8 |
} |
954 |
|
|
955 |
|
private void enterBean() |
956 |
|
{ |
957 |
8 |
String name = getValidatedAttribute("name", BEAN_NAME_PATTERN, "invalid-bean-name"); |
958 |
|
|
959 |
8 |
String classAttribute = getAttribute("class"); |
960 |
|
|
961 |
|
|
962 |
|
|
963 |
8 |
int commax = classAttribute.indexOf(','); |
964 |
|
|
965 |
8 |
String className = commax < 0 ? classAttribute : classAttribute.substring(0, commax); |
966 |
|
|
967 |
8 |
BeanLifecycle lifecycle = (BeanLifecycle) getConvertedAttribute( |
968 |
|
"lifecycle", |
969 |
|
BeanLifecycle.REQUEST); |
970 |
8 |
String propertyName = getValidatedAttribute( |
971 |
|
"property", |
972 |
|
PROPERTY_NAME_PATTERN, |
973 |
|
"invalid-property-name"); |
974 |
|
|
975 |
8 |
IBeanSpecification bs = _factory.createBeanSpecification(); |
976 |
|
|
977 |
8 |
bs.setClassName(className); |
978 |
8 |
bs.setLifecycle(lifecycle); |
979 |
8 |
bs.setPropertyName(propertyName); |
980 |
|
|
981 |
8 |
if (commax > 0) |
982 |
|
{ |
983 |
1 |
String initializer = classAttribute.substring(commax + 1); |
984 |
1 |
bs.addInitializer(new LightweightBeanInitializer(initializer)); |
985 |
|
} |
986 |
|
|
987 |
8 |
IComponentSpecification cs = (IComponentSpecification) peekObject(); |
988 |
|
|
989 |
8 |
cs.addBeanSpecification(name, bs); |
990 |
|
|
991 |
8 |
push(_elementName, bs, STATE_BEAN); |
992 |
8 |
} |
993 |
|
|
994 |
|
private void enterBinding() |
995 |
|
{ |
996 |
7 |
if (!_dtd40) |
997 |
|
{ |
998 |
4 |
enterBinding30(); |
999 |
4 |
return; |
1000 |
|
} |
1001 |
|
|
1002 |
|
|
1003 |
|
|
1004 |
3 |
String name = getValidatedAttribute( |
1005 |
|
"name", |
1006 |
|
PARAMETER_NAME_PATTERN, |
1007 |
|
"invalid-parameter-name"); |
1008 |
3 |
String value = getAttribute("value"); |
1009 |
|
|
1010 |
3 |
IContainedComponent cc = (IContainedComponent) peekObject(); |
1011 |
|
|
1012 |
3 |
BindingSetter bs = new BindingSetter(cc, name, value); |
1013 |
|
|
1014 |
3 |
push(_elementName, bs, STATE_BINDING, false); |
1015 |
3 |
} |
1016 |
|
|
1017 |
|
private void endBinding() |
1018 |
|
{ |
1019 |
3 |
BindingSetter bs = (BindingSetter) peekObject(); |
1020 |
|
|
1021 |
3 |
String value = getExtendedValue(bs.getValue(), "value", true); |
1022 |
|
|
1023 |
3 |
IBindingSpecification spec = _factory.createBindingSpecification(); |
1024 |
|
|
1025 |
3 |
spec.setType(BindingType.PREFIXED); |
1026 |
3 |
spec.setValue(value); |
1027 |
|
|
1028 |
3 |
bs.apply(spec); |
1029 |
3 |
} |
1030 |
|
|
1031 |
|
|
1032 |
|
|
1033 |
|
|
1034 |
|
|
1035 |
|
private void enterBinding30() |
1036 |
|
{ |
1037 |
4 |
String name = getAttribute("name"); |
1038 |
4 |
String expression = getAttribute("expression"); |
1039 |
|
|
1040 |
4 |
IContainedComponent cc = (IContainedComponent) peekObject(); |
1041 |
|
|
1042 |
4 |
BindingSetter bs = new BindingSetter(cc, name, expression); |
1043 |
|
|
1044 |
4 |
push(_elementName, bs, STATE_BINDING_3_0, false); |
1045 |
4 |
} |
1046 |
|
|
1047 |
|
private void enterComponent() |
1048 |
|
{ |
1049 |
23 |
String id = getValidatedAttribute("id", COMPONENT_ID_PATTERN, "invalid-component-id"); |
1050 |
|
|
1051 |
22 |
String type = getValidatedAttribute( |
1052 |
|
"type", |
1053 |
|
COMPONENT_TYPE_PATTERN, |
1054 |
|
"invalid-component-type"); |
1055 |
22 |
String copyOf = getAttribute("copy-of"); |
1056 |
22 |
boolean inherit = getBooleanAttribute("inherit-informal-parameters", false); |
1057 |
22 |
String propertyName = getValidatedAttribute( |
1058 |
|
"property", |
1059 |
|
PROPERTY_NAME_PATTERN, |
1060 |
|
"invalid-property-name"); |
1061 |
|
|
1062 |
|
|
1063 |
|
|
1064 |
22 |
boolean hasCopyOf = HiveMind.isNonBlank(copyOf); |
1065 |
|
|
1066 |
22 |
if (hasCopyOf) |
1067 |
|
{ |
1068 |
4 |
if (HiveMind.isNonBlank(type)) |
1069 |
1 |
throw new DocumentParseException(ParseMessages.bothTypeAndCopyOf(id), getLocation()); |
1070 |
|
} |
1071 |
|
else |
1072 |
|
{ |
1073 |
18 |
if (HiveMind.isBlank(type)) |
1074 |
1 |
throw new DocumentParseException(ParseMessages.missingTypeOrCopyOf(id), |
1075 |
|
getLocation()); |
1076 |
|
} |
1077 |
|
|
1078 |
20 |
IContainedComponent cc = _factory.createContainedComponent(); |
1079 |
20 |
cc.setType(type); |
1080 |
20 |
cc.setCopyOf(copyOf); |
1081 |
20 |
cc.setInheritInformalParameters(inherit); |
1082 |
20 |
cc.setPropertyName(propertyName); |
1083 |
|
|
1084 |
20 |
IComponentSpecification cs = (IComponentSpecification) peekObject(); |
1085 |
|
|
1086 |
20 |
cs.addComponent(id, cc); |
1087 |
|
|
1088 |
20 |
if (hasCopyOf) |
1089 |
3 |
copyBindings(copyOf, cs, cc); |
1090 |
|
|
1091 |
19 |
push(_elementName, cc, STATE_COMPONENT); |
1092 |
19 |
} |
1093 |
|
|
1094 |
|
private void enterComponentType() |
1095 |
|
{ |
1096 |
10 |
String type = getValidatedAttribute( |
1097 |
|
"type", |
1098 |
|
COMPONENT_ALIAS_PATTERN, |
1099 |
|
"invalid-component-type"); |
1100 |
9 |
String path = getAttribute("specification-path"); |
1101 |
|
|
1102 |
9 |
ILibrarySpecification ls = (ILibrarySpecification) peekObject(); |
1103 |
|
|
1104 |
9 |
ls.setComponentSpecificationPath(type, path); |
1105 |
|
|
1106 |
9 |
push(_elementName, null, STATE_NO_CONTENT); |
1107 |
9 |
} |
1108 |
|
|
1109 |
|
private void enterConfigure() |
1110 |
|
{ |
1111 |
24 |
String attributeName = _dtd40 ? "property" : "property-name"; |
1112 |
|
|
1113 |
24 |
String propertyName = getValidatedAttribute( |
1114 |
|
attributeName, |
1115 |
|
PROPERTY_NAME_PATTERN, |
1116 |
|
"invalid-property-name"); |
1117 |
|
|
1118 |
24 |
String value = getAttribute("value"); |
1119 |
|
|
1120 |
24 |
IExtensionSpecification es = (IExtensionSpecification) peekObject(); |
1121 |
|
|
1122 |
24 |
ExtensionConfigurationSetter setter = new ExtensionConfigurationSetter(es, propertyName, |
1123 |
|
value); |
1124 |
|
|
1125 |
24 |
push(_elementName, setter, STATE_CONFIGURE, false); |
1126 |
24 |
} |
1127 |
|
|
1128 |
|
private void enterContextAsset30() |
1129 |
|
{ |
1130 |
2 |
enterAsset("path", "context:"); |
1131 |
2 |
} |
1132 |
|
|
1133 |
|
|
1134 |
|
|
1135 |
|
|
1136 |
|
|
1137 |
|
|
1138 |
|
|
1139 |
|
|
1140 |
|
private void enterAsset() |
1141 |
|
{ |
1142 |
1 |
enterAsset("path", null); |
1143 |
1 |
} |
1144 |
|
|
1145 |
|
private void enterDescription() |
1146 |
|
{ |
1147 |
5 |
push(_elementName, new DescriptionSetter(peekObject()), STATE_DESCRIPTION, false); |
1148 |
5 |
} |
1149 |
|
|
1150 |
|
private void enterExtension() |
1151 |
|
{ |
1152 |
9 |
String name = getValidatedAttribute( |
1153 |
|
"name", |
1154 |
|
EXTENSION_NAME_PATTERN, |
1155 |
|
"invalid-extension-name"); |
1156 |
|
|
1157 |
8 |
boolean immediate = getBooleanAttribute("immediate", false); |
1158 |
8 |
String className = getAttribute("class"); |
1159 |
|
|
1160 |
8 |
IExtensionSpecification es = _factory.createExtensionSpecification( |
1161 |
|
_resolver, |
1162 |
|
_valueConverter); |
1163 |
|
|
1164 |
8 |
es.setClassName(className); |
1165 |
8 |
es.setImmediate(immediate); |
1166 |
|
|
1167 |
8 |
ILibrarySpecification ls = (ILibrarySpecification) peekObject(); |
1168 |
|
|
1169 |
8 |
ls.addExtensionSpecification(name, es); |
1170 |
|
|
1171 |
8 |
push(_elementName, es, STATE_EXTENSION); |
1172 |
8 |
} |
1173 |
|
|
1174 |
|
private void enterExternalAsset30() |
1175 |
|
{ |
1176 |
|
|
1177 |
|
|
1178 |
|
|
1179 |
2 |
enterAsset("URL", null); |
1180 |
2 |
} |
1181 |
|
|
1182 |
|
|
1183 |
|
|
1184 |
|
private void enterInheritedBinding30() |
1185 |
|
{ |
1186 |
0 |
String name = getAttribute("name"); |
1187 |
0 |
String parameterName = getAttribute("parameter-name"); |
1188 |
|
|
1189 |
0 |
IBindingSpecification bs = _factory.createBindingSpecification(); |
1190 |
0 |
bs.setType(BindingType.INHERITED); |
1191 |
0 |
bs.setValue(parameterName); |
1192 |
|
|
1193 |
0 |
IContainedComponent cc = (IContainedComponent) peekObject(); |
1194 |
|
|
1195 |
0 |
cc.setBinding(name, bs); |
1196 |
|
|
1197 |
0 |
push(_elementName, null, STATE_NO_CONTENT); |
1198 |
0 |
} |
1199 |
|
|
1200 |
|
private void enterLibrary() |
1201 |
|
{ |
1202 |
5 |
String libraryId = getValidatedAttribute("id", LIBRARY_ID_PATTERN, "invalid-library-id"); |
1203 |
4 |
String path = getAttribute("specification-path"); |
1204 |
|
|
1205 |
4 |
if (libraryId.equals(INamespace.FRAMEWORK_NAMESPACE) |
1206 |
|
|| libraryId.equals(INamespace.APPLICATION_NAMESPACE)) |
1207 |
1 |
throw new DocumentParseException(ParseMessages |
1208 |
|
.frameworkLibraryIdIsReserved(INamespace.FRAMEWORK_NAMESPACE), getLocation()); |
1209 |
|
|
1210 |
3 |
ILibrarySpecification ls = (ILibrarySpecification) peekObject(); |
1211 |
|
|
1212 |
3 |
ls.setLibrarySpecificationPath(libraryId, path); |
1213 |
|
|
1214 |
3 |
push(_elementName, null, STATE_NO_CONTENT); |
1215 |
3 |
} |
1216 |
|
|
1217 |
|
private void enterListenerBinding() |
1218 |
|
{ |
1219 |
1 |
_log.warn(ParseMessages.listenerBindingUnsupported(getLocation())); |
1220 |
|
|
1221 |
1 |
push(_elementName, null, STATE_LISTENER_BINDING, false); |
1222 |
1 |
} |
1223 |
|
|
1224 |
|
private void enterMessageBinding30() |
1225 |
|
{ |
1226 |
1 |
String name = getAttribute("name"); |
1227 |
1 |
String key = getAttribute("key"); |
1228 |
|
|
1229 |
1 |
IBindingSpecification bs = _factory.createBindingSpecification(); |
1230 |
1 |
bs.setType(BindingType.PREFIXED); |
1231 |
1 |
bs.setValue(BindingConstants.MESSAGE_PREFIX + ":" + key); |
1232 |
1 |
bs.setLocation(getLocation()); |
1233 |
|
|
1234 |
1 |
IContainedComponent cc = (IContainedComponent) peekObject(); |
1235 |
|
|
1236 |
1 |
cc.setBinding(name, bs); |
1237 |
|
|
1238 |
1 |
push(_elementName, null, STATE_NO_CONTENT); |
1239 |
1 |
} |
1240 |
|
|
1241 |
|
private void enterPage() |
1242 |
|
{ |
1243 |
19 |
String name = getValidatedAttribute("name", PAGE_NAME_PATTERN, "invalid-page-name"); |
1244 |
18 |
String path = getAttribute("specification-path"); |
1245 |
|
|
1246 |
18 |
ILibrarySpecification ls = (ILibrarySpecification) peekObject(); |
1247 |
|
|
1248 |
18 |
ls.setPageSpecificationPath(name, path); |
1249 |
|
|
1250 |
18 |
push(_elementName, null, STATE_NO_CONTENT); |
1251 |
18 |
} |
1252 |
|
|
1253 |
|
private void enterParameter() |
1254 |
|
{ |
1255 |
14 |
IParameterSpecification ps = _factory.createParameterSpecification(); |
1256 |
|
|
1257 |
14 |
String name = getValidatedAttribute( |
1258 |
|
"name", |
1259 |
|
PARAMETER_NAME_PATTERN, |
1260 |
|
"invalid-parameter-name"); |
1261 |
|
|
1262 |
13 |
String attributeName = _dtd40 ? "property" : "property-name"; |
1263 |
|
|
1264 |
13 |
String propertyName = getValidatedAttribute( |
1265 |
|
attributeName, |
1266 |
|
PROPERTY_NAME_PATTERN, |
1267 |
|
"invalid-property-name"); |
1268 |
|
|
1269 |
13 |
if (propertyName == null) |
1270 |
12 |
propertyName = name; |
1271 |
|
|
1272 |
13 |
ps.setParameterName(name); |
1273 |
13 |
ps.setPropertyName(propertyName); |
1274 |
|
|
1275 |
13 |
ps.setRequired(getBooleanAttribute("required", false)); |
1276 |
|
|
1277 |
|
|
1278 |
|
|
1279 |
|
|
1280 |
|
|
1281 |
13 |
String defaultValue = getAttribute("default-value"); |
1282 |
|
|
1283 |
13 |
if (defaultValue != null && !_dtd40) |
1284 |
1 |
defaultValue = BindingConstants.OGNL_PREFIX + ":" + defaultValue; |
1285 |
|
|
1286 |
13 |
ps.setDefaultValue(defaultValue); |
1287 |
|
|
1288 |
13 |
if (!_dtd40) |
1289 |
|
{ |
1290 |
|
|
1291 |
|
|
1292 |
7 |
String direction = getAttribute("direction"); |
1293 |
7 |
ps.setCache(!"auto".equals(direction)); |
1294 |
7 |
} |
1295 |
|
else |
1296 |
|
{ |
1297 |
6 |
boolean cache = getBooleanAttribute("cache", true); |
1298 |
6 |
ps.setCache(cache); |
1299 |
|
} |
1300 |
|
|
1301 |
|
|
1302 |
|
|
1303 |
13 |
String type = getAttribute("type"); |
1304 |
|
|
1305 |
13 |
if (type != null) |
1306 |
1 |
ps.setType(type); |
1307 |
|
|
1308 |
|
|
1309 |
|
|
1310 |
13 |
String aliases = getAttribute("aliases"); |
1311 |
|
|
1312 |
13 |
ps.setAliases(aliases); |
1313 |
13 |
ps.setDeprecated(getBooleanAttribute("deprecated", false)); |
1314 |
|
|
1315 |
13 |
IComponentSpecification cs = (IComponentSpecification) peekObject(); |
1316 |
|
|
1317 |
13 |
cs.addParameter(ps); |
1318 |
|
|
1319 |
13 |
push(_elementName, ps, STATE_ALLOW_DESCRIPTION); |
1320 |
13 |
} |
1321 |
|
|
1322 |
|
private void enterPrivateAsset30() |
1323 |
|
{ |
1324 |
4 |
enterAsset("resource-path", "classpath:"); |
1325 |
3 |
} |
1326 |
|
|
1327 |
|
|
1328 |
|
private void enterMeta() |
1329 |
|
{ |
1330 |
2 |
String key = getAttribute("key"); |
1331 |
2 |
String value = getAttribute("value"); |
1332 |
|
|
1333 |
|
|
1334 |
|
|
1335 |
2 |
IPropertyHolder ph = (IPropertyHolder) peekObject(); |
1336 |
|
|
1337 |
2 |
push(_elementName, new PropertyValueSetter(ph, key, value), STATE_META, false); |
1338 |
2 |
} |
1339 |
|
|
1340 |
|
private void enterProperty30() |
1341 |
|
{ |
1342 |
19 |
String name = getAttribute("name"); |
1343 |
19 |
String value = getAttribute("value"); |
1344 |
|
|
1345 |
|
|
1346 |
|
|
1347 |
19 |
IPropertyHolder ph = (IPropertyHolder) peekObject(); |
1348 |
|
|
1349 |
19 |
push(_elementName, new PropertyValueSetter(ph, name, value), STATE_META, false); |
1350 |
19 |
} |
1351 |
|
|
1352 |
|
|
1353 |
|
|
1354 |
|
|
1355 |
|
|
1356 |
|
private void enterProperty() |
1357 |
|
{ |
1358 |
8 |
String name = getValidatedAttribute("name", PROPERTY_NAME_PATTERN, "invalid-property-name"); |
1359 |
8 |
String type = getAttribute("type"); |
1360 |
|
|
1361 |
8 |
String persistence = null; |
1362 |
|
|
1363 |
8 |
if (_dtd40) |
1364 |
4 |
persistence = getAttribute("persist"); |
1365 |
|
else |
1366 |
4 |
persistence = getBooleanAttribute("persistent", false) ? "session" : null; |
1367 |
|
|
1368 |
8 |
String initialValue = getAttribute("initial-value"); |
1369 |
|
|
1370 |
8 |
IPropertySpecification ps = _factory.createPropertySpecification(); |
1371 |
8 |
ps.setName(name); |
1372 |
|
|
1373 |
8 |
if (HiveMind.isNonBlank(type)) |
1374 |
1 |
ps.setType(type); |
1375 |
|
|
1376 |
8 |
ps.setPersistence(persistence); |
1377 |
8 |
ps.setInitialValue(initialValue); |
1378 |
|
|
1379 |
8 |
IComponentSpecification cs = (IComponentSpecification) peekObject(); |
1380 |
8 |
cs.addPropertySpecification(ps); |
1381 |
|
|
1382 |
8 |
push(_elementName, ps, STATE_PROPERTY, false); |
1383 |
8 |
} |
1384 |
|
|
1385 |
|
|
1386 |
|
|
1387 |
|
|
1388 |
|
|
1389 |
|
private void enterInject() |
1390 |
|
{ |
1391 |
2 |
String property = getValidatedAttribute( |
1392 |
|
"property", |
1393 |
|
PROPERTY_NAME_PATTERN, |
1394 |
|
"invalid-property-name"); |
1395 |
2 |
String type = getAttribute("type"); |
1396 |
2 |
String objectReference = getAttribute("object"); |
1397 |
|
|
1398 |
2 |
InjectSpecification spec = _factory.createInjectSpecification(); |
1399 |
|
|
1400 |
2 |
spec.setProperty(property); |
1401 |
2 |
spec.setType(type); |
1402 |
2 |
spec.setObject(objectReference); |
1403 |
2 |
IComponentSpecification cs = (IComponentSpecification) peekObject(); |
1404 |
|
|
1405 |
2 |
cs.addInjectSpecification(spec); |
1406 |
|
|
1407 |
2 |
push(_elementName, spec, STATE_NO_CONTENT); |
1408 |
2 |
} |
1409 |
|
|
1410 |
|
private void enterReservedParameter() |
1411 |
|
{ |
1412 |
0 |
String name = getAttribute("name"); |
1413 |
0 |
IComponentSpecification cs = (IComponentSpecification) peekObject(); |
1414 |
|
|
1415 |
0 |
cs.addReservedParameterName(name); |
1416 |
|
|
1417 |
0 |
push(_elementName, null, STATE_NO_CONTENT); |
1418 |
0 |
} |
1419 |
|
|
1420 |
|
private void enterService30() |
1421 |
|
{ |
1422 |
0 |
_errorHandler.error(_log, ParseMessages.serviceElementNotSupported(), getLocation(), null); |
1423 |
|
|
1424 |
0 |
push(_elementName, null, STATE_NO_CONTENT); |
1425 |
0 |
} |
1426 |
|
|
1427 |
|
private void enterSetMessage30() |
1428 |
|
{ |
1429 |
1 |
String name = getAttribute("name"); |
1430 |
1 |
String key = getAttribute("key"); |
1431 |
|
|
1432 |
1 |
BindingBeanInitializer bi = _factory.createBindingBeanInitializer(_bindingSource); |
1433 |
|
|
1434 |
1 |
bi.setPropertyName(name); |
1435 |
1 |
bi.setBindingReference(BindingConstants.MESSAGE_PREFIX + ":" + key); |
1436 |
1 |
bi.setLocation(getLocation()); |
1437 |
|
|
1438 |
1 |
IBeanSpecification bs = (IBeanSpecification) peekObject(); |
1439 |
|
|
1440 |
1 |
bs.addInitializer(bi); |
1441 |
|
|
1442 |
1 |
push(_elementName, null, STATE_NO_CONTENT); |
1443 |
1 |
} |
1444 |
|
|
1445 |
|
private void enterSet() |
1446 |
|
{ |
1447 |
3 |
String name = getAttribute("name"); |
1448 |
3 |
String reference = getAttribute("value"); |
1449 |
|
|
1450 |
3 |
BindingBeanInitializer bi = _factory.createBindingBeanInitializer(_bindingSource); |
1451 |
|
|
1452 |
3 |
bi.setPropertyName(name); |
1453 |
|
|
1454 |
3 |
IBeanSpecification bs = (IBeanSpecification) peekObject(); |
1455 |
|
|
1456 |
3 |
push(_elementName, new BeanSetPropertySetter(bs, bi, null, reference), STATE_SET, false); |
1457 |
3 |
} |
1458 |
|
|
1459 |
|
private void enterSetProperty30() |
1460 |
|
{ |
1461 |
2 |
String name = getAttribute("name"); |
1462 |
2 |
String expression = getAttribute("expression"); |
1463 |
|
|
1464 |
2 |
BindingBeanInitializer bi = _factory.createBindingBeanInitializer(_bindingSource); |
1465 |
|
|
1466 |
2 |
bi.setPropertyName(name); |
1467 |
|
|
1468 |
2 |
IBeanSpecification bs = (IBeanSpecification) peekObject(); |
1469 |
|
|
1470 |
2 |
push(_elementName, new BeanSetPropertySetter(bs, bi, BindingConstants.OGNL_PREFIX + ":", |
1471 |
|
expression), STATE_SET, false); |
1472 |
2 |
} |
1473 |
|
|
1474 |
|
private void enterStaticBinding30() |
1475 |
|
{ |
1476 |
6 |
String name = getAttribute("name"); |
1477 |
6 |
String expression = getAttribute("value"); |
1478 |
|
|
1479 |
6 |
IContainedComponent cc = (IContainedComponent) peekObject(); |
1480 |
|
|
1481 |
6 |
BindingSetter bs = new BindingSetter(cc, name, expression); |
1482 |
|
|
1483 |
6 |
push(_elementName, bs, STATE_STATIC_BINDING, false); |
1484 |
6 |
} |
1485 |
|
|
1486 |
|
private void expectElement(String elementName) |
1487 |
|
{ |
1488 |
62 |
if (_elementName.equals(elementName)) |
1489 |
61 |
return; |
1490 |
|
|
1491 |
1 |
throw new DocumentParseException(ParseMessages.incorrectDocumentType( |
1492 |
|
_elementName, |
1493 |
|
elementName), getLocation(), null); |
1494 |
|
|
1495 |
|
} |
1496 |
|
|
1497 |
|
private String getAttribute(String name) |
1498 |
|
{ |
1499 |
676 |
return (String) _attributes.get(name); |
1500 |
|
} |
1501 |
|
|
1502 |
|
private boolean getBooleanAttribute(String name, boolean defaultValue) |
1503 |
|
{ |
1504 |
144 |
String value = getAttribute(name); |
1505 |
|
|
1506 |
144 |
if (value == null) |
1507 |
25 |
return defaultValue; |
1508 |
|
|
1509 |
119 |
Boolean b = (Boolean) _conversionMap.get(value); |
1510 |
|
|
1511 |
119 |
return b.booleanValue(); |
1512 |
|
} |
1513 |
|
|
1514 |
|
private Object getConvertedAttribute(String name, Object defaultValue) |
1515 |
|
{ |
1516 |
8 |
String key = getAttribute(name); |
1517 |
|
|
1518 |
8 |
if (key == null) |
1519 |
0 |
return defaultValue; |
1520 |
|
|
1521 |
8 |
return _conversionMap.get(key); |
1522 |
|
} |
1523 |
|
|
1524 |
|
private InputSource getDTDInputSource(String name) |
1525 |
|
{ |
1526 |
62 |
InputStream stream = getClass().getResourceAsStream(name); |
1527 |
|
|
1528 |
62 |
return new InputSource(stream); |
1529 |
|
} |
1530 |
|
|
1531 |
|
private String getExtendedValue(String attributeValue, String attributeName, boolean required) |
1532 |
|
{ |
1533 |
71 |
String contentValue = peekContent(); |
1534 |
|
|
1535 |
71 |
boolean asAttribute = HiveMind.isNonBlank(attributeValue); |
1536 |
71 |
boolean asContent = HiveMind.isNonBlank(contentValue); |
1537 |
|
|
1538 |
71 |
if (asAttribute && asContent) |
1539 |
|
{ |
1540 |
1 |
throw new DocumentParseException(ParseMessages.noAttributeAndBody( |
1541 |
|
attributeName, |
1542 |
|
_elementName), getLocation(), null); |
1543 |
|
} |
1544 |
|
|
1545 |
70 |
if (required && !(asAttribute || asContent)) |
1546 |
|
{ |
1547 |
1 |
throw new DocumentParseException(ParseMessages.requiredExtendedAttribute( |
1548 |
|
_elementName, |
1549 |
|
attributeName), getLocation(), null); |
1550 |
|
} |
1551 |
|
|
1552 |
69 |
if (asAttribute) |
1553 |
30 |
return attributeValue; |
1554 |
|
|
1555 |
39 |
return contentValue; |
1556 |
|
} |
1557 |
|
|
1558 |
|
private String getValidatedAttribute(String name, String pattern, String errorKey) |
1559 |
|
{ |
1560 |
207 |
String value = getAttribute(name); |
1561 |
|
|
1562 |
207 |
if (value == null) |
1563 |
51 |
return null; |
1564 |
|
|
1565 |
156 |
if (_matcher.matches(pattern, value)) |
1566 |
149 |
return value; |
1567 |
|
|
1568 |
7 |
throw new InvalidStringException(ParseMessages.invalidAttribute(errorKey, value), value, |
1569 |
|
getLocation()); |
1570 |
|
} |
1571 |
|
|
1572 |
|
protected void initializeParser(Resource resource, int startState) |
1573 |
|
{ |
1574 |
64 |
super.initializeParser(resource, startState); |
1575 |
|
|
1576 |
64 |
_rootObject = null; |
1577 |
64 |
_attributes = new HashMap(); |
1578 |
64 |
} |
1579 |
|
|
1580 |
|
public IApplicationSpecification parseApplicationSpecification(Resource resource) |
1581 |
|
{ |
1582 |
15 |
initializeParser(resource, STATE_APPLICATION_SPECIFICATION_INITIAL); |
1583 |
|
|
1584 |
|
try |
1585 |
|
{ |
1586 |
15 |
parseDocument(); |
1587 |
|
|
1588 |
10 |
return (IApplicationSpecification) _rootObject; |
1589 |
|
} |
1590 |
|
finally |
1591 |
|
{ |
1592 |
10 |
resetParser(); |
1593 |
|
} |
1594 |
|
} |
1595 |
|
|
1596 |
|
public IComponentSpecification parseComponentSpecification(Resource resource) |
1597 |
|
{ |
1598 |
27 |
initializeParser(resource, STATE_COMPONENT_SPECIFICATION_INITIAL); |
1599 |
|
|
1600 |
|
try |
1601 |
|
{ |
1602 |
27 |
parseDocument(); |
1603 |
|
|
1604 |
20 |
return (IComponentSpecification) _rootObject; |
1605 |
|
} |
1606 |
|
finally |
1607 |
|
{ |
1608 |
20 |
resetParser(); |
1609 |
|
} |
1610 |
|
} |
1611 |
|
|
1612 |
|
private void parseDocument() |
1613 |
|
{ |
1614 |
64 |
InputStream stream = null; |
1615 |
|
|
1616 |
64 |
Resource resource = getResource(); |
1617 |
|
|
1618 |
64 |
boolean success = false; |
1619 |
|
|
1620 |
|
try |
1621 |
|
{ |
1622 |
64 |
if (_parser == null) |
1623 |
64 |
_parser = _parserFactory.newSAXParser(); |
1624 |
|
|
1625 |
64 |
URL resourceURL = resource.getResourceURL(); |
1626 |
|
|
1627 |
64 |
if (resourceURL == null) |
1628 |
0 |
throw new DocumentParseException(ParseMessages.missingResource(resource), resource); |
1629 |
|
|
1630 |
64 |
InputStream rawStream = resourceURL.openStream(); |
1631 |
64 |
stream = new BufferedInputStream(rawStream); |
1632 |
|
|
1633 |
64 |
_parser.parse(stream, this, resourceURL.toExternalForm()); |
1634 |
|
|
1635 |
47 |
stream.close(); |
1636 |
47 |
stream = null; |
1637 |
|
|
1638 |
47 |
success = true; |
1639 |
|
} |
1640 |
2 |
catch (SAXParseException ex) |
1641 |
|
{ |
1642 |
2 |
_parser = null; |
1643 |
|
|
1644 |
2 |
Location location = new LocationImpl(resource, ex.getLineNumber(), ex.getColumnNumber()); |
1645 |
|
|
1646 |
2 |
throw new DocumentParseException(ParseMessages.errorReadingResource(resource, ex), |
1647 |
|
location, ex); |
1648 |
|
} |
1649 |
15 |
catch (Exception ex) |
1650 |
|
{ |
1651 |
15 |
_parser = null; |
1652 |
|
|
1653 |
15 |
throw new DocumentParseException(ParseMessages.errorReadingResource(resource, ex), |
1654 |
|
resource, ex); |
1655 |
|
} |
1656 |
|
finally |
1657 |
|
{ |
1658 |
64 |
if (!success) |
1659 |
17 |
_parser = null; |
1660 |
|
|
1661 |
64 |
close(stream); |
1662 |
47 |
} |
1663 |
47 |
} |
1664 |
|
|
1665 |
|
public ILibrarySpecification parseLibrarySpecification(Resource resource) |
1666 |
|
{ |
1667 |
7 |
initializeParser(resource, STATE_LIBRARY_SPECIFICATION_INITIAL); |
1668 |
|
|
1669 |
|
try |
1670 |
|
{ |
1671 |
7 |
parseDocument(); |
1672 |
|
|
1673 |
5 |
return (ILibrarySpecification) _rootObject; |
1674 |
|
} |
1675 |
|
finally |
1676 |
|
{ |
1677 |
5 |
resetParser(); |
1678 |
|
} |
1679 |
|
} |
1680 |
|
|
1681 |
|
public IComponentSpecification parsePageSpecification(Resource resource) |
1682 |
|
{ |
1683 |
15 |
initializeParser(resource, STATE_PAGE_SPECIFICATION_INITIAL); |
1684 |
|
|
1685 |
|
try |
1686 |
|
{ |
1687 |
15 |
parseDocument(); |
1688 |
|
|
1689 |
12 |
return (IComponentSpecification) _rootObject; |
1690 |
|
} |
1691 |
|
finally |
1692 |
|
{ |
1693 |
12 |
resetParser(); |
1694 |
|
} |
1695 |
|
} |
1696 |
|
|
1697 |
|
protected String peekContent() |
1698 |
|
{ |
1699 |
76 |
String content = super.peekContent(); |
1700 |
|
|
1701 |
76 |
if (content == null) |
1702 |
35 |
return null; |
1703 |
|
|
1704 |
41 |
return content.trim(); |
1705 |
|
} |
1706 |
|
|
1707 |
|
protected void resetParser() |
1708 |
|
{ |
1709 |
64 |
_rootObject = null; |
1710 |
64 |
_dtd40 = false; |
1711 |
|
|
1712 |
64 |
_attributes.clear(); |
1713 |
64 |
} |
1714 |
|
|
1715 |
|
|
1716 |
|
|
1717 |
|
|
1718 |
|
|
1719 |
|
public InputSource resolveEntity(String publicId, String systemId) throws SAXException |
1720 |
|
{ |
1721 |
63 |
if (TAPESTRY_DTD_4_0_PUBLIC_ID.equals(publicId)) |
1722 |
|
{ |
1723 |
14 |
_dtd40 = true; |
1724 |
14 |
return getDTDInputSource("Tapestry_4_0.dtd"); |
1725 |
|
} |
1726 |
|
|
1727 |
49 |
if (TAPESTRY_DTD_4_1_PUBLIC_ID.equals(publicId)) |
1728 |
|
{ |
1729 |
0 |
_dtd40 = true; |
1730 |
0 |
return getDTDInputSource("Tapestry_4_1.dtd"); |
1731 |
|
} |
1732 |
|
|
1733 |
49 |
if (TAPESTRY_DTD_3_0_PUBLIC_ID.equals(publicId)) |
1734 |
48 |
return getDTDInputSource("Tapestry_3_0.dtd"); |
1735 |
|
|
1736 |
1 |
throw new DocumentParseException(ParseMessages.unknownPublicId(getResource(), publicId), |
1737 |
|
new LocationImpl(getResource()), null); |
1738 |
|
} |
1739 |
|
|
1740 |
|
|
1741 |
|
public void setBindingSource(BindingSource bindingSource) |
1742 |
|
{ |
1743 |
16 |
_bindingSource = bindingSource; |
1744 |
16 |
} |
1745 |
|
|
1746 |
|
|
1747 |
|
public void setValueConverter(ValueConverter valueConverter) |
1748 |
|
{ |
1749 |
22 |
_valueConverter = valueConverter; |
1750 |
22 |
} |
1751 |
|
} |