1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.aggregator.impl; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.util.ArrayList; |
21 |
|
import java.util.Iterator; |
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import org.apache.commons.logging.Log; |
25 |
|
import org.apache.commons.logging.LogFactory; |
26 |
|
import org.apache.jetspeed.PortalReservedParameters; |
27 |
|
import org.apache.jetspeed.aggregator.FailedToRenderFragmentException; |
28 |
|
import org.apache.jetspeed.aggregator.PageAggregator; |
29 |
|
import org.apache.jetspeed.aggregator.PortletContent; |
30 |
|
import org.apache.jetspeed.aggregator.PortletRenderer; |
31 |
|
import org.apache.jetspeed.aggregator.RenderingJob; |
32 |
|
import org.apache.jetspeed.aggregator.CurrentWorkerContext; |
33 |
|
import org.apache.jetspeed.container.state.NavigationalState; |
34 |
|
import org.apache.jetspeed.exception.JetspeedException; |
35 |
|
import org.apache.jetspeed.om.page.ContentFragment; |
36 |
|
import org.apache.jetspeed.om.page.ContentPage; |
37 |
|
import org.apache.jetspeed.request.RequestContext; |
38 |
|
import org.apache.pluto.om.window.PortletWindow; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public class AsyncPageAggregatorImpl implements PageAggregator |
51 |
|
{ |
52 |
0 |
protected final static Log log = LogFactory.getLog(AsyncPageAggregatorImpl.class); |
53 |
|
|
54 |
|
protected PortletRenderer renderer; |
55 |
|
|
56 |
|
protected List fallBackContentPathes; |
57 |
|
|
58 |
|
public AsyncPageAggregatorImpl(PortletRenderer renderer) |
59 |
0 |
{ |
60 |
0 |
this.renderer = renderer; |
61 |
0 |
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
public void build( RequestContext context ) throws JetspeedException, IOException |
69 |
|
{ |
70 |
0 |
ContentPage page = context.getPage(); |
71 |
0 |
if (null == page) |
72 |
|
{ |
73 |
0 |
throw new JetspeedException("Failed to find PSML Pin ContentPageAggregator.build"); |
74 |
|
} |
75 |
0 |
ContentFragment root = page.getRootContentFragment(); |
76 |
0 |
if (root == null) |
77 |
|
{ |
78 |
0 |
throw new JetspeedException("No root ContentFragment found in ContentPage"); |
79 |
|
} |
80 |
|
|
81 |
0 |
NavigationalState nav = context.getPortalURL().getNavigationalState(); |
82 |
0 |
PortletWindow window = nav.getMaximizedWindow(); |
83 |
0 |
if (null != window) |
84 |
|
{ |
85 |
0 |
renderMaximizedWindow(context, page, root, window); |
86 |
|
} |
87 |
|
else |
88 |
|
{ |
89 |
0 |
aggregateAndRender(root, context, page, true, null, class="keyword">null, class="keyword">null); |
90 |
|
} |
91 |
|
|
92 |
0 |
context.getResponse().getWriter().write(root.getRenderedContent()); |
93 |
0 |
if (null != window) |
94 |
|
{ |
95 |
0 |
context.getRequest().removeAttribute(PortalReservedParameters.MAXIMIZED_FRAGMENT_ATTRIBUTE); |
96 |
0 |
context.getRequest().removeAttribute(PortalReservedParameters.MAXIMIZED_LAYOUT_ATTRIBUTE); |
97 |
|
} |
98 |
0 |
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
protected void renderMaximizedWindow( RequestContext context, ContentPage page, ContentFragment layoutContentFragment, |
114 |
|
PortletWindow window ) throws FailedToRenderFragmentException |
115 |
|
{ |
116 |
0 |
ContentFragment maxedContentFragment = page.getContentFragmentById(window.getId().toString()); |
117 |
0 |
if (maxedContentFragment != null) |
118 |
|
{ |
119 |
0 |
context.getRequest().setAttribute(PortalReservedParameters.MAXIMIZED_FRAGMENT_ATTRIBUTE, maxedContentFragment); |
120 |
0 |
context.getRequest().setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, maxedContentFragment); |
121 |
0 |
context.getRequest().setAttribute(PortalReservedParameters.MAXIMIZED_LAYOUT_ATTRIBUTE, page.getRootContentFragment()); |
122 |
|
try |
123 |
|
{ |
124 |
0 |
renderer.renderNow(maxedContentFragment, context); |
125 |
0 |
renderer.renderNow(layoutContentFragment, context); |
126 |
|
} |
127 |
0 |
catch (Exception e) |
128 |
|
{ |
129 |
0 |
log.error(e.getMessage(), e); |
130 |
0 |
maxedContentFragment.overrideRenderedContent("Sorry, but we were unable access the requested portlet. Send the following message to your portal admin: "+ e.getMessage()); |
131 |
0 |
} |
132 |
|
} |
133 |
0 |
} |
134 |
|
|
135 |
|
protected void aggregateAndRender(ContentFragment f, RequestContext context, ContentPage page, boolean isRoot, |
136 |
|
List sequentialJobs, List parallelJobs, List layoutFragments) |
137 |
|
throws FailedToRenderFragmentException |
138 |
|
{ |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
0 |
if (sequentialJobs == null) |
143 |
|
{ |
144 |
0 |
sequentialJobs = new ArrayList(); |
145 |
|
} |
146 |
0 |
if (parallelJobs == null) |
147 |
|
{ |
148 |
0 |
parallelJobs = new ArrayList(); |
149 |
|
} |
150 |
0 |
if (layoutFragments == null) |
151 |
|
{ |
152 |
0 |
layoutFragments = new ArrayList(); |
153 |
|
} |
154 |
|
|
155 |
0 |
if (f.getContentFragments() != null && f.getContentFragments().size() > 0) |
156 |
|
{ |
157 |
0 |
Iterator children = f.getContentFragments().iterator(); |
158 |
0 |
while (children.hasNext()) |
159 |
|
{ |
160 |
0 |
ContentFragment child = (ContentFragment) children.next(); |
161 |
0 |
if (!"hidden".equals(f.getState())) |
162 |
|
{ |
163 |
0 |
if (child.getType().equals(ContentFragment.PORTLET)) |
164 |
|
{ |
165 |
|
|
166 |
0 |
RenderingJob job = renderer.createRenderingJob(child, context); |
167 |
|
|
168 |
|
|
169 |
0 |
if (job != null) |
170 |
|
{ |
171 |
0 |
if (job.getTimeout() > 0) |
172 |
0 |
parallelJobs.add(job); |
173 |
|
else |
174 |
0 |
sequentialJobs.add(job); |
175 |
|
} |
176 |
0 |
} |
177 |
|
else |
178 |
|
{ |
179 |
|
|
180 |
|
|
181 |
0 |
aggregateAndRender(child, context, page, false, sequentialJobs, parallelJobs, layoutFragments); |
182 |
0 |
layoutFragments.add(child); |
183 |
|
} |
184 |
|
} |
185 |
0 |
} |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
0 |
if (!isRoot) |
190 |
0 |
return; |
191 |
|
|
192 |
0 |
int parallelJobCount = parallelJobs.size(); |
193 |
0 |
int sequentialJobCount = sequentialJobs.size(); |
194 |
|
|
195 |
0 |
if (log.isInfoEnabled()) |
196 |
|
{ |
197 |
0 |
log.info("Aggregating " + page.getPath() + ". Parallel: " + parallelJobCount + ", Sequential: " + sequentialJobCount); |
198 |
|
} |
199 |
|
|
200 |
0 |
CurrentWorkerContext.setParallelRenderingMode(parallelJobCount > 0); |
201 |
|
|
202 |
|
|
203 |
0 |
Iterator iter = parallelJobs.iterator(); |
204 |
0 |
while (iter.hasNext()) |
205 |
|
{ |
206 |
0 |
RenderingJob job = (RenderingJob) iter.next(); |
207 |
0 |
renderer.processRenderingJob(job); |
208 |
0 |
} |
209 |
|
|
210 |
|
|
211 |
0 |
iter = sequentialJobs.iterator(); |
212 |
0 |
while (iter.hasNext()) |
213 |
|
{ |
214 |
0 |
RenderingJob job = (RenderingJob) iter.next(); |
215 |
0 |
renderer.processRenderingJob(job); |
216 |
0 |
} |
217 |
|
|
218 |
|
|
219 |
0 |
renderer.waitForRenderingJobs(parallelJobs); |
220 |
|
|
221 |
|
|
222 |
0 |
CurrentWorkerContext.setParallelRenderingMode(false); |
223 |
|
|
224 |
|
|
225 |
0 |
iter = layoutFragments.iterator(); |
226 |
0 |
while (iter.hasNext()) |
227 |
|
{ |
228 |
0 |
ContentFragment child = (ContentFragment) iter.next(); |
229 |
0 |
renderer.renderNow(child, context); |
230 |
0 |
} |
231 |
|
|
232 |
|
|
233 |
0 |
String defaultPortletDecorator = page.getEffectiveDefaultDecorator(ContentFragment.PORTLET); |
234 |
0 |
if (log.isDebugEnabled()) |
235 |
|
{ |
236 |
0 |
log.debug("Rendering portlet fragment: [[name, " + f.getName() + "], [id, " + f.getId() + "]]"); |
237 |
|
} |
238 |
|
|
239 |
0 |
renderer.renderNow(f, context); |
240 |
0 |
} |
241 |
|
|
242 |
|
|
243 |
|
} |