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.Iterator; |
21 |
|
|
22 |
|
import org.apache.commons.logging.Log; |
23 |
|
import org.apache.commons.logging.LogFactory; |
24 |
|
import org.apache.jetspeed.PortalReservedParameters; |
25 |
|
import org.apache.jetspeed.aggregator.FailedToRenderFragmentException; |
26 |
|
import org.apache.jetspeed.aggregator.PageAggregator; |
27 |
|
import org.apache.jetspeed.aggregator.PortletRenderer; |
28 |
|
import org.apache.jetspeed.container.state.NavigationalState; |
29 |
|
import org.apache.jetspeed.exception.JetspeedException; |
30 |
|
import org.apache.jetspeed.om.page.ContentFragment; |
31 |
|
import org.apache.jetspeed.om.page.ContentPage; |
32 |
|
import org.apache.jetspeed.request.RequestContext; |
33 |
|
import org.apache.pluto.om.window.PortletWindow; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
public class PageAggregatorImpl implements PageAggregator |
43 |
|
{ |
44 |
0 |
private final static Log log = LogFactory.getLog(PageAggregatorImpl.class); |
45 |
|
private PortletRenderer renderer; |
46 |
|
|
47 |
|
public PageAggregatorImpl( PortletRenderer renderer) |
48 |
0 |
{ |
49 |
0 |
this.renderer = renderer; |
50 |
0 |
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
public void build( RequestContext context ) throws JetspeedException, IOException |
58 |
|
{ |
59 |
0 |
ContentPage page = context.getPage(); |
60 |
0 |
if (null == page) |
61 |
|
{ |
62 |
0 |
throw new JetspeedException("Failed to find PSML Pin ContentPageAggregator.build"); |
63 |
|
} |
64 |
0 |
ContentFragment root = page.getRootContentFragment(); |
65 |
0 |
if (root == null) |
66 |
|
{ |
67 |
0 |
throw new JetspeedException("No root ContentFragment found in ContentPage"); |
68 |
|
} |
69 |
|
|
70 |
0 |
NavigationalState nav = context.getPortalURL().getNavigationalState(); |
71 |
0 |
PortletWindow window = nav.getMaximizedWindow(); |
72 |
0 |
if (null != window) |
73 |
|
{ |
74 |
0 |
renderMaximizedWindow(context, page, root, window); |
75 |
|
} |
76 |
|
else |
77 |
|
{ |
78 |
0 |
aggregateAndRender(root, context, page); |
79 |
|
} |
80 |
0 |
context.getResponse().getWriter().write(root.getRenderedContent()); |
81 |
0 |
if (null != window) |
82 |
|
{ |
83 |
0 |
context.getRequest().removeAttribute(PortalReservedParameters.MAXIMIZED_FRAGMENT_ATTRIBUTE); |
84 |
0 |
context.getRequest().removeAttribute(PortalReservedParameters.MAXIMIZED_LAYOUT_ATTRIBUTE); |
85 |
|
} |
86 |
0 |
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
protected void renderMaximizedWindow( RequestContext context, ContentPage page, ContentFragment layoutContentFragment, |
102 |
|
PortletWindow window ) throws FailedToRenderFragmentException |
103 |
|
{ |
104 |
0 |
ContentFragment maxedContentFragment = page.getContentFragmentById(window.getId().toString()); |
105 |
0 |
if (maxedContentFragment != null) |
106 |
|
{ |
107 |
0 |
context.getRequest().setAttribute(PortalReservedParameters.MAXIMIZED_FRAGMENT_ATTRIBUTE, maxedContentFragment); |
108 |
0 |
context.getRequest().setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, maxedContentFragment); |
109 |
0 |
context.getRequest().setAttribute(PortalReservedParameters.MAXIMIZED_LAYOUT_ATTRIBUTE, page.getRootContentFragment()); |
110 |
|
|
111 |
|
try |
112 |
|
{ |
113 |
0 |
renderer.renderNow(maxedContentFragment, context); |
114 |
0 |
renderer.renderNow(layoutContentFragment, context); |
115 |
|
|
116 |
|
} |
117 |
0 |
catch (Exception e) |
118 |
|
{ |
119 |
0 |
log.error(e.getMessage(), e); |
120 |
0 |
maxedContentFragment.overrideRenderedContent("Sorry, but we were unable access the requested portlet. Send the following message to your portal admin: "+ e.getMessage()); |
121 |
0 |
} |
122 |
|
} |
123 |
|
else |
124 |
|
{ |
125 |
0 |
String message = "Maximized fragment not found."; |
126 |
0 |
log.error(message); |
127 |
0 |
if (maxedContentFragment != null) |
128 |
0 |
maxedContentFragment.overrideRenderedContent("Sorry, but we were unable access the requested portlet. Send the following message to your portal admin: "+ message); |
129 |
|
} |
130 |
0 |
} |
131 |
|
|
132 |
|
protected void aggregateAndRender( ContentFragment f, RequestContext context, ContentPage page ) |
133 |
|
throws FailedToRenderFragmentException |
134 |
|
{ |
135 |
0 |
if (f.getContentFragments() != null && f.getContentFragments().size() > 0) |
136 |
|
{ |
137 |
0 |
Iterator children = f.getContentFragments().iterator(); |
138 |
0 |
while (children.hasNext()) |
139 |
|
{ |
140 |
0 |
ContentFragment child = (ContentFragment) children.next(); |
141 |
0 |
if (!"hidden".equals(f.getState())) |
142 |
|
{ |
143 |
0 |
aggregateAndRender(child, context, page); |
144 |
|
} |
145 |
0 |
} |
146 |
|
} |
147 |
0 |
renderer.renderNow(f, context); |
148 |
0 |
} |
149 |
|
} |