|
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.Date; |
|
18 |
| import java.util.Iterator; |
|
19 |
| |
|
20 |
| import org.apache.hivemind.HiveMind; |
|
21 |
| import org.apache.tapestry.AbstractComponent; |
|
22 |
| import org.apache.tapestry.IAsset; |
|
23 |
| import org.apache.tapestry.IMarkupWriter; |
|
24 |
| import org.apache.tapestry.IPage; |
|
25 |
| import org.apache.tapestry.IRender; |
|
26 |
| import org.apache.tapestry.IRequestCycle; |
|
27 |
| import org.apache.tapestry.Tapestry; |
|
28 |
| import org.apache.tapestry.coerce.ValueConverter; |
|
29 |
| import org.apache.tapestry.engine.IEngineService; |
|
30 |
| import org.apache.tapestry.engine.ILink; |
|
31 |
| import org.apache.tapestry.spec.IApplicationSpecification; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| public abstract class Shell extends AbstractComponent |
|
45 |
| { |
|
46 |
| private static final String generatorContent = "Tapestry Application Framework, version " |
|
47 |
| + Tapestry.VERSION; |
|
48 |
| |
|
49 |
327
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
50 |
| { |
|
51 |
327
| long startTime = 0;
|
|
52 |
| |
|
53 |
327
| boolean rewinding = cycle.isRewinding();
|
|
54 |
| |
|
55 |
327
| if (!rewinding)
|
|
56 |
| { |
|
57 |
318
| startTime = System.currentTimeMillis();
|
|
58 |
| |
|
59 |
318
| writeDocType(writer, cycle);
|
|
60 |
| |
|
61 |
318
| IPage page = getPage();
|
|
62 |
| |
|
63 |
318
| writer.comment("Application: " + getApplicationSpecification().getName());
|
|
64 |
| |
|
65 |
318
| writer.comment("Page: " + page.getPageName());
|
|
66 |
318
| writer.comment("Generated: " + new Date());
|
|
67 |
| |
|
68 |
318
| writer.begin("html");
|
|
69 |
318
| writer.println();
|
|
70 |
318
| writer.begin("head");
|
|
71 |
318
| writer.println();
|
|
72 |
| |
|
73 |
318
| writeMetaTag(writer, "name", "generator", generatorContent);
|
|
74 |
| |
|
75 |
318
| if (getRenderContentType())
|
|
76 |
318
| writeMetaTag(writer, "http-equiv", "Content-Type", writer.getContentType());
|
|
77 |
| |
|
78 |
318
| if (getRenderBaseTag())
|
|
79 |
318
| getBaseTagWriter().render(writer, cycle);
|
|
80 |
| |
|
81 |
318
| writer.begin("title");
|
|
82 |
| |
|
83 |
318
| writer.print(getTitle());
|
|
84 |
318
| writer.end();
|
|
85 |
318
| writer.println();
|
|
86 |
| |
|
87 |
318
| IRender delegate = getDelegate();
|
|
88 |
| |
|
89 |
318
| if (delegate != null)
|
|
90 |
0
| delegate.render(writer, cycle);
|
|
91 |
| |
|
92 |
318
| IAsset stylesheet = getStylesheet();
|
|
93 |
| |
|
94 |
318
| if (stylesheet != null)
|
|
95 |
129
| writeStylesheetLink(writer, cycle, stylesheet);
|
|
96 |
| |
|
97 |
318
| Iterator i = (Iterator) getValueConverter().coerceValue(
|
|
98 |
| getStylesheets(), |
|
99 |
| Iterator.class); |
|
100 |
| |
|
101 |
318
| while (i.hasNext())
|
|
102 |
| { |
|
103 |
0
| stylesheet = (IAsset) i.next();
|
|
104 |
| |
|
105 |
0
| writeStylesheetLink(writer, cycle, stylesheet);
|
|
106 |
| } |
|
107 |
| |
|
108 |
318
| writeRefresh(writer, cycle);
|
|
109 |
| |
|
110 |
318
| writer.end();
|
|
111 |
| } |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
327
| renderBody(writer, cycle);
|
|
116 |
| |
|
117 |
306
| if (!rewinding)
|
|
118 |
| { |
|
119 |
303
| writer.end();
|
|
120 |
303
| writer.println();
|
|
121 |
| |
|
122 |
303
| long endTime = System.currentTimeMillis();
|
|
123 |
| |
|
124 |
303
| writer.comment("Render time: ~ " + (endTime - startTime) + " ms");
|
|
125 |
| } |
|
126 |
| |
|
127 |
| } |
|
128 |
| |
|
129 |
318
| private void writeDocType(IMarkupWriter writer, IRequestCycle cycle)
|
|
130 |
| { |
|
131 |
| |
|
132 |
318
| String doctype = getDoctype();
|
|
133 |
318
| if (HiveMind.isNonBlank(doctype))
|
|
134 |
| { |
|
135 |
318
| writer.printRaw("<!DOCTYPE " + doctype + ">");
|
|
136 |
318
| writer.println();
|
|
137 |
| } |
|
138 |
| } |
|
139 |
| |
|
140 |
129
| private void writeStylesheetLink(IMarkupWriter writer, IRequestCycle cycle, IAsset stylesheet)
|
|
141 |
| { |
|
142 |
129
| writer.beginEmpty("link");
|
|
143 |
129
| writer.attribute("rel", "stylesheet");
|
|
144 |
129
| writer.attribute("type", "text/css");
|
|
145 |
129
| writer.attribute("href", stylesheet.buildURL());
|
|
146 |
129
| writer.println();
|
|
147 |
| } |
|
148 |
| |
|
149 |
318
| private void writeRefresh(IMarkupWriter writer, IRequestCycle cycle)
|
|
150 |
| { |
|
151 |
318
| int refresh = getRefresh();
|
|
152 |
| |
|
153 |
318
| if (refresh <= 0)
|
|
154 |
318
| return;
|
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
0
| IEngineService pageService = getPageService();
|
|
160 |
0
| String pageName = getPage().getPageName();
|
|
161 |
| |
|
162 |
0
| ILink link = pageService.getLink(false, pageName);
|
|
163 |
| |
|
164 |
0
| StringBuffer buffer = new StringBuffer();
|
|
165 |
0
| buffer.append(refresh);
|
|
166 |
0
| buffer.append("; URL=");
|
|
167 |
0
| buffer.append(link.getAbsoluteURL());
|
|
168 |
| |
|
169 |
0
| writeMetaTag(writer, "http-equiv", "Refresh", buffer.toString());
|
|
170 |
| } |
|
171 |
| |
|
172 |
636
| private void writeMetaTag(IMarkupWriter writer, String key, String value, String content)
|
|
173 |
| { |
|
174 |
636
| writer.beginEmpty("meta");
|
|
175 |
636
| writer.attribute(key, value);
|
|
176 |
636
| writer.attribute("content", content);
|
|
177 |
636
| writer.println();
|
|
178 |
| } |
|
179 |
| |
|
180 |
| public abstract IRender getDelegate(); |
|
181 |
| |
|
182 |
| public abstract int getRefresh(); |
|
183 |
| |
|
184 |
| public abstract IAsset getStylesheet(); |
|
185 |
| |
|
186 |
| public abstract Object getStylesheets(); |
|
187 |
| |
|
188 |
| public abstract String getTitle(); |
|
189 |
| |
|
190 |
| public abstract String getDoctype(); |
|
191 |
| |
|
192 |
| public abstract boolean getRenderContentType(); |
|
193 |
| |
|
194 |
| |
|
195 |
| public abstract ValueConverter getValueConverter(); |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| public abstract IEngineService getPageService(); |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| public abstract IApplicationSpecification getApplicationSpecification(); |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| public abstract IRender getBaseTagWriter(); |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| public abstract boolean getRenderBaseTag(); |
|
212 |
| } |