|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ScriptParser.java | - | 100% | 100% | 100% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.script;
|
|
16 |
|
|
17 |
import org.apache.hivemind.ClassResolver;
|
|
18 |
import org.apache.hivemind.Resource;
|
|
19 |
import org.apache.tapestry.IScript;
|
|
20 |
import org.apache.tapestry.coerce.ValueConverter;
|
|
21 |
import org.apache.tapestry.services.ExpressionEvaluator;
|
|
22 |
import org.apache.tapestry.util.xml.DocumentParseException;
|
|
23 |
import org.apache.tapestry.util.xml.RuleDirectedParser;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Parses a Tapestry Script, an XML file defined by one of the following public identifiers:
|
|
27 |
* <ul>
|
|
28 |
* <li><code>-//Primix Solutions//Tapestry Script 1.0//EN</code></li>
|
|
29 |
* <li><code>-//Howard Ship//Tapestry Script 1.1//EN</code></li>
|
|
30 |
* <li><code>-//Howard Lewis Ship//Tapestry Script 1.2//EN</code></li>.
|
|
31 |
* <p>
|
|
32 |
* The version 1.1, is largely backwards compatible to the old script, but adds a number of new
|
|
33 |
* features (if, if-not, foreach and the use of property paths with insert).
|
|
34 |
* <p>
|
|
35 |
* Version 1.2 removes the <insert> element, using an Ant-like syntax (
|
|
36 |
* <code>${<i>expression</i>}</code>). It also replaces the attribute name
|
|
37 |
* <code>property-path</code> with <code>expression</code> (because OGNL is used).
|
|
38 |
* <p>
|
|
39 |
* A Tapestry Script is used, in association with the {@link org.apache.tapestry.html.Body}and/or
|
|
40 |
* {@link org.apache.tapestry.html.Script}components, to generate JavaScript for use with a
|
|
41 |
* Tapestry component. Two seperate pieces of JavaScript can be generated. The body section
|
|
42 |
* (associated with the <code>body</code> element of the XML document) is typically used to define
|
|
43 |
* JavaScript functions (most often, event handlers). The initialization section (associated with
|
|
44 |
* the <code>initialization</code> element of the XML document) is used to add JavaScript that
|
|
45 |
* will be evaluated when the page finishes loading (i.e., from the HTML <body> element's
|
|
46 |
* onLoad event handler).
|
|
47 |
*
|
|
48 |
* @author Howard Lewis Ship
|
|
49 |
*/
|
|
50 |
|
|
51 |
public class ScriptParser |
|
52 |
{ |
|
53 |
private RuleDirectedParser _parser;
|
|
54 |
|
|
55 |
public static final String SCRIPT_DTD_1_0_PUBLIC_ID = "-//Primix Solutions//Tapestry Script 1.0//EN"; |
|
56 |
|
|
57 |
public static final String SCRIPT_DTD_1_1_PUBLIC_ID = "-//Howard Ship//Tapestry Script 1.1//EN"; |
|
58 |
|
|
59 |
public static final String SCRIPT_DTD_1_2_PUBLIC_ID = "-//Howard Lewis Ship//Tapestry Script 1.2//EN"; |
|
60 |
|
|
61 |
/** @since 3.0 */
|
|
62 |
public static final String SCRIPT_DTD_3_0_PUBLIC_ID = "-//Apache Software Foundation//Tapestry Script Specification 3.0//EN"; |
|
63 |
|
|
64 | 18 |
public ScriptParser(ClassResolver resolver, ExpressionEvaluator evaluator,
|
65 |
ValueConverter valueConverter) |
|
66 |
{ |
|
67 | 18 |
_parser = new RuleDirectedParser();
|
68 |
|
|
69 | 18 |
_parser.registerEntity( |
70 |
SCRIPT_DTD_1_0_PUBLIC_ID, |
|
71 |
"/org/apache/tapestry/script/Script_1_0.dtd");
|
|
72 | 18 |
_parser.registerEntity( |
73 |
SCRIPT_DTD_1_1_PUBLIC_ID, |
|
74 |
"/org/apache/tapestry/script/Script_1_1.dtd");
|
|
75 | 18 |
_parser.registerEntity( |
76 |
SCRIPT_DTD_1_2_PUBLIC_ID, |
|
77 |
"/org/apache/tapestry/script/Script_1_2.dtd");
|
|
78 | 18 |
_parser.registerEntity( |
79 |
SCRIPT_DTD_3_0_PUBLIC_ID, |
|
80 |
"/org/apache/tapestry/script/Script_3_0.dtd");
|
|
81 |
|
|
82 | 18 |
_parser.addRule("script", new ScriptRule(evaluator, valueConverter)); |
83 | 18 |
_parser.addRule("let", new LetRule()); |
84 | 18 |
_parser.addRule("set", new SetRule()); |
85 | 18 |
_parser.addRule("include-script", new IncludeScriptRule()); |
86 | 18 |
_parser.addRule("input-symbol", new InputSymbolRule(resolver)); |
87 | 18 |
_parser.addRule("body", new BodyRule()); |
88 | 18 |
_parser.addRule("initialization", new InitRule()); |
89 | 18 |
_parser.addRule("if", new IfRule(true)); |
90 | 18 |
_parser.addRule("if-not", new IfRule(false)); |
91 | 18 |
_parser.addRule("foreach", new ForeachRule()); |
92 | 18 |
_parser.addRule("unique", new UniqueRule()); |
93 |
|
|
94 |
// This will go away when the 1.1 and earler DTDs are retired.
|
|
95 | 18 |
_parser.addRule("insert", new InsertRule()); |
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
/**
|
|
100 |
* Parses the given input stream to produce a parsed script, ready to execute.
|
|
101 |
*/
|
|
102 |
|
|
103 | 18 |
public IScript parse(Resource resourceLocation) throws DocumentParseException |
104 |
{ |
|
105 | 18 |
return (IScript) _parser.parse(resourceLocation);
|
106 |
} |
|
107 |
|
|
108 |
} |
|