Coverage report

  %line %branch
org.apache.jetspeed.container.state.impl.AbstractNavigationalState
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.container.state.impl;
 18  
 
 19  
 import java.io.UnsupportedEncodingException;
 20  
 import java.util.Collections;
 21  
 import java.util.Iterator;
 22  
 import java.util.Map;
 23  
 
 24  
 import javax.portlet.PortletMode;
 25  
 import javax.portlet.WindowState;
 26  
 
 27  
 import org.apache.jetspeed.JetspeedActions;
 28  
 import org.apache.jetspeed.cache.JetspeedContentCache;
 29  
 import org.apache.jetspeed.container.state.MutableNavigationalState;
 30  
 import org.apache.jetspeed.om.common.portlet.PortletApplication;
 31  
 import org.apache.pluto.om.window.PortletWindow;
 32  
 
 33  
 /**
 34  
  * BaseNavigationalState
 35  
  *
 36  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
 37  
  * @version $Id: AbstractNavigationalState.java 554926 2007-07-10 13:12:26Z ate $
 38  
  */
 39  
 public abstract class AbstractNavigationalState implements MutableNavigationalState
 40  
 {
 41  
     private NavigationalStateCodec codec;
 42  
     private PortletWindowRequestNavigationalStates requestStates;
 43  
     protected JetspeedContentCache cache;
 44  
     protected JetspeedContentCache decorationCache;
 45  
     
 46  
     public AbstractNavigationalState(NavigationalStateCodec codec, JetspeedContentCache cache)
 47  
     {
 48  0
         this(codec, cache, null);
 49  0
     }
 50  
 
 51  
     public AbstractNavigationalState(NavigationalStateCodec codec, JetspeedContentCache cache, JetspeedContentCache decorationCache)
 52  0
     {
 53  0
         this.codec = codec;
 54  0
         this.cache = cache;
 55  0
         this.decorationCache = decorationCache;
 56  0
     }
 57  
     
 58  
     public void init(String encodedState, String characterEncoding)
 59  
     throws UnsupportedEncodingException
 60  
     {
 61  0
         if ( requestStates == null )
 62  
         {
 63  0
             requestStates = codec.decode(encodedState, characterEncoding);
 64  
         }
 65  0
     }
 66  
     
 67  
     protected PortletWindowRequestNavigationalStates getPortletWindowRequestNavigationalStates()
 68  
     {
 69  0
         return requestStates;
 70  
     }
 71  
     
 72  
     public void setState(PortletWindow window, WindowState windowState)
 73  
     {
 74  0
         if ( windowState != null )
 75  
         {
 76  0
             if (!JetspeedActions.getStandardWindowStates().contains(windowState))
 77  
             {
 78  0
                 PortletApplication pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 79  0
                 windowState = pa.getMappedWindowState(windowState);
 80  
             }
 81  0
             String windowId = window.getId().toString();
 82  0
             PortletWindowRequestNavigationalState state = requestStates.getPortletWindowNavigationalState(windowId);
 83  0
             if (state != null && (state.getWindowState() == class="keyword">null || !state.getWindowState().equals(windowState)))
 84  
             {
 85  0
                 state.setWindowState(windowState);
 86  
             }
 87  
             else
 88  
             {
 89  0
                 state = new PortletWindowRequestNavigationalState(windowId);
 90  0
                 requestStates.addPortletWindowNavigationalState(windowId, state);
 91  0
                 state.setWindowState(windowState);
 92  
             }
 93  0
             if (windowState.equals(WindowState.MAXIMIZED))
 94  
             {
 95  0
                 requestStates.setMaximizedWindow(window);
 96  
             }
 97  
         }
 98  0
     }
 99  
 
 100  
     public void setMode(PortletWindow window, PortletMode portletMode)
 101  
     {
 102  0
         if ( portletMode != null )
 103  
         {
 104  0
             if (!JetspeedActions.getStandardPortletModes().contains(portletMode))
 105  
             {
 106  0
                 PortletApplication pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 107  0
                 portletMode = pa.getMappedPortletMode(portletMode);
 108  
             }
 109  0
             String windowId = window.getId().toString();
 110  0
             PortletWindowRequestNavigationalState state = requestStates.getPortletWindowNavigationalState(windowId);
 111  0
             if (state != null && (state.getPortletMode() == class="keyword">null || !state.getPortletMode().equals(portletMode)))
 112  
             {
 113  0
                 state.setPortletMode(portletMode);
 114  
             }
 115  
             else
 116  
             {
 117  0
                 state = new PortletWindowRequestNavigationalState(windowId);
 118  0
                 requestStates.addPortletWindowNavigationalState(windowId, state);
 119  0
                 state.setPortletMode(portletMode);
 120  
             }
 121  
         }
 122  0
     }
 123  
 
 124  
     public WindowState getMappedState(String windowId)
 125  
     {
 126  0
         WindowState windowState = null;
 127  0
         PortletWindowRequestNavigationalState state = requestStates.getPortletWindowNavigationalState(windowId);
 128  0
         if (state != null)
 129  
         {
 130  0
             windowState = state.getWindowState();
 131  
         }
 132  0
         return windowState != null ? windowState : WindowState.NORMAL;
 133  
     }
 134  
 
 135  
     /**
 136  
      * @deprecated
 137  
      */
 138  
     public WindowState getState(String windowId)
 139  
     {
 140  0
         return getMappedState(windowId);
 141  
     }
 142  
 
 143  
     public WindowState getState(PortletWindow window)
 144  
     {
 145  0
         WindowState state = getMappedState(window.getId().toString());
 146  0
         if (state != null && !JetspeedActions.getStandardWindowStates().contains(state))
 147  
         {
 148  0
             PortletApplication pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 149  0
             state = pa.getCustomWindowState(state);
 150  
         }
 151  0
         return state;
 152  
     }
 153  
 
 154  
     public WindowState getMappedState(PortletWindow window)
 155  
     {
 156  0
         return getMappedState(window.getId().toString());
 157  
     }
 158  
 
 159  
     public PortletMode getMappedMode(String windowId)
 160  
     {
 161  0
         PortletMode portletMode = null;
 162  0
         PortletWindowRequestNavigationalState state = requestStates.getPortletWindowNavigationalState(windowId);
 163  0
         if (state != null)
 164  
         {
 165  0
             portletMode = state.getPortletMode();
 166  
         }
 167  0
         return portletMode != null ? portletMode : PortletMode.VIEW;
 168  
     }
 169  
     
 170  
     /**
 171  
      * @deprecated
 172  
      */
 173  
     public PortletMode getMode(String windowId)
 174  
     {
 175  0
         return getMappedMode(windowId);
 176  
     }
 177  
     
 178  
     public PortletMode getMode(PortletWindow window)
 179  
     {
 180  0
         PortletMode mode = getMappedMode(window.getId().toString());
 181  0
         if (mode != null && !JetspeedActions.getStandardPortletModes().contains(mode))
 182  
         {
 183  0
             PortletApplication pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 184  0
             mode = pa.getCustomPortletMode(mode);
 185  
         }
 186  0
         return mode;
 187  
     }
 188  
 
 189  
     public PortletMode getMappedMode(PortletWindow window)
 190  
     {
 191  0
         return getMappedMode(window.getId().toString());
 192  
     }
 193  
 
 194  
     public PortletWindow getMaximizedWindow()
 195  
     {
 196  0
         return requestStates.getMaximizedWindow();
 197  
     }
 198  
 
 199  
     public Iterator getParameterNames(PortletWindow window)
 200  
     {
 201  0
         PortletWindowRequestNavigationalState state = requestStates.getPortletWindowNavigationalState(window.getId().toString());
 202  0
         if ( state != null && state.getParametersMap() != class="keyword">null )
 203  
         {
 204  0
             return state.getParametersMap().keySet().iterator();
 205  
         }
 206  
         else
 207  
         {
 208  0
             return Collections.EMPTY_LIST.iterator();
 209  
         }
 210  
     }
 211  
 
 212  
     public String[] getParameterValues(PortletWindow window, String parameterName)
 213  
     {
 214  0
         PortletWindowRequestNavigationalState state = requestStates.getPortletWindowNavigationalState(window.getId().toString());
 215  0
         if ( state != null && state.getParametersMap() != class="keyword">null )
 216  
         {
 217  0
             return (String[])state.getParametersMap().get(parameterName);
 218  
         }
 219  
         else
 220  
         {
 221  0
             return null;
 222  
         }
 223  
     }
 224  
 
 225  
     public PortletWindow getPortletWindowOfAction()
 226  
     {
 227  0
         return requestStates.getActionWindow();
 228  
     }
 229  
     
 230  
     public PortletWindow getPortletWindowOfResource()
 231  
     {
 232  0
         return requestStates.getResourceWindow();
 233  
     }
 234  
 
 235  
     public String encode(PortletWindow window, Map parameters, PortletMode mode, WindowState state, boolean action)
 236  
     throws UnsupportedEncodingException
 237  
     {
 238  0
         if ( mode != null || state != class="keyword">null )
 239  
         {
 240  0
             PortletApplication pa = null;
 241  0
             if (mode != null && !JetspeedActions.getStandardPortletModes().contains(mode))
 242  
             {
 243  0
                 pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 244  0
                 mode = pa.getMappedPortletMode(mode);
 245  
             }
 246  0
             if (state != null && !JetspeedActions.getStandardWindowStates().contains(state))
 247  
             {
 248  0
                 if ( pa == null )
 249  
                 {
 250  0
                     pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 251  
                 }
 252  0
                 state = pa.getMappedWindowState(state);
 253  
             }
 254  
         }
 255  0
         return codec.encode(requestStates, window, parameters, mode, state, action, isNavigationalParameterStateFull(),
 256  
                 isRenderParameterStateFull());
 257  
     }
 258  
 
 259  
     public String encode(PortletWindow window, PortletMode mode, WindowState state)
 260  
     throws UnsupportedEncodingException
 261  
     {
 262  0
         if ( mode != null || state != class="keyword">null )
 263  
         {
 264  0
             PortletApplication pa = null;
 265  0
             if (mode != null && !JetspeedActions.getStandardPortletModes().contains(mode))
 266  
             {
 267  0
                 pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 268  0
                 mode = pa.getMappedPortletMode(mode);
 269  
             }
 270  0
             if (state != null && !JetspeedActions.getStandardWindowStates().contains(state))
 271  
             {
 272  0
                 if ( pa == null )
 273  
                 {
 274  0
                     pa = (PortletApplication)window.getPortletEntity().getPortletDefinition().getPortletApplicationDefinition();
 275  
                 }
 276  0
                 state = pa.getMappedWindowState(state);
 277  
             }
 278  
         }
 279  0
         String encodedState = null;
 280  0
         Map currentWindowStates = null;
 281  0
         PortletWindowExtendedNavigationalState windowNavState = null;
 282  0
         PortletMode targetMode = mode;
 283  0
         WindowState targetState = state;
 284  0
         if (this instanceof SessionNavigationalState)
 285  
         {
 286  0
             currentWindowStates = ((SessionNavigationalState)this).getCurrentPageWindowStates();
 287  0
             if (currentWindowStates != null)
 288  
             {
 289  0
                 windowNavState = (PortletWindowExtendedNavigationalState)currentWindowStates.get(window.getId().toString());
 290  0
                 if (windowNavState != null)
 291  
                 {
 292  0
                     if (targetMode == null)
 293  
                     {
 294  0
                         targetMode = windowNavState.getPortletMode();
 295  
                     }
 296  0
                     if (targetState == null)
 297  
                     {
 298  0
                         targetState = windowNavState.getWindowState();
 299  
                     }
 300  0
                    encodedState = windowNavState.getDecoratorActionEncoding(targetMode, targetState);
 301  
                 }
 302  
             }
 303  
         }
 304  0
         if (encodedState == null)
 305  
         {
 306  0
             encodedState = codec.encode(requestStates, window, mode, state, isNavigationalParameterStateFull(), isRenderParameterStateFull());
 307  0
             if (currentWindowStates != null)
 308  
             {
 309  0
                 if (windowNavState == null)
 310  
                 {
 311  0
                     windowNavState = new PortletWindowExtendedNavigationalState();
 312  0
                     currentWindowStates.put(window.getId().toString(), windowNavState);
 313  
                 }
 314  0
                 windowNavState.setDecoratorActionEncoding(targetMode, targetState, encodedState);
 315  
             }
 316  
         }
 317  0
         return encodedState;
 318  
     }
 319  
     
 320  
     public String encode() throws UnsupportedEncodingException
 321  
     {
 322  0
         return codec.encode(requestStates, isNavigationalParameterStateFull(), isRenderParameterStateFull());
 323  
     }
 324  
 
 325  
     public Iterator getWindowIdIterator()
 326  
     {
 327  0
         return requestStates.getWindowIdIterator();
 328  
     }
 329  
     
 330  
     public void clearParameters(PortletWindow window)
 331  
     {
 332  0
         PortletWindowRequestNavigationalState state = requestStates.getPortletWindowNavigationalState(window.getId().toString());
 333  0
         if (state != null)
 334  
         {
 335  0
             Map map = state.getParametersMap();
 336  0
             if (map != null)
 337  
             {
 338  0
                 map.clear();
 339  0
                 state.setClearParameters(true);
 340  
             }
 341  
         }
 342  0
     }
 343  
     
 344  
     public void removeState(PortletWindow window)
 345  
     {
 346  0
         requestStates.removePortletWindowNavigationalState(window.getId().toString());
 347  0
     }
 348  
 }

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