|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
PortletRendererImpl.java | - | 100% | 100% | 100% |
|
1 | // Copyright 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.portlet; | |
16 | ||
17 | import java.io.IOException; | |
18 | import java.io.PrintWriter; | |
19 | import java.util.Date; | |
20 | ||
21 | import org.apache.tapestry.IMarkupWriter; | |
22 | import org.apache.tapestry.IPage; | |
23 | import org.apache.tapestry.IRequestCycle; | |
24 | import org.apache.tapestry.Tapestry; | |
25 | import org.apache.tapestry.TapestryUtils; | |
26 | import org.apache.tapestry.asset.AssetFactory; | |
27 | import org.apache.tapestry.engine.IEngineService; | |
28 | import org.apache.tapestry.markup.MarkupWriterSource; | |
29 | import org.apache.tapestry.util.ContentType; | |
30 | import org.apache.tapestry.util.PageRenderSupportImpl; | |
31 | import org.apache.tapestry.web.WebResponse; | |
32 | ||
33 | /** | |
34 | * The guts of rendering a page as a portlet response; used by | |
35 | * {@link org.apache.tapestry.portlet.RenderService} and | |
36 | * {@link org.apache.tapestry.portlet.PortletHomeService}. | |
37 | * | |
38 | * @author Howard M. Lewis Ship | |
39 | * @since 4.0 | |
40 | */ | |
41 | public class PortletRendererImpl implements PortletRenderer | |
42 | { | |
43 | private WebResponse _response; | |
44 | ||
45 | private MarkupWriterSource _markupWriterSource; | |
46 | ||
47 | private AssetFactory _assetFactory; | |
48 | ||
49 | private String _applicationId; | |
50 | ||
51 | 1 | public void renderPage(IRequestCycle cycle, String pageName) throws IOException |
52 | { | |
53 | 1 | cycle.activate(pageName); |
54 | ||
55 | 1 | IPage page = cycle.getPage(); |
56 | ||
57 | 1 | ContentType contentType = page.getResponseContentType(); |
58 | ||
59 | 1 | PrintWriter printWriter = _response.getPrintWriter(contentType); |
60 | ||
61 | 1 | IMarkupWriter writer = _markupWriterSource.newMarkupWriter(printWriter, contentType); |
62 | ||
63 | 1 | String namespace = _response.getNamespace(); |
64 | ||
65 | 1 | PageRenderSupportImpl support = new PageRenderSupportImpl(_assetFactory, namespace, null); |
66 | ||
67 | 1 | TapestryUtils.storePageRenderSupport(cycle, support); |
68 | ||
69 | 1 | IMarkupWriter nested = writer.getNestedWriter(); |
70 | ||
71 | 1 | cycle.renderPage(nested); |
72 | ||
73 | 1 | String id = "Tapestry Portlet " + _applicationId + " " + namespace; |
74 | ||
75 | 1 | writer.comment("BEGIN " + id); |
76 | 1 | writer.comment("Page: " + page.getPageName()); |
77 | 1 | writer.comment("Generated: " + new Date()); |
78 | 1 | writer.comment("Framework version: " + Tapestry.VERSION); |
79 | ||
80 | 1 | support.writeBodyScript(writer, cycle); |
81 | ||
82 | 1 | nested.close(); |
83 | ||
84 | 1 | support.writeInitializationScript(writer); |
85 | ||
86 | 1 | writer.comment("END " + id); |
87 | ||
88 | 1 | writer.close(); |
89 | ||
90 | // TODO: Trap errors and do some error reporting here? | |
91 | } | |
92 | ||
93 | 1 | public void setMarkupWriterSource(MarkupWriterSource markupWriterSource) |
94 | { | |
95 | 1 | _markupWriterSource = markupWriterSource; |
96 | } | |
97 | ||
98 | 1 | public void setResponse(WebResponse response) |
99 | { | |
100 | 1 | _response = response; |
101 | } | |
102 | ||
103 | 1 | public void setAssetFactory(AssetFactory assetFactory) |
104 | { | |
105 | 1 | _assetFactory = assetFactory; |
106 | } | |
107 | ||
108 | 1 | public void setApplicationId(String applicationId) |
109 | { | |
110 | 1 | _applicationId = applicationId; |
111 | } | |
112 | } |
|