1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.portlet; |
16 |
| |
17 |
| import java.io.IOException; |
18 |
| import java.io.PrintWriter; |
19 |
| import java.util.ArrayList; |
20 |
| import java.util.Date; |
21 |
| import java.util.List; |
22 |
| |
23 |
| import org.apache.hivemind.ApplicationRuntimeException; |
24 |
| import org.apache.tapestry.IMarkupWriter; |
25 |
| import org.apache.tapestry.IPage; |
26 |
| import org.apache.tapestry.IRequestCycle; |
27 |
| import org.apache.tapestry.PageRedirectException; |
28 |
| import org.apache.tapestry.Tapestry; |
29 |
| import org.apache.tapestry.TapestryUtils; |
30 |
| import org.apache.tapestry.asset.AssetFactory; |
31 |
| import org.apache.tapestry.engine.EngineMessages; |
32 |
| import org.apache.tapestry.markup.MarkupWriterSource; |
33 |
| import org.apache.tapestry.util.ContentType; |
34 |
| import org.apache.tapestry.util.PageRenderSupportImpl; |
35 |
| import org.apache.tapestry.web.WebResponse; |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| public class PortletRendererImpl implements PortletRenderer |
46 |
| { |
47 |
| private WebResponse _response; |
48 |
| |
49 |
| private MarkupWriterSource _markupWriterSource; |
50 |
| |
51 |
| private AssetFactory _assetFactory; |
52 |
| |
53 |
| private String _applicationId; |
54 |
| |
55 |
1
| public void renderPage(IRequestCycle cycle, String pageName) throws IOException
|
56 |
| { |
57 |
1
| try {
|
58 |
1
| cycle.activate(pageName);
|
59 |
| |
60 |
1
| IPage page = cycle.getPage();
|
61 |
| |
62 |
1
| ContentType contentType = page.getResponseContentType();
|
63 |
| |
64 |
1
| PrintWriter printWriter = _response.getPrintWriter(contentType);
|
65 |
| |
66 |
1
| IMarkupWriter writer = _markupWriterSource.newMarkupWriter(printWriter, contentType);
|
67 |
| |
68 |
1
| String namespace = _response.getNamespace();
|
69 |
| |
70 |
1
| PageRenderSupportImpl support = new PageRenderSupportImpl(_assetFactory, namespace, null);
|
71 |
| |
72 |
1
| TapestryUtils.storePageRenderSupport(cycle, support);
|
73 |
| |
74 |
1
| IMarkupWriter nested = writer.getNestedWriter();
|
75 |
| |
76 |
1
| cycle.renderPage(nested);
|
77 |
| |
78 |
1
| String id = "Tapestry Portlet " + _applicationId + " " + namespace;
|
79 |
| |
80 |
1
| writer.comment("BEGIN " + id);
|
81 |
1
| writer.comment("Page: " + page.getPageName());
|
82 |
1
| writer.comment("Generated: " + new Date());
|
83 |
1
| writer.comment("Framework version: " + Tapestry.VERSION);
|
84 |
| |
85 |
1
| support.writeBodyScript(writer, cycle);
|
86 |
| |
87 |
1
| nested.close();
|
88 |
| |
89 |
1
| support.writeInitializationScript(writer);
|
90 |
| |
91 |
1
| writer.comment("END " + id);
|
92 |
| |
93 |
1
| writer.close();
|
94 |
| |
95 |
| |
96 |
| } |
97 |
| catch (PageRedirectException e) { |
98 |
0
| handlePageRedirectException(cycle, e);
|
99 |
| } |
100 |
| } |
101 |
| |
102 |
0
| protected void handlePageRedirectException(IRequestCycle cycle, PageRedirectException exception)
|
103 |
| throws IOException |
104 |
| { |
105 |
0
| List pageNames = new ArrayList();
|
106 |
| |
107 |
0
| String pageName = exception.getTargetPageName();
|
108 |
| |
109 |
0
| while (true)
|
110 |
| { |
111 |
0
| if (pageNames.contains(pageName))
|
112 |
| { |
113 |
0
| pageNames.add(pageName);
|
114 |
| |
115 |
0
| throw new ApplicationRuntimeException(EngineMessages.validateCycle(pageNames));
|
116 |
| } |
117 |
| |
118 |
| |
119 |
| |
120 |
0
| pageNames.add(pageName);
|
121 |
| |
122 |
0
| try
|
123 |
| { |
124 |
| |
125 |
| |
126 |
0
| cycle.activate(pageName);
|
127 |
| |
128 |
0
| break;
|
129 |
| } |
130 |
| catch (PageRedirectException secondRedirectException) |
131 |
| { |
132 |
0
| pageName = secondRedirectException.getTargetPageName();
|
133 |
| } |
134 |
| } |
135 |
| |
136 |
0
| renderPage(cycle, pageName);
|
137 |
| } |
138 |
| |
139 |
1
| public void setMarkupWriterSource(MarkupWriterSource markupWriterSource)
|
140 |
| { |
141 |
1
| _markupWriterSource = markupWriterSource;
|
142 |
| } |
143 |
| |
144 |
1
| public void setResponse(WebResponse response)
|
145 |
| { |
146 |
1
| _response = response;
|
147 |
| } |
148 |
| |
149 |
1
| public void setAssetFactory(AssetFactory assetFactory)
|
150 |
| { |
151 |
1
| _assetFactory = assetFactory;
|
152 |
| } |
153 |
| |
154 |
1
| public void setApplicationId(String applicationId)
|
155 |
| { |
156 |
1
| _applicationId = applicationId;
|
157 |
| } |
158 |
| } |