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