1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.decoration; |
18 |
|
|
19 |
|
import java.util.ArrayList; |
20 |
|
import java.util.Collections; |
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Properties; |
25 |
|
|
26 |
|
import javax.portlet.PortletMode; |
27 |
|
import javax.portlet.WindowState; |
28 |
|
|
29 |
|
import org.apache.commons.logging.Log; |
30 |
|
import org.apache.commons.logging.LogFactory; |
31 |
|
import org.apache.jetspeed.JetspeedActions; |
32 |
|
import org.apache.jetspeed.PortalReservedParameters; |
33 |
|
import org.apache.jetspeed.cache.CacheElement; |
34 |
|
import org.apache.jetspeed.cache.ContentCacheKey; |
35 |
|
import org.apache.jetspeed.cache.JetspeedContentCache; |
36 |
|
import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException; |
37 |
|
import org.apache.jetspeed.container.url.PortalURL; |
38 |
|
import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow; |
39 |
|
import org.apache.jetspeed.container.window.PortletWindowAccessor; |
40 |
|
import org.apache.jetspeed.decoration.caches.SessionPathResolverCache; |
41 |
|
import org.apache.jetspeed.om.common.portlet.PortletApplication; |
42 |
|
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite; |
43 |
|
import org.apache.jetspeed.om.page.ContentFragment; |
44 |
|
import org.apache.jetspeed.om.page.ContentPage; |
45 |
|
import org.apache.jetspeed.om.page.Fragment; |
46 |
|
import org.apache.jetspeed.om.page.Page; |
47 |
|
import org.apache.jetspeed.pipeline.PipelineException; |
48 |
|
import org.apache.jetspeed.pipeline.valve.AbstractValve; |
49 |
|
import org.apache.jetspeed.pipeline.valve.Valve; |
50 |
|
import org.apache.jetspeed.pipeline.valve.ValveContext; |
51 |
|
import org.apache.jetspeed.request.RequestContext; |
52 |
|
import org.apache.jetspeed.security.SecurityAccessController; |
53 |
|
import org.apache.pluto.om.portlet.ContentTypeSet; |
54 |
|
import org.apache.pluto.om.window.PortletWindow; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
public class DecorationValve extends AbstractValve implements Valve |
72 |
|
{ |
73 |
|
public static final String ACTION_IMAGE_EXTENSION_ATTR = "actionImageExtension"; |
74 |
|
public static final String IS_AJAX_DECORATION_REQUEST = "org.apache.jetspeed.decoration.ajax"; |
75 |
|
|
76 |
0 |
protected final static Log log = LogFactory.getLog(DecorationValve.class); |
77 |
|
|
78 |
|
private final DecorationFactory decorationFactory; |
79 |
|
|
80 |
|
private final PortletWindowAccessor windowAccessor; |
81 |
|
|
82 |
0 |
private HashMap decoratorActionsAdapterCache = new HashMap(); |
83 |
|
|
84 |
|
private DecoratorActionsFactory defaultDecoratorActionsFactory; |
85 |
|
|
86 |
0 |
private JetspeedContentCache cache = null; |
87 |
|
|
88 |
0 |
private boolean useSessionForThemeCaching = false; |
89 |
|
|
90 |
0 |
private boolean maxOnEdit = false; |
91 |
|
|
92 |
0 |
private boolean maxOnConfig = false; |
93 |
|
|
94 |
0 |
private boolean maxOnEditDefaults = false; |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
0 |
private boolean autoSwitchingForConfigMode = false; |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
0 |
private boolean autoSwitchingToEditDefaultsModes = true; |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
protected SecurityAccessController accessController; |
110 |
|
|
111 |
|
public DecorationValve(DecorationFactory decorationFactory, PortletWindowAccessor windowAccessor,SecurityAccessController accessController) |
112 |
|
{ |
113 |
0 |
this(decorationFactory, windowAccessor, accessController, null); |
114 |
0 |
} |
115 |
|
|
116 |
|
public DecorationValve(DecorationFactory decorationFactory, PortletWindowAccessor windowAccessor, |
117 |
|
SecurityAccessController accessController, JetspeedContentCache cache) |
118 |
|
{ |
119 |
0 |
this(decorationFactory, windowAccessor, accessController, cache, false); |
120 |
0 |
} |
121 |
|
|
122 |
|
public DecorationValve(DecorationFactory decorationFactory, PortletWindowAccessor windowAccessor, |
123 |
|
SecurityAccessController accessController, JetspeedContentCache cache, |
124 |
|
boolean useSessionForThemeCaching) |
125 |
0 |
{ |
126 |
0 |
this.decorationFactory = decorationFactory; |
127 |
0 |
this.windowAccessor = windowAccessor; |
128 |
0 |
this.defaultDecoratorActionsFactory = new DefaultDecoratorActionsFactory(); |
129 |
|
|
130 |
0 |
this.accessController = accessController; |
131 |
0 |
this.cache = cache; |
132 |
0 |
this.useSessionForThemeCaching = useSessionForThemeCaching; |
133 |
0 |
} |
134 |
|
|
135 |
|
public void invoke(RequestContext requestContext, ValveContext context) throws PipelineException |
136 |
|
{ |
137 |
|
|
138 |
0 |
boolean isAjaxRequest = (context == null); |
139 |
0 |
initFragments( requestContext, isAjaxRequest, null ); |
140 |
|
|
141 |
|
|
142 |
0 |
if (!isAjaxRequest) |
143 |
|
{ |
144 |
0 |
context.invokeNext(requestContext); |
145 |
|
} |
146 |
0 |
} |
147 |
|
|
148 |
|
|
149 |
|
public void initFragments( RequestContext requestContext, boolean isAjaxRequest, List fragments ) |
150 |
|
{ |
151 |
0 |
if (isAjaxRequest) |
152 |
|
{ |
153 |
0 |
requestContext.setAttribute(IS_AJAX_DECORATION_REQUEST, new Boolean(true)); |
154 |
|
} |
155 |
|
|
156 |
0 |
ContentPage page = requestContext.getPage(); |
157 |
|
|
158 |
|
|
159 |
0 |
if (requestContext |
160 |
|
.getSessionAttribute(PortalReservedParameters.PAGE_THEME_OVERRIDE_ATTRIBUTE) != null) |
161 |
|
{ |
162 |
0 |
String decoratorName = (String) requestContext |
163 |
|
.getSessionAttribute(PortalReservedParameters.PAGE_THEME_OVERRIDE_ATTRIBUTE); |
164 |
0 |
page.setDefaultDecorator(decoratorName, Fragment.LAYOUT); |
165 |
|
} |
166 |
|
|
167 |
0 |
PageActionAccess pageActionAccess = (PageActionAccess)requestContext.getAttribute(PortalReservedParameters.PAGE_EDIT_ACCESS_ATTRIBUTE); |
168 |
0 |
String themeCacheKey = null; |
169 |
0 |
ContentCacheKey themeContentCacheKey = null; |
170 |
0 |
Theme theme = null; |
171 |
|
|
172 |
0 |
if (useCache()) |
173 |
|
{ |
174 |
0 |
if (pageActionAccess.isEditing() == false) |
175 |
|
{ |
176 |
|
|
177 |
0 |
if (this.useSessionForThemeCaching) |
178 |
|
{ |
179 |
0 |
themeCacheKey = cache.createSessionKey(requestContext); |
180 |
0 |
theme = (Theme) requestContext.getSessionAttribute(themeCacheKey); |
181 |
|
} |
182 |
|
else |
183 |
|
{ |
184 |
0 |
themeContentCacheKey = cache.createCacheKey(requestContext, page.getId()); |
185 |
0 |
CacheElement themeCacheElem = cache.get(themeContentCacheKey); |
186 |
|
|
187 |
0 |
if (themeCacheElem != null) |
188 |
|
{ |
189 |
0 |
theme = (Theme) themeCacheElem.getContent(); |
190 |
|
} |
191 |
|
} |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
0 |
if (theme != null) |
196 |
|
{ |
197 |
0 |
theme.init(page, decorationFactory, requestContext); |
198 |
0 |
requestContext.setAttribute(PortalReservedParameters.PAGE_THEME_ATTRIBUTE, theme); |
199 |
0 |
boolean solo = isSoloMode(requestContext); |
200 |
0 |
SessionPathResolverCache sessionPathResolver = new SessionPathResolverCache( requestContext.getRequest().getSession() ); |
201 |
0 |
initDepthFragmentDecorations(requestContext, theme, page.getRootContentFragment(), |
202 |
|
pageActionAccess, isAjaxRequest, |
203 |
|
((DecorationFactoryImpl) decorationFactory).getResourceValidator(), |
204 |
|
sessionPathResolver, (theme.isInvalidated() && !solo)); |
205 |
|
|
206 |
0 |
if (theme.isInvalidated() && !solo) |
207 |
|
{ |
208 |
0 |
if (this.useSessionForThemeCaching) |
209 |
|
{ |
210 |
0 |
requestContext.setSessionAttribute(themeCacheKey, theme); |
211 |
|
} |
212 |
|
else |
213 |
|
{ |
214 |
0 |
CacheElement themeCacheElem = cache.createElement(themeContentCacheKey, theme); |
215 |
0 |
cache.put(themeCacheElem); |
216 |
|
} |
217 |
0 |
theme.setInvalidated(false); |
218 |
|
} |
219 |
0 |
return; |
220 |
|
} |
221 |
0 |
theme = decorationFactory.getTheme(page, requestContext); |
222 |
0 |
requestContext.setAttribute(PortalReservedParameters.PAGE_THEME_ATTRIBUTE, theme); |
223 |
0 |
if ( fragments == null || fragments.size() == 0 ) |
224 |
|
{ |
225 |
0 |
ContentFragment rootFragment = page.getRootContentFragment(); |
226 |
0 |
initDepthFragments(requestContext, theme, rootFragment, pageActionAccess, isAjaxRequest, fragments); |
227 |
0 |
} |
228 |
|
else |
229 |
|
{ |
230 |
0 |
Iterator fragmentsIter = fragments.iterator(); |
231 |
0 |
while ( fragmentsIter.hasNext() ) |
232 |
|
{ |
233 |
0 |
ContentFragment fragment = (ContentFragment)fragmentsIter.next(); |
234 |
0 |
initFragment(requestContext, theme, fragment, pageActionAccess, isAjaxRequest); |
235 |
0 |
} |
236 |
|
} |
237 |
|
|
238 |
0 |
if (useCache() && !isSoloMode(requestContext)) |
239 |
|
{ |
240 |
0 |
if (themeContentCacheKey == null && themeCacheKey == class="keyword">null) |
241 |
|
{ |
242 |
0 |
if (this.useSessionForThemeCaching) |
243 |
|
{ |
244 |
0 |
themeCacheKey = cache.createSessionKey(requestContext); |
245 |
0 |
requestContext.getRequest().getSession().removeAttribute(themeCacheKey); |
246 |
|
} |
247 |
|
else |
248 |
|
{ |
249 |
0 |
themeContentCacheKey = cache.createCacheKey(requestContext, page.getId()); |
250 |
0 |
cache.remove(themeContentCacheKey); |
251 |
|
} |
252 |
|
} |
253 |
|
else |
254 |
|
{ |
255 |
0 |
if (this.useSessionForThemeCaching) |
256 |
|
{ |
257 |
0 |
themeContentCacheKey = cache.createCacheKey(requestContext, page.getId()); |
258 |
0 |
requestContext.setSessionAttribute(themeCacheKey, theme); |
259 |
|
} |
260 |
|
else |
261 |
|
{ |
262 |
0 |
CacheElement themeCacheElem = cache.createElement(themeContentCacheKey, theme); |
263 |
0 |
cache.put(themeCacheElem); |
264 |
|
} |
265 |
|
} |
266 |
|
} |
267 |
0 |
} |
268 |
|
|
269 |
|
protected boolean isSoloMode(RequestContext requestContext) |
270 |
|
{ |
271 |
0 |
boolean solo = false; |
272 |
0 |
PortletWindow window = requestContext.getPortalURL().getNavigationalState().getMaximizedWindow(); |
273 |
0 |
boolean maximized = (window != null); |
274 |
0 |
if (maximized) |
275 |
|
{ |
276 |
0 |
solo = JetspeedActions.SOLO_STATE.equals(requestContext.getPortalURL().getNavigationalState().getMappedState(window)); |
277 |
|
} |
278 |
0 |
return solo; |
279 |
|
} |
280 |
|
|
281 |
|
protected boolean useCache() |
282 |
|
{ |
283 |
0 |
return this.cache != null; |
284 |
|
} |
285 |
|
|
286 |
|
public String toString() |
287 |
|
{ |
288 |
0 |
return "DecorationValve"; |
289 |
|
} |
290 |
|
|
291 |
|
public DecoratorActionsFactory getDecoratorActionsAdapter(Decoration decoration) |
292 |
|
{ |
293 |
|
|
294 |
0 |
String decoratorActionsAdapterClassName = decoration.getProperty("actions.factory"); |
295 |
0 |
if ( decoratorActionsAdapterClassName == null ) |
296 |
|
{ |
297 |
0 |
decoratorActionsAdapterClassName = defaultDecoratorActionsFactory.getClass().getName(); |
298 |
|
} |
299 |
0 |
synchronized (decoratorActionsAdapterCache) |
300 |
|
{ |
301 |
0 |
DecoratorActionsFactory adapter = (DecoratorActionsFactory)decoratorActionsAdapterCache.get(decoratorActionsAdapterClassName); |
302 |
0 |
if ( adapter == null ) |
303 |
|
{ |
304 |
|
try |
305 |
|
{ |
306 |
0 |
adapter = (DecoratorActionsFactory)Class.forName(decoratorActionsAdapterClassName).newInstance(); |
307 |
0 |
adapter.setMaximizeOnEdit(this.maxOnEdit); |
308 |
0 |
adapter.setMaximizeOnConfig(this.maxOnConfig); |
309 |
0 |
adapter.setMaximizeOnEditDefaults(this.maxOnEditDefaults); |
310 |
|
} |
311 |
0 |
catch (Exception e) |
312 |
|
{ |
313 |
0 |
log.error("Failed to instantiate custom DecoratorActionsAdaptor "+decoratorActionsAdapterClassName+", falling back to default.",e); |
314 |
0 |
adapter = (DecoratorActionsFactory)decoratorActionsAdapterCache.get(defaultDecoratorActionsFactory.getClass().getName()); |
315 |
0 |
if ( adapter == null ) |
316 |
|
{ |
317 |
0 |
adapter = defaultDecoratorActionsFactory; |
318 |
|
} |
319 |
0 |
} |
320 |
0 |
decoratorActionsAdapterCache.put(decoratorActionsAdapterClassName,adapter); |
321 |
|
} |
322 |
0 |
return adapter; |
323 |
0 |
} |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
protected boolean initActionsForFragment(RequestContext requestContext, |
337 |
|
ContentFragment fragment, |
338 |
|
PageActionAccess pageActionAccess, |
339 |
|
Decoration decoration, |
340 |
|
boolean isAjaxRequest) throws FailedToRetrievePortletWindow, PortletEntityNotStoredException |
341 |
|
{ |
342 |
0 |
boolean fragmentSupportsActions = false; |
343 |
0 |
PortletWindow window = windowAccessor.getPortletWindow(fragment); |
344 |
0 |
PortletDefinitionComposite portlet = (PortletDefinitionComposite) window.getPortletEntity().getPortletDefinition(); |
345 |
|
|
346 |
0 |
if (null == portlet) |
347 |
|
{ |
348 |
0 |
return fragmentSupportsActions; |
349 |
|
} |
350 |
|
|
351 |
0 |
List actions = Collections.EMPTY_LIST; |
352 |
|
|
353 |
0 |
PortletMode currentMode = requestContext.getPortalURL().getNavigationalState().getMode(window); |
354 |
0 |
WindowState currentState = requestContext.getPortalURL().getNavigationalState().getState(window); |
355 |
0 |
ContentTypeSet content = portlet.getContentTypeSet(); |
356 |
|
|
357 |
0 |
if ( fragment.equals(requestContext.getPage().getRootFragment()) ) |
358 |
|
{ |
359 |
0 |
fragmentSupportsActions = true; |
360 |
0 |
actions = getPageModes(requestContext, window, content, currentMode, currentState, pageActionAccess, decoration, isAjaxRequest); |
361 |
|
} |
362 |
0 |
else if ( !Fragment.LAYOUT.equals(fragment.getType()) ) |
363 |
|
{ |
364 |
0 |
fragmentSupportsActions = true; |
365 |
0 |
String fragmentId = fragment.getId(); |
366 |
0 |
PortletApplication pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition(); |
367 |
|
|
368 |
0 |
String portletName = portlet.getUniqueName(); |
369 |
|
|
370 |
0 |
PortletMode currentMappedMode = pa.getMappedPortletMode(currentMode); |
371 |
0 |
WindowState currentMappedState = pa.getMappedWindowState(currentState); |
372 |
|
|
373 |
|
Object action; |
374 |
|
PortletMode mappedMode; |
375 |
|
PortletMode customMode; |
376 |
|
WindowState mappedState; |
377 |
|
WindowState customState; |
378 |
|
|
379 |
0 |
ArrayList actionTemplates = new ArrayList(); |
380 |
|
|
381 |
0 |
DecoratorActionsFactory actionsAdapter = getDecoratorActionsAdapter(decoration); |
382 |
|
|
383 |
0 |
List supportedActions = actionsAdapter.getSupportedActions(requestContext, pa, window, currentMappedMode, currentMappedState, decoration); |
384 |
0 |
Iterator iter = supportedActions.iterator(); |
385 |
|
|
386 |
0 |
String currentModeAction = null; |
387 |
0 |
String currentStateAction = null; |
388 |
|
|
389 |
0 |
while ( iter.hasNext() ) |
390 |
|
{ |
391 |
0 |
action = iter.next(); |
392 |
0 |
if ( action instanceof PortletMode ) |
393 |
|
{ |
394 |
0 |
mappedMode = (PortletMode)action; |
395 |
0 |
customMode = pa.getCustomPortletMode(mappedMode); |
396 |
|
|
397 |
0 |
if ( customMode != null ) |
398 |
|
{ |
399 |
0 |
boolean equalsCurrentMode = customMode.equals(currentMode); |
400 |
0 |
if ( equalsCurrentMode ) |
401 |
|
{ |
402 |
0 |
currentModeAction = mappedMode.toString(); |
403 |
|
} |
404 |
0 |
if ( ! equalsCurrentMode || isAjaxRequest ) |
405 |
|
{ |
406 |
0 |
if ( (content.supportsPortletMode(customMode) || isAutoSwitchableCustomMode(content, customMode)) |
407 |
|
&& (!PortletMode.EDIT.equals(customMode) || pageActionAccess.isEditAllowed()) |
408 |
|
&& pageActionAccess.checkPortletMode(fragmentId, portletName, mappedMode) |
409 |
|
) |
410 |
|
{ |
411 |
0 |
actionTemplates.add(new DecoratorActionTemplate(mappedMode, customMode)); |
412 |
|
} |
413 |
|
} |
414 |
0 |
} |
415 |
|
} |
416 |
0 |
else if ( action instanceof WindowState ) |
417 |
|
{ |
418 |
0 |
mappedState = (WindowState)action; |
419 |
0 |
customState = pa.getCustomWindowState(mappedState); |
420 |
|
|
421 |
0 |
if ( customState != null ) |
422 |
|
{ |
423 |
0 |
boolean equalsCurrentState = customState.equals(currentState); |
424 |
0 |
if ( equalsCurrentState ) |
425 |
|
{ |
426 |
0 |
currentStateAction = mappedState.toString(); |
427 |
|
} |
428 |
0 |
if ( ! equalsCurrentState || isAjaxRequest ) |
429 |
|
{ |
430 |
0 |
if ( pageActionAccess.checkWindowState(fragmentId, portletName, mappedState ) ) |
431 |
|
{ |
432 |
0 |
actionTemplates.add(new DecoratorActionTemplate(mappedState, customState)); |
433 |
|
} |
434 |
|
} |
435 |
0 |
} |
436 |
|
} |
437 |
|
} |
438 |
0 |
actions = actionsAdapter.getDecoratorActions(requestContext, pa, window, currentMode, currentState, decoration, actionTemplates,portlet,fragment,accessController); |
439 |
|
|
440 |
0 |
decoration.setCurrentModeAction( currentModeAction ); |
441 |
0 |
decoration.setCurrentStateAction( currentStateAction ); |
442 |
|
} |
443 |
|
|
444 |
0 |
decoration.setActions( actions ); |
445 |
|
|
446 |
0 |
return fragmentSupportsActions; |
447 |
|
} |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
protected List getPageModes(RequestContext requestContext, PortletWindow window, ContentTypeSet content, |
464 |
|
PortletMode mode, WindowState state, PageActionAccess pageActionAccess, Decoration decoration, |
465 |
|
boolean isAjaxRequest) |
466 |
|
{ |
467 |
0 |
List pageModes = new ArrayList(); |
468 |
|
|
469 |
|
|
470 |
|
try |
471 |
|
{ |
472 |
0 |
if (mode.equals(PortletMode.HELP) || !state.equals(WindowState.NORMAL)) |
473 |
|
{ |
474 |
|
|
475 |
0 |
PortalURL portalURL = requestContext.getPortalURL(); |
476 |
0 |
String action = requestContext.getResponse().encodeURL( (isAjaxRequest) |
477 |
|
? portalURL.createNavigationalEncoding(window, PortletMode.VIEW, WindowState.NORMAL) |
478 |
|
: portalURL.createPortletURL(window, PortletMode.VIEW, WindowState.NORMAL, portalURL.isSecure()).toString() ); |
479 |
0 |
String actionName = PortletMode.VIEW.toString(); |
480 |
0 |
pageModes.add(new DecoratorAction(actionName, requestContext.getLocale(), decoration.getResource("images/" + actionName + ".gif"),action,DecoratorActionTemplate.ACTION_TYPE_MODE)); |
481 |
0 |
} |
482 |
0 |
else if ( pageActionAccess.isEditAllowed() ) |
483 |
|
{ |
484 |
0 |
String targetMode = pageActionAccess.isEditing() ? PortletMode.VIEW.toString() : PortletMode.EDIT.toString(); |
485 |
0 |
PortalURL portalURL = requestContext.getPortalURL(); |
486 |
0 |
HashMap parameters = new HashMap(); |
487 |
0 |
String[] paramValues = new String[]{targetMode}; |
488 |
0 |
parameters.put("pageMode",paramValues); |
489 |
|
|
490 |
|
|
491 |
0 |
String action = requestContext.getResponse().encodeURL( (isAjaxRequest) |
492 |
|
? portalURL.createNavigationalEncoding(window, parameters, PortletMode.VIEW, WindowState.NORMAL, true) |
493 |
|
: portalURL.createPortletURL(window, parameters, PortletMode.VIEW, WindowState.NORMAL, true, portalURL.isSecure()).toString() ); |
494 |
0 |
pageModes.add(new DecoratorAction(targetMode, requestContext.getLocale(), decoration.getResource("images/" + targetMode + ".gif"), action,DecoratorActionTemplate.ACTION_TYPE_MODE)); |
495 |
|
|
496 |
|
|
497 |
|
|
498 |
0 |
if (content.supportsPortletMode(PortletMode.HELP)) |
499 |
|
{ |
500 |
0 |
if ( pageActionAccess.isEditing() ) |
501 |
|
{ |
502 |
|
|
503 |
0 |
paramValues[0] = PortletMode.VIEW.toString(); |
504 |
0 |
action = requestContext.getResponse().encodeURL( (isAjaxRequest) |
505 |
|
? portalURL.createNavigationalEncoding(window, parameters, PortletMode.HELP, WindowState.MAXIMIZED, true) |
506 |
|
: portalURL.createPortletURL(window, parameters, PortletMode.HELP, WindowState.MAXIMIZED, true, portalURL.isSecure()).toString() ); |
507 |
|
} |
508 |
|
else |
509 |
|
{ |
510 |
|
|
511 |
0 |
action = requestContext.getResponse().encodeURL( (isAjaxRequest) |
512 |
|
? portalURL.createNavigationalEncoding(window, PortletMode.HELP, WindowState.MAXIMIZED) |
513 |
|
: portalURL.createPortletURL(window,PortletMode.HELP, WindowState.MAXIMIZED, portalURL.isSecure()).toString() ); |
514 |
|
} |
515 |
0 |
String actionName = PortletMode.HELP.toString(); |
516 |
0 |
pageModes.add(new DecoratorAction(actionName, requestContext.getLocale(), decoration.getResource("images/" + actionName + ".gif"), action,DecoratorActionTemplate.ACTION_TYPE_MODE)); |
517 |
|
} |
518 |
|
} |
519 |
|
} |
520 |
0 |
catch (Exception e) |
521 |
|
{ |
522 |
0 |
log.warn("Unable to initalize PageLayout actions", e); |
523 |
0 |
pageModes = null; |
524 |
0 |
} |
525 |
|
|
526 |
0 |
return pageModes; |
527 |
|
} |
528 |
|
|
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
|
534 |
|
|
535 |
|
|
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
protected void initDepthFragments(RequestContext requestContext, |
540 |
|
Theme theme, |
541 |
|
ContentFragment fragment, |
542 |
|
PageActionAccess pageActionAccess, |
543 |
|
boolean isAjaxRequest, |
544 |
|
List collectFragments ) |
545 |
|
{ |
546 |
0 |
final List contentFragments = fragment.getContentFragments(); |
547 |
|
|
548 |
0 |
if(contentFragments != null && contentFragments.size() > 0) |
549 |
|
{ |
550 |
0 |
Iterator itr = contentFragments.iterator(); |
551 |
0 |
while(itr.hasNext()) |
552 |
|
{ |
553 |
0 |
ContentFragment aFragment = (ContentFragment) itr.next(); |
554 |
0 |
initDepthFragments(requestContext, theme, aFragment, pageActionAccess, isAjaxRequest, collectFragments); |
555 |
0 |
} |
556 |
|
} |
557 |
|
|
558 |
0 |
if ( initFragment(requestContext, theme, fragment, pageActionAccess, isAjaxRequest) ) |
559 |
|
{ |
560 |
0 |
if ( collectFragments != null ) |
561 |
|
{ |
562 |
0 |
collectFragments.add( fragment ); |
563 |
|
} |
564 |
|
} |
565 |
0 |
} |
566 |
|
|
567 |
|
protected boolean initFragment(RequestContext requestContext, |
568 |
|
Theme theme, |
569 |
|
ContentFragment fragment, |
570 |
|
PageActionAccess pageActionAccess, |
571 |
|
boolean isAjaxRequest) |
572 |
|
{ |
573 |
0 |
boolean fragmentSupportsActions = false; |
574 |
|
try |
575 |
|
{ |
576 |
0 |
Decoration decoration = theme.getDecoration(fragment); |
577 |
0 |
fragment.setDecoration(decoration); |
578 |
0 |
fragmentSupportsActions = initActionsForFragment(requestContext, fragment, pageActionAccess, decoration, isAjaxRequest); |
579 |
|
} |
580 |
0 |
catch (Exception e) |
581 |
|
{ |
582 |
0 |
log.warn("Unable to initalize actions for fragment "+fragment.getId(), e); |
583 |
0 |
} |
584 |
0 |
return fragmentSupportsActions; |
585 |
|
} |
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
|
599 |
|
protected void initDepthFragmentDecorations(RequestContext requestContext, |
600 |
|
Theme theme, |
601 |
|
ContentFragment fragment, |
602 |
|
PageActionAccess pageActionAccess, |
603 |
|
boolean isAjaxRequest, |
604 |
|
ResourceValidator validator, |
605 |
|
PathResolverCache pathResolverCache, |
606 |
|
boolean reloadActionList) |
607 |
|
{ |
608 |
0 |
final List contentFragments = fragment.getContentFragments(); |
609 |
|
|
610 |
0 |
if(contentFragments != null && contentFragments.size() > 0) |
611 |
|
{ |
612 |
0 |
Iterator itr = contentFragments.iterator(); |
613 |
0 |
while(itr.hasNext()) |
614 |
|
{ |
615 |
0 |
ContentFragment aFragment = (ContentFragment) itr.next(); |
616 |
0 |
initDepthFragmentDecorations(requestContext, theme, aFragment, |
617 |
|
pageActionAccess, isAjaxRequest, |
618 |
|
validator, pathResolverCache, reloadActionList); |
619 |
0 |
} |
620 |
|
} |
621 |
|
|
622 |
|
try |
623 |
|
{ |
624 |
|
|
625 |
0 |
Decoration decoration = theme.getDecoration(fragment); |
626 |
|
|
627 |
0 |
Properties config = ((DecorationFactoryImpl) decorationFactory).getConfiguration(decoration.getName(), fragment.getType()); |
628 |
0 |
((BaseDecoration) decoration).init(config, validator, pathResolverCache); |
629 |
|
|
630 |
0 |
fragment.setDecoration(decoration); |
631 |
|
|
632 |
0 |
if (reloadActionList) |
633 |
|
{ |
634 |
0 |
initActionsForFragment(requestContext, fragment, pageActionAccess, decoration, isAjaxRequest); |
635 |
|
} |
636 |
|
} |
637 |
0 |
catch (Exception e) |
638 |
|
{ |
639 |
0 |
log.warn("Unable to initalize actions for fragment "+fragment.getId(), e); |
640 |
0 |
} |
641 |
0 |
} |
642 |
|
|
643 |
|
public void setMaximizeOnEdit(boolean maxOnEdit) |
644 |
|
{ |
645 |
0 |
this.maxOnEdit = maxOnEdit; |
646 |
0 |
this.defaultDecoratorActionsFactory.setMaximizeOnEdit(maxOnEdit); |
647 |
0 |
} |
648 |
|
|
649 |
|
public boolean getMaximizeOnEdit() |
650 |
|
{ |
651 |
0 |
return this.maxOnEdit; |
652 |
|
} |
653 |
|
|
654 |
|
public void setMaximizeOnConfig(boolean maxOnConfig) |
655 |
|
{ |
656 |
0 |
this.maxOnConfig = maxOnConfig; |
657 |
0 |
this.defaultDecoratorActionsFactory.setMaximizeOnConfig(maxOnConfig); |
658 |
0 |
} |
659 |
|
|
660 |
|
public boolean getMaximizeOnConfig() |
661 |
|
{ |
662 |
0 |
return this.maxOnConfig; |
663 |
|
} |
664 |
|
|
665 |
|
public void setMaximizeOnEditDefaults(boolean maxOnEditDefaults) |
666 |
|
{ |
667 |
0 |
this.maxOnEditDefaults = maxOnEditDefaults; |
668 |
0 |
this.defaultDecoratorActionsFactory.setMaximizeOnEditDefaults(maxOnEditDefaults); |
669 |
0 |
} |
670 |
|
|
671 |
|
public boolean getMaximizeOnEditDefaults() |
672 |
|
{ |
673 |
0 |
return this.maxOnEditDefaults; |
674 |
|
} |
675 |
|
|
676 |
|
public void setAutoSwitchingToEditDefaultsModes(boolean autoSwitchingToEditDefaultsModes) |
677 |
|
{ |
678 |
0 |
this.autoSwitchingToEditDefaultsModes = autoSwitchingToEditDefaultsModes; |
679 |
0 |
} |
680 |
|
|
681 |
|
public boolean getAutoSwitchingToEditDefaultsModes() |
682 |
|
{ |
683 |
0 |
return this.autoSwitchingToEditDefaultsModes; |
684 |
|
} |
685 |
|
|
686 |
|
public void setAutoSwitchingForConfigMode(boolean autoSwitchingForConfigMode) |
687 |
|
{ |
688 |
0 |
this.autoSwitchingForConfigMode = autoSwitchingForConfigMode; |
689 |
0 |
} |
690 |
|
|
691 |
|
public boolean getAutoSwitchingForConfigMode() |
692 |
|
{ |
693 |
0 |
return this.autoSwitchingForConfigMode; |
694 |
|
} |
695 |
|
|
696 |
|
private boolean isAutoSwitchableCustomMode(ContentTypeSet content, PortletMode customMode) |
697 |
|
{ |
698 |
0 |
if (this.autoSwitchingForConfigMode && JetspeedActions.CONFIG_MODE.equals(customMode)) |
699 |
|
{ |
700 |
0 |
return true; |
701 |
|
} |
702 |
|
|
703 |
0 |
if (this.autoSwitchingToEditDefaultsModes) |
704 |
|
{ |
705 |
0 |
if (content.supportsPortletMode(PortletMode.EDIT) && JetspeedActions.EDIT_DEFAULTS_MODE.equals(customMode)) |
706 |
|
{ |
707 |
0 |
return true; |
708 |
|
} |
709 |
|
} |
710 |
|
|
711 |
0 |
return false; |
712 |
|
} |
713 |
|
} |