Coverage report

  %line %branch
org.apache.jetspeed.decoration.DecorationValve
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 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  
  * Assigns decorations and page actions to all of the portlet Fragments within
 58  
  * the current request. 
 59  
  * 
 60  
  * @see org.apache.jetspeed.om.page.Fragment 
 61  
  * @see org.apache.jetspeed.om.page.Page
 62  
  * @see org.apache.jetspeed.decoration.Decoration
 63  
  * @see org.apache.jetspeed.decoration.LayoutDecoration
 64  
  * @see org.apache.jetspeed.decoration.PortletDecoration
 65  
  * @see org.apache.jetspeed.decoration.Theme
 66  
  * 
 67  
  * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
 68  
  * @author <href a="mailto:firevelocity@gmail.com">Vivek Kumar</a>
 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  
      * When edit_defaults mode is not supported by a portlet, support the mode automatically.
 98  
      */
 99  0
     private boolean autoSwitchingForConfigMode = false;
 100  
 
 101  
     /**
 102  
      * When edit_defaults mode is not supported by a portlet, support the mode automatically.
 103  
      */
 104  0
     private boolean autoSwitchingToEditDefaultsModes = true;
 105  
          
 106  
      /**
 107  
       * For security constraint checks
 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  
         //added the accessController in portlet decorater for checking the actions
 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  
         //long start = System.currentTimeMillis();
 138  0
         boolean isAjaxRequest = (context == null);        
 139  0
         initFragments( requestContext, isAjaxRequest, null );        
 140  
         //long end = System.currentTimeMillis();
 141  
         //System.out.println(end - start);
 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  
         // Globaly override all psml themes if override session attribute has been set
 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  
                 // user helps us with the funky way jetspeed doesn't create  a new session on login
 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  
         // FIXME: why always get this property
 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  
      * Builds and assigns a list of available portlet modes and window states for
 328  
      * the target <code>Fragment</code>.
 329  
      * 
 330  
      * @param requestContext RequestContext of the current portal request.
 331  
      * @param fragment Fragment to initialize modes and states for.
 332  
      * @return
 333  
      * @throws PortletEntityNotStoredException 
 334  
      * @throws FailedToRetrievePortletWindow 
 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; // allow nothing
 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  
      * Builds a list of portlet modes that can be executed on the current
 451  
      * <code>fragment</code> excluding the portlet's current mode.
 452  
      * 
 453  
      * @param requestContext RequestContext of the current portal request.
 454  
      * @param pageActionAccess
 455  
      * @param mode
 456  
      * @param content
 457  
      * @param portletName
 458  
      * @param window
 459  
      * @param fragment
 460  
      * @return <code>java.util.List</code> of modes excluding the current one.
 461  
      * @throws PortletEntityNotStoredException 
 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  
                 // switch back to VIEW mode and NORMAL state.
 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  
                 // Use an ActionURL to set the oposite pageMode and always set VIEW mode and state NORMAL 
 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  
                 //window.getPortletEntity().getPortletDefinition().getInitParameterSet().get( "xxxx" );
 497  
                 
 498  0
                 if (content.supportsPortletMode(PortletMode.HELP))
 499  
                 {
 500  0
                     if ( pageActionAccess.isEditing() )
 501  
                     {
 502  
                         // force it back to VIEW mode first with an ActionURL, as well as setting HELP mode and MAXIMIZED state
 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  
                         // switch to mode HELP and state MAXIMIZED
 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  
      * Intializes all fragments with there decorations and portlet modes 
 531  
      * and winodw states.
 532  
      * 
 533  
      * 
 534  
      * @param requestContext RequestContext of the current portal request.
 535  
      * @param theme
 536  
      * @param fragment
 537  
      * @param pageActionAccess
 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  
      * Reintializes all fragments with there decorations and portlet modes 
 589  
      * and winodw states after theme is restored from cache.
 590  
      * 
 591  
      * @param requestContext RequestContext of the current portal request.
 592  
      * @param theme
 593  
      * @param fragment
 594  
      * @param pageActionAccess
 595  
      * @param isAjaxRequest
 596  
      * @param validator
 597  
      * @param pathResolverCache
 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  
             // PageTheme::getDecoration retrieves cached decoration only.
 625  0
             Decoration decoration = theme.getDecoration(fragment);
 626  
             // re-init to set transient memebers.
 627  0
             Properties config = ((DecorationFactoryImpl) decorationFactory).getConfiguration(decoration.getName(), fragment.getType());
 628  0
             ((BaseDecoration) decoration).init(config, validator, pathResolverCache);
 629  
             // fragment is newly created on every request, so reset decoration for fragment.
 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  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.