1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.html; |
16 |
| |
17 |
| import java.util.HashMap; |
18 |
| import java.util.Iterator; |
19 |
| import java.util.Map; |
20 |
| |
21 |
| import org.apache.hivemind.ApplicationRuntimeException; |
22 |
| import org.apache.hivemind.Resource; |
23 |
| import org.apache.tapestry.AbstractComponent; |
24 |
| import org.apache.tapestry.IBinding; |
25 |
| import org.apache.tapestry.IEngine; |
26 |
| import org.apache.tapestry.IMarkupWriter; |
27 |
| import org.apache.tapestry.IRequestCycle; |
28 |
| import org.apache.tapestry.IScript; |
29 |
| import org.apache.tapestry.PageRenderSupport; |
30 |
| import org.apache.tapestry.Tapestry; |
31 |
| import org.apache.tapestry.TapestryUtils; |
32 |
| import org.apache.tapestry.engine.IScriptSource; |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public abstract class Script extends AbstractComponent |
43 |
| { |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| public abstract IScriptSource getScriptSource(); |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| private Map _symbols; |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
3
| private Map getInputSymbols()
|
68 |
| { |
69 |
3
| Map result = new HashMap();
|
70 |
| |
71 |
3
| Map baseSymbols = getBaseSymbols();
|
72 |
| |
73 |
3
| if (baseSymbols != null)
|
74 |
2
| result.putAll(baseSymbols);
|
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
3
| Iterator i = getBindingNames().iterator();
|
81 |
3
| while (i.hasNext())
|
82 |
| { |
83 |
1
| String bindingName = (String) i.next();
|
84 |
| |
85 |
| |
86 |
| |
87 |
1
| if (getSpecification().getParameter(bindingName) != null)
|
88 |
0
| continue;
|
89 |
| |
90 |
1
| IBinding binding = getBinding(bindingName);
|
91 |
| |
92 |
1
| Object value = binding.getObject();
|
93 |
| |
94 |
1
| result.put(bindingName, value);
|
95 |
| } |
96 |
| |
97 |
3
| return result;
|
98 |
| } |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
3
| private IScript getParsedScript()
|
105 |
| { |
106 |
3
| String scriptPath = getScriptPath();
|
107 |
| |
108 |
3
| if (scriptPath == null)
|
109 |
0
| throw Tapestry.createRequiredParameterException(this, "scriptPath");
|
110 |
| |
111 |
3
| IScriptSource source = getScriptSource();
|
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
3
| Resource rootLocation = getContainer().getSpecification().getSpecificationLocation();
|
117 |
3
| Resource scriptLocation = rootLocation.getRelativeResource(scriptPath);
|
118 |
| |
119 |
3
| try
|
120 |
| { |
121 |
3
| return source.getScript(scriptLocation);
|
122 |
| } |
123 |
| catch (RuntimeException ex) |
124 |
| { |
125 |
0
| throw new ApplicationRuntimeException(ex.getMessage(), this, getBinding("script")
|
126 |
| .getLocation(), ex); |
127 |
| } |
128 |
| |
129 |
| } |
130 |
| |
131 |
4
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
132 |
| { |
133 |
4
| if (!cycle.isRewinding())
|
134 |
| { |
135 |
3
| PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
|
136 |
| |
137 |
3
| _symbols = getInputSymbols();
|
138 |
| |
139 |
3
| getParsedScript().execute(cycle, pageRenderSupport, _symbols);
|
140 |
| } |
141 |
| |
142 |
| |
143 |
4
| renderBody(writer, cycle);
|
144 |
| } |
145 |
| |
146 |
| public abstract String getScriptPath(); |
147 |
| |
148 |
| |
149 |
| |
150 |
| public abstract Map getBaseSymbols(); |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
| |
157 |
| |
158 |
| |
159 |
2
| public Map getSymbols()
|
160 |
| { |
161 |
2
| return _symbols;
|
162 |
| } |
163 |
| |
164 |
0
| protected void cleanupAfterRender(IRequestCycle cycle)
|
165 |
| { |
166 |
0
| _symbols = null;
|
167 |
| |
168 |
0
| super.cleanupAfterRender(cycle);
|
169 |
| } |
170 |
| |
171 |
| } |