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