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