Coverage report

  %line %branch
org.apache.jetspeed.decoration.CustomDecoratorActionsFactory
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.List;
 22  
 
 23  
 import javax.portlet.PortletMode;
 24  
 import javax.portlet.WindowState;
 25  
 
 26  
 import org.apache.jetspeed.JetspeedActions;
 27  
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
 28  
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 29  
 import org.apache.jetspeed.om.page.ContentPage;
 30  
 import org.apache.jetspeed.om.page.ContentFragment;
 31  
 import org.apache.jetspeed.request.RequestContext;
 32  
 import org.apache.jetspeed.security.SecurityAccessController;
 33  
 import org.apache.pluto.om.window.PortletWindow;
 34  
 
 35  
 public class CustomDecoratorActionsFactory extends AbstractDecoratorActionsFactory
 36  
 {
 37  0
     private static final DecoratorActionTemplate ABOUT_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.ABOUT_MODE);
 38  0
     private static final DecoratorActionTemplate CONFIG_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.CONFIG_MODE);
 39  0
     private static final DecoratorActionTemplate EDIT_DEFAULTS_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.EDIT_DEFAULTS_MODE);
 40  
     //private static final DecoratorActionTemplate PREVIEW_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.PREVIEW_MODE);
 41  0
     private static final DecoratorActionTemplate PRINT_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.PRINT_MODE);
 42  0
     private static final DecoratorActionTemplate SOLO_ACTION_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.SOLO_STATE);
 43  
     
 44  
     private final List supportedActions;
 45  
     private final List supportedSoloActions;
 46  
     
 47  
     public CustomDecoratorActionsFactory()
 48  0
     {
 49  0
         ArrayList list = new ArrayList(JetspeedActions.getStandardPortletModes());
 50  0
         list.add(JetspeedActions.ABOUT_MODE);
 51  0
         list.add(JetspeedActions.CONFIG_MODE);
 52  0
         list.add(JetspeedActions.EDIT_DEFAULTS_MODE);
 53  
         //list.add(JetspeedActions.PREVIEW_MODE);
 54  0
         list.add(JetspeedActions.PRINT_MODE);
 55  0
         list.addAll(JetspeedActions.getStandardWindowStates());
 56  0
         list.add(JetspeedActions.SOLO_STATE);
 57  0
         supportedActions = Collections.unmodifiableList(list);
 58  
         
 59  0
         list = new ArrayList(JetspeedActions.getStandardPortletModes());
 60  0
         list.add(JetspeedActions.PRINT_MODE);
 61  0
         supportedSoloActions = Collections.unmodifiableList(list);
 62  0
     }
 63  
 
 64  
     public List getSupportedActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode cm,
 65  
                     WindowState ws, Decoration decoration)
 66  
     {
 67  
         // don't support any window state actions when in "solo" state
 68  0
         return JetspeedActions.SOLO_STATE.equals(ws) ? supportedSoloActions : supportedActions;
 69  
     }
 70  
     
 71  
     public List getDecoratorActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode pm,
 72  
                     WindowState ws, Decoration decoration, List actionTemplates, 
 73  
                     PortletDefinitionComposite portlet, ContentFragment fragment, SecurityAccessController accessController)
 74  
     {
 75  0
         int prclass="keyword">intModeIndex = actionTemplates.indexOf(PRINT_MODE_TEMPLATE);
 76  0
         int soloStateIndex = actionTemplates.indexOf(SOLO_ACTION_TEMPLATE);
 77  
         
 78  0
         if ( printModeIndex != -1 && soloStateIndex != -1 )
 79  
         {
 80  
             // merge "solo" state with "print" mode
 81  0
             DecoratorActionTemplate soloStateTemplate = (DecoratorActionTemplate)actionTemplates.remove(soloStateIndex);
 82  0
             DecoratorActionTemplate printActionTemplate = (DecoratorActionTemplate)actionTemplates.get(printModeIndex);
 83  0
             printActionTemplate.setState(soloStateTemplate.getState());
 84  0
             printActionTemplate.setCustomState((soloStateTemplate.getCustomState()));
 85  0
         }
 86  0
         else if ( soloStateIndex != -1 )
 87  
         {
 88  
             // don't provide "solo" action separately without "print" mode
 89  0
             actionTemplates.remove(soloStateIndex);
 90  
         }
 91  
         // else if (printModeIndex != -1)
 92  
         //   support switching to different modes once in "solo" state, even back to "print"
 93  
         
 94  0
         int configModeIndex = actionTemplates.indexOf(CONFIG_MODE_TEMPLATE);
 95  0
         if (configModeIndex != -1)
 96  
         {
 97  
             try
 98  
             {
 99  0
                 ContentPage page = rc.getPage();
 100  0
                 page.checkAccess(JetspeedActions.CONFIG);
 101  
             }
 102  0
             catch (SecurityException e)
 103  
             {
 104  0
                 actionTemplates.remove(configModeIndex);
 105  0
             }
 106  
         }
 107  
         
 108  0
         int editDefaultsModeIndex = actionTemplates.indexOf(EDIT_DEFAULTS_MODE_TEMPLATE);
 109  0
         if (editDefaultsModeIndex != -1)
 110  
         {
 111  
             try
 112  
             {
 113  0
                 ContentPage page = rc.getPage();
 114  0
                 page.checkAccess(JetspeedActions.EDIT_DEFAULTS);
 115  
             }
 116  0
             catch (SecurityException e)
 117  
             {
 118  0
                 actionTemplates.remove(editDefaultsModeIndex);
 119  0
             }
 120  
         }
 121  
         
 122  0
         return super.getDecoratorActions(rc,pa,pw,pm,ws,decoration,actionTemplates, portlet,  fragment, accessController);
 123  
     }
 124  
     
 125  
     protected DecoratorAction createAction(RequestContext rc, PortletWindow pw, Decoration decoration,
 126  
                     DecoratorActionTemplate template)
 127  
     {
 128  0
         DecoratorAction action = super.createAction(rc,pw,decoration,template);
 129  0
         if ( template.getState() != null && JetspeedActions.SOLO_STATE.equals(template.getState()))
 130  
         {
 131  
             // "solo" opens in a new popup winodw
 132  0
             action.setTarget("_blank");
 133  
         }
 134  0
         return action;
 135  
     }
 136  
 }

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