1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.layout.impl; |
18 |
|
|
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.Iterator; |
21 |
|
import java.util.List; |
22 |
|
import java.util.Map; |
23 |
|
|
24 |
|
import org.apache.commons.logging.Log; |
25 |
|
import org.apache.commons.logging.LogFactory; |
26 |
|
import org.apache.jetspeed.JetspeedActions; |
27 |
|
import org.apache.jetspeed.PortalReservedParameters; |
28 |
|
import org.apache.jetspeed.ajax.AjaxAction; |
29 |
|
import org.apache.jetspeed.ajax.AjaxBuilder; |
30 |
|
import org.apache.jetspeed.components.portletregistry.PortletRegistry; |
31 |
|
import org.apache.jetspeed.decoration.DecorationValve; |
32 |
|
import org.apache.jetspeed.decoration.Theme; |
33 |
|
import org.apache.jetspeed.layout.PortletActionSecurityBehavior; |
34 |
|
import org.apache.jetspeed.om.page.Fragment; |
35 |
|
import org.apache.jetspeed.om.page.Page; |
36 |
|
import org.apache.jetspeed.page.PageManager; |
37 |
|
import org.apache.jetspeed.portalsite.PortalSiteRequestContext; |
38 |
|
import org.apache.jetspeed.profiler.impl.ProfilerValveImpl; |
39 |
|
import org.apache.jetspeed.request.RequestContext; |
40 |
|
import org.apache.pluto.om.common.Parameter; |
41 |
|
import org.apache.pluto.om.common.ParameterSet; |
42 |
|
import org.apache.pluto.om.portlet.PortletDefinition; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public class GetPageAction |
54 |
|
extends BaseGetResourceAction |
55 |
|
implements AjaxAction, AjaxBuilder, Constants |
56 |
|
{ |
57 |
0 |
protected Log log = LogFactory.getLog(GetPageAction.class); |
58 |
|
|
59 |
|
private PortletRegistry registry; |
60 |
|
private DecorationValve decorationValve; |
61 |
|
|
62 |
|
public GetPageAction(String template, |
63 |
|
String errorTemplate, |
64 |
|
PageManager pageManager, |
65 |
|
PortletActionSecurityBehavior securityBehavior, |
66 |
|
PortletRegistry registry, |
67 |
|
DecorationValve decorationValve) |
68 |
|
{ |
69 |
0 |
super(template, errorTemplate, pageManager, securityBehavior); |
70 |
0 |
this.registry = registry; |
71 |
0 |
this.decorationValve = decorationValve; |
72 |
0 |
} |
73 |
|
|
74 |
|
public boolean run(RequestContext requestContext, Map resultMap) |
75 |
|
{ |
76 |
0 |
boolean success = true; |
77 |
0 |
String status = "success"; |
78 |
|
try |
79 |
|
{ |
80 |
0 |
resultMap.put(ACTION, "getpage"); |
81 |
0 |
if (false == checkAccess(requestContext, JetspeedActions.VIEW)) |
82 |
|
{ |
83 |
0 |
resultMap.put(REASON, "Insufficient access to view page"); |
84 |
0 |
success = false; |
85 |
0 |
return success; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
0 |
decorationValve.invoke(requestContext, null); |
90 |
|
|
91 |
|
|
92 |
0 |
Page page = requestContext.getPage(); |
93 |
0 |
String pageName = getActionParameter(requestContext, PAGE); |
94 |
0 |
if (pageName != null) |
95 |
|
{ |
96 |
0 |
page = retrievePage(requestContext, pageName); |
97 |
|
} |
98 |
0 |
resultMap.put(STATUS, status); |
99 |
0 |
resultMap.put(PAGE, page); |
100 |
|
|
101 |
0 |
Theme theme = (Theme)requestContext.getAttribute(PortalReservedParameters.PAGE_THEME_ATTRIBUTE); |
102 |
0 |
String pageDecoratorName = null; |
103 |
0 |
if ( theme != null ) |
104 |
|
{ |
105 |
0 |
pageDecoratorName = theme.getPageLayoutDecoration().getName(); |
106 |
|
} |
107 |
|
else |
108 |
|
{ |
109 |
0 |
pageDecoratorName = page.getDefaultDecorator( LAYOUT ); |
110 |
|
} |
111 |
0 |
if ( pageDecoratorName != null ) |
112 |
0 |
resultMap.put( DEFAULT_LAYOUT, pageDecoratorName ); |
113 |
|
|
114 |
0 |
PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY); |
115 |
0 |
if (siteRequestContext == null) |
116 |
|
{ |
117 |
0 |
success = false; |
118 |
0 |
resultMap.put(REASON, "Missing portal site request context from ProfilerValve"); |
119 |
0 |
return success; |
120 |
|
} |
121 |
|
|
122 |
0 |
resultMap.put(PROFILED_PATH, siteRequestContext.getPage().getPath() ); |
123 |
0 |
putSecurityInformation(resultMap, page); |
124 |
0 |
String fragments = getActionParameter(requestContext, FRAGMENTS); |
125 |
0 |
if (fragments == null) |
126 |
|
{ |
127 |
0 |
resultMap.put(FRAGMENTS, "true"); |
128 |
|
} |
129 |
|
else |
130 |
|
{ |
131 |
0 |
if (fragments.equalsIgnoreCase("true")) |
132 |
|
{ |
133 |
0 |
resultMap.put(FRAGMENTS, "true"); |
134 |
|
} |
135 |
|
else |
136 |
|
{ |
137 |
0 |
resultMap.put(FRAGMENTS, "false"); |
138 |
0 |
return success; |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
0 |
Map fragSizes = new HashMap(); |
143 |
0 |
Map portletIcons = new HashMap(); |
144 |
|
|
145 |
0 |
String singleLayoutId = getActionParameter(requestContext, LAYOUTID); |
146 |
0 |
if ( singleLayoutId != null ) |
147 |
|
{ |
148 |
0 |
Fragment currentLayoutFragment = page.getFragmentById( singleLayoutId ); |
149 |
0 |
if ( currentLayoutFragment == null ) |
150 |
|
{ |
151 |
0 |
throw new Exception("layout id not found: " + singleLayoutId ); |
152 |
|
} |
153 |
0 |
Fragment currentPortletFragment = null; |
154 |
|
|
155 |
0 |
String singlePortletId = getActionParameter(requestContext, PORTLETENTITY); |
156 |
0 |
if ( singlePortletId != null ) |
157 |
|
{ |
158 |
0 |
Iterator layoutChildIter = currentLayoutFragment.getFragments().iterator(); |
159 |
0 |
while ( layoutChildIter.hasNext() ) |
160 |
|
{ |
161 |
0 |
Fragment childFrag = (Fragment)layoutChildIter.next(); |
162 |
0 |
if ( childFrag != null ) |
163 |
|
{ |
164 |
0 |
if ( singlePortletId.equals( childFrag.getId() ) ) |
165 |
|
{ |
166 |
0 |
currentPortletFragment = childFrag; |
167 |
0 |
break; |
168 |
|
} |
169 |
|
} |
170 |
0 |
} |
171 |
0 |
if ( currentPortletFragment == null ) |
172 |
|
{ |
173 |
0 |
throw new Exception("portlet id " + singlePortletId + " not found in layout " + singleLayoutId ); |
174 |
|
} |
175 |
0 |
resultMap.put( "portletsingleId", currentPortletFragment.getId() ); |
176 |
|
} |
177 |
|
|
178 |
0 |
retrieveFragmentSpecialProperties( requestContext, currentLayoutFragment, fragSizes, portletIcons ); |
179 |
0 |
resultMap.put( "layoutsingle", currentLayoutFragment ); |
180 |
0 |
} |
181 |
|
else |
182 |
|
{ |
183 |
0 |
retrieveFragmentSpecialProperties( requestContext, page.getRootFragment(), fragSizes, portletIcons ); |
184 |
|
} |
185 |
0 |
resultMap.put( SIZES, fragSizes ); |
186 |
0 |
resultMap.put( "portletIcons", portletIcons ); |
187 |
|
} |
188 |
0 |
catch (Exception e) |
189 |
|
{ |
190 |
|
|
191 |
0 |
log.error("exception while getting page", e); |
192 |
|
|
193 |
|
|
194 |
0 |
success = false; |
195 |
0 |
} |
196 |
|
|
197 |
0 |
return success; |
198 |
|
} |
199 |
|
|
200 |
|
protected Page retrievePage(RequestContext requestContext, String pageName) |
201 |
|
throws Exception |
202 |
|
{ |
203 |
0 |
if (pageName == null) |
204 |
|
{ |
205 |
0 |
pageName = "/"; |
206 |
|
} |
207 |
0 |
Page page = pageManager.getPage(pageName); |
208 |
0 |
return page; |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
protected void retrieveFragmentSpecialProperties( RequestContext requestContext, Fragment frag, Map fragSizes, Map portletIcons ) |
213 |
|
{ |
214 |
0 |
if ( frag == null ) |
215 |
|
{ |
216 |
0 |
return; |
217 |
|
} |
218 |
0 |
if ( fragSizes != null && "layout".equals( frag.getType() ) ) |
219 |
|
{ |
220 |
0 |
String sizesVal = frag.getProperty( "sizes" ); |
221 |
0 |
if ( sizesVal == null || sizesVal.length() == 0 ) |
222 |
|
{ |
223 |
0 |
String layoutName = frag.getName(); |
224 |
0 |
if ( layoutName != null && layoutName.length() > 0 ) |
225 |
|
{ |
226 |
|
|
227 |
0 |
PortletDefinition portletDef = registry.getPortletDefinitionByUniqueName( layoutName ); |
228 |
|
|
229 |
0 |
ParameterSet paramSet = portletDef.getInitParameterSet(); |
230 |
0 |
Parameter sizesParam = paramSet.get( "sizes" ); |
231 |
0 |
String sizesParamVal = ( sizesParam == null ) ? class="keyword">null : sizesParam.getValue(); |
232 |
0 |
if ( sizesParamVal != null && sizesParamVal.length() > 0 ) |
233 |
|
{ |
234 |
0 |
fragSizes.put( frag.getId(), sizesParamVal ); |
235 |
|
|
236 |
|
} |
237 |
|
else |
238 |
|
{ |
239 |
0 |
Parameter colsParam = paramSet.get( "columns" ); |
240 |
0 |
String colsParamVal = ( colsParam == null ) ? class="keyword">null : colsParam.getValue(); |
241 |
0 |
if ( colsParamVal != null && colsParamVal.length() > 0 ) |
242 |
|
{ |
243 |
0 |
int cols = 0; |
244 |
|
try |
245 |
|
{ |
246 |
0 |
cols = Integer.parseInt( colsParamVal ); |
247 |
|
} |
248 |
0 |
catch ( NumberFormatException ex ) |
249 |
|
{ |
250 |
0 |
} |
251 |
0 |
if ( cols < 1 ) |
252 |
|
{ |
253 |
0 |
cols = 2; |
254 |
|
} |
255 |
0 |
switch (cols) |
256 |
|
{ |
257 |
0 |
case 1: sizesParamVal = "100%"; break; |
258 |
0 |
case 2: sizesParamVal = "50%,50%"; break; |
259 |
0 |
case 3: sizesParamVal = "34%,33%,33%"; break; |
260 |
0 |
default: sizesParamVal = "50%,50%"; break; |
261 |
|
} |
262 |
0 |
fragSizes.put( frag.getId(), sizesParamVal ); |
263 |
|
|
264 |
|
} |
265 |
|
} |
266 |
|
} |
267 |
|
} |
268 |
0 |
List childFragments = frag.getFragments(); |
269 |
0 |
if ( childFragments != null ) |
270 |
|
{ |
271 |
0 |
Iterator childFragIter = childFragments.iterator(); |
272 |
0 |
while ( childFragIter.hasNext() ) |
273 |
|
{ |
274 |
0 |
Fragment childFrag = (Fragment)childFragIter.next(); |
275 |
0 |
retrieveFragmentSpecialProperties( requestContext, childFrag, fragSizes, portletIcons ); |
276 |
0 |
} |
277 |
|
} |
278 |
0 |
} |
279 |
0 |
else if ( portletIcons != null && "portlet".equals( frag.getType() ) ) |
280 |
|
{ |
281 |
0 |
String portletName = frag.getName(); |
282 |
0 |
if ( portletName != null && portletName.length() > 0 ) |
283 |
|
{ |
284 |
0 |
PortletDefinition portletDef = registry.getPortletDefinitionByUniqueName( portletName ); |
285 |
|
|
286 |
0 |
if ( portletDef != null && portletIcons != class="keyword">null ) |
287 |
|
{ |
288 |
0 |
ParameterSet paramSet = portletDef.getInitParameterSet(); |
289 |
0 |
Parameter iconParam = paramSet.get( "portlet-icon" ); |
290 |
0 |
String iconParamVal = ( iconParam == null ) ? class="keyword">null : iconParam.getValue(); |
291 |
0 |
if ( iconParamVal != null && iconParamVal.length() > 0 ) |
292 |
|
{ |
293 |
0 |
portletIcons.put( frag.getId(), iconParamVal ); |
294 |
|
} |
295 |
0 |
} |
296 |
0 |
else if ( portletDef == null ) |
297 |
|
{ |
298 |
0 |
log.error( "GetPageAction could not obtain PortletDefinition for portlet " + portletName ); |
299 |
|
} |
300 |
|
} |
301 |
|
} |
302 |
0 |
} |
303 |
|
|
304 |
|
} |