|
|||||||||||||||||||
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 | |||||||||||||||
Shell.java | 68.8% | 82.5% | 100% | 81% |
|
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.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 |
* Component for creating a standard 'shell' for a page, which comprises the <html> and
|
|
35 |
* <head> portions of the page. [ <a
|
|
36 |
* href="../../../../../ComponentReference/Shell.html">Component Reference </a>]
|
|
37 |
* <p>
|
|
38 |
* Specifically does <em>not</em> provide a <body> tag, that is usually accomplished using a
|
|
39 |
* {@link Body} component.
|
|
40 |
*
|
|
41 |
* @author Howard Lewis Ship
|
|
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 | 140 |
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
50 |
{ |
|
51 | 140 |
long startTime = 0;
|
52 |
|
|
53 | 140 |
boolean rewinding = cycle.isRewinding();
|
54 |
|
|
55 | 140 |
if (!rewinding)
|
56 |
{ |
|
57 | 135 |
startTime = System.currentTimeMillis(); |
58 |
|
|
59 | 135 |
writeDocType(writer, cycle); |
60 |
|
|
61 | 135 |
IPage page = getPage(); |
62 |
|
|
63 | 135 |
writer.comment("Application: " + getApplicationSpecification().getName());
|
64 |
|
|
65 | 135 |
writer.comment("Page: " + page.getPageName());
|
66 | 135 |
writer.comment("Generated: " + new Date()); |
67 |
|
|
68 | 135 |
writer.begin("html");
|
69 | 135 |
writer.println(); |
70 | 135 |
writer.begin("head");
|
71 | 135 |
writer.println(); |
72 |
|
|
73 | 135 |
writeMetaTag(writer, "name", "generator", generatorContent); |
74 |
|
|
75 | 135 |
if (getRenderContentType())
|
76 | 135 |
writeMetaTag(writer, "http-equiv", "Content-Type", writer.getContentType()); |
77 |
|
|
78 | 135 |
getBaseTagWriter().render(writer, cycle); |
79 |
|
|
80 | 135 |
writer.begin("title");
|
81 |
|
|
82 | 135 |
writer.print(getTitle()); |
83 | 135 |
writer.end(); // title
|
84 | 135 |
writer.println(); |
85 |
|
|
86 | 135 |
IRender delegate = getDelegate(); |
87 |
|
|
88 | 135 |
if (delegate != null) |
89 | 0 |
delegate.render(writer, cycle); |
90 |
|
|
91 | 135 |
IAsset stylesheet = getStylesheet(); |
92 |
|
|
93 | 135 |
if (stylesheet != null) |
94 | 51 |
writeStylesheetLink(writer, cycle, stylesheet); |
95 |
|
|
96 | 135 |
Iterator i = (Iterator) getValueConverter().coerceValue( |
97 |
getStylesheets(), |
|
98 |
Iterator.class);
|
|
99 |
|
|
100 | 135 |
while (i.hasNext())
|
101 |
{ |
|
102 | 0 |
stylesheet = (IAsset) i.next(); |
103 |
|
|
104 | 0 |
writeStylesheetLink(writer, cycle, stylesheet); |
105 |
} |
|
106 |
|
|
107 | 135 |
writeRefresh(writer, cycle); |
108 |
|
|
109 | 135 |
writer.end(); // head
|
110 |
} |
|
111 |
|
|
112 |
// Render the body, the actual page content
|
|
113 |
|
|
114 | 140 |
renderBody(writer, cycle); |
115 |
|
|
116 | 128 |
if (!rewinding)
|
117 |
{ |
|
118 | 127 |
writer.end(); // html
|
119 | 127 |
writer.println(); |
120 |
|
|
121 | 127 |
long endTime = System.currentTimeMillis();
|
122 |
|
|
123 | 127 |
writer.comment("Render time: ~ " + (endTime - startTime) + " ms"); |
124 |
} |
|
125 |
|
|
126 |
} |
|
127 |
|
|
128 | 135 |
private void writeDocType(IMarkupWriter writer, IRequestCycle cycle) |
129 |
{ |
|
130 |
// This is the real code
|
|
131 | 135 |
String doctype = getDoctype(); |
132 | 135 |
if (HiveMind.isNonBlank(doctype))
|
133 |
{ |
|
134 | 135 |
writer.printRaw("<!DOCTYPE " + doctype + ">"); |
135 | 135 |
writer.println(); |
136 |
} |
|
137 |
} |
|
138 |
|
|
139 | 51 |
private void writeStylesheetLink(IMarkupWriter writer, IRequestCycle cycle, IAsset stylesheet) |
140 |
{ |
|
141 | 51 |
writer.beginEmpty("link");
|
142 | 51 |
writer.attribute("rel", "stylesheet"); |
143 | 51 |
writer.attribute("type", "text/css"); |
144 | 51 |
writer.attribute("href", stylesheet.buildURL(cycle));
|
145 | 51 |
writer.println(); |
146 |
} |
|
147 |
|
|
148 | 135 |
private void writeRefresh(IMarkupWriter writer, IRequestCycle cycle) |
149 |
{ |
|
150 | 135 |
int refresh = getRefresh();
|
151 |
|
|
152 | 135 |
if (refresh <= 0)
|
153 | 135 |
return;
|
154 |
|
|
155 |
// Here comes the tricky part ... have to assemble a complete URL
|
|
156 |
// for the current page.
|
|
157 |
|
|
158 | 0 |
IEngineService pageService = getPageService(); |
159 | 0 |
String pageName = getPage().getPageName(); |
160 |
|
|
161 | 0 |
ILink link = pageService.getLink(cycle, pageName); |
162 |
|
|
163 | 0 |
StringBuffer buffer = new StringBuffer();
|
164 | 0 |
buffer.append(refresh); |
165 | 0 |
buffer.append("; URL=");
|
166 | 0 |
buffer.append(link.getAbsoluteURL()); |
167 |
|
|
168 | 0 |
writeMetaTag(writer, "http-equiv", "Refresh", buffer.toString()); |
169 |
} |
|
170 |
|
|
171 | 270 |
private void writeMetaTag(IMarkupWriter writer, String key, String value, String content) |
172 |
{ |
|
173 | 270 |
writer.beginEmpty("meta");
|
174 | 270 |
writer.attribute(key, value); |
175 | 270 |
writer.attribute("content", content);
|
176 | 270 |
writer.println(); |
177 |
} |
|
178 |
|
|
179 |
public abstract IRender getDelegate();
|
|
180 |
|
|
181 |
public abstract int getRefresh(); |
|
182 |
|
|
183 |
public abstract IAsset getStylesheet();
|
|
184 |
|
|
185 |
public abstract Object getStylesheets();
|
|
186 |
|
|
187 |
public abstract String getTitle();
|
|
188 |
|
|
189 |
public abstract String getDoctype();
|
|
190 |
|
|
191 |
public abstract boolean getRenderContentType(); |
|
192 |
|
|
193 |
/** @since 4.0 */
|
|
194 |
public abstract ValueConverter getValueConverter();
|
|
195 |
|
|
196 |
/** @since 4.0 */
|
|
197 |
|
|
198 |
public abstract IEngineService getPageService();
|
|
199 |
|
|
200 |
/** @since 4.0 */
|
|
201 |
|
|
202 |
public abstract IApplicationSpecification getApplicationSpecification();
|
|
203 |
|
|
204 |
/** @since 4.0 */
|
|
205 |
|
|
206 |
public abstract IRender getBaseTagWriter();
|
|
207 |
} |
|