KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > portlet > PortletRendererImpl


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 JavaDoc;
18 import java.io.PrintWriter JavaDoc;
19 import java.util.Date JavaDoc;
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 JavaDoc _applicationId;
50
51     public void renderPage(IRequestCycle cycle, String JavaDoc pageName) throws IOException JavaDoc
52     {
53         cycle.activate(pageName);
54
55         IPage page = cycle.getPage();
56
57         ContentType contentType = page.getResponseContentType();
58
59         PrintWriter JavaDoc printWriter = _response.getPrintWriter(contentType);
60
61         IMarkupWriter writer = _markupWriterSource.newMarkupWriter(printWriter, contentType);
62
63         String JavaDoc namespace = _response.getNamespace();
64
65         PageRenderSupportImpl support = new PageRenderSupportImpl(_assetFactory, namespace, null);
66
67         TapestryUtils.storePageRenderSupport(cycle, support);
68
69         IMarkupWriter nested = writer.getNestedWriter();
70
71         cycle.renderPage(nested);
72
73         String JavaDoc id = "Tapestry Portlet " + _applicationId + " " + namespace;
74
75         writer.comment("BEGIN " + id);
76         writer.comment("Page: " + page.getPageName());
77         writer.comment("Generated: " + new Date JavaDoc());
78         writer.comment("Framework version: " + Tapestry.VERSION);
79
80         support.writeBodyScript(writer, cycle);
81
82         nested.close();
83
84         support.writeInitializationScript(writer);
85
86         writer.comment("END " + id);
87
88         writer.close();
89
90         // TODO: Trap errors and do some error reporting here?
91
}
92
93     public void setMarkupWriterSource(MarkupWriterSource markupWriterSource)
94     {
95         _markupWriterSource = markupWriterSource;
96     }
97
98     public void setResponse(WebResponse response)
99     {
100         _response = response;
101     }
102
103     public void setAssetFactory(AssetFactory assetFactory)
104     {
105         _assetFactory = assetFactory;
106     }
107
108     public void setApplicationId(String JavaDoc applicationId)
109     {
110         _applicationId = applicationId;
111     }
112 }
Popular Tags