View Javadoc

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.ContentFragment;
30  import org.apache.jetspeed.request.RequestContext;
31  import org.apache.jetspeed.security.SecurityAccessController;
32  import org.apache.pluto.om.window.PortletWindow;
33  
34  public class PrintSoloDecoratorActionsFactory extends AbstractDecoratorActionsFactory
35  {
36      private static final DecoratorActionTemplate PRINT_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.PRINT_MODE);
37      private static final DecoratorActionTemplate SOLO_ACTION_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.SOLO_STATE);
38      
39      private final List supportedActions;
40      private final List supportedSoloActions;
41      
42      public PrintSoloDecoratorActionsFactory()
43      {
44          ArrayList list = new ArrayList(JetspeedActions.getStandardPortletModes());
45          list.add(JetspeedActions.PRINT_MODE);
46          list.addAll(JetspeedActions.getStandardWindowStates());
47          list.add(JetspeedActions.SOLO_STATE);
48          supportedActions = Collections.unmodifiableList(list);
49          list = new ArrayList(JetspeedActions.getStandardPortletModes());
50          list.add(JetspeedActions.PRINT_MODE);
51          supportedSoloActions = Collections.unmodifiableList(list);
52      }
53  
54      public List getSupportedActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode cm,
55                      WindowState ws, Decoration decoration)
56      {
57          // don't support any window state actions when in "solo" state
58          return JetspeedActions.SOLO_STATE.equals(ws) ? supportedSoloActions : supportedActions;
59      }
60      
61      public List getDecoratorActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode pm,
62                      WindowState ws, Decoration decoration, List actionTemplates, 
63                      PortletDefinitionComposite portlet, ContentFragment fragment, SecurityAccessController accessController)
64      {
65          int printModeIndex = actionTemplates.indexOf(PRINT_MODE_TEMPLATE);
66          int soloStateIndex = actionTemplates.indexOf(SOLO_ACTION_TEMPLATE);
67          
68          if ( printModeIndex != -1 && soloStateIndex != -1 )
69          {
70              // merge "solo" state with "print" mode
71              DecoratorActionTemplate soloStateTemplate = (DecoratorActionTemplate)actionTemplates.remove(soloStateIndex);
72              DecoratorActionTemplate printActionTemplate = (DecoratorActionTemplate)actionTemplates.get(printModeIndex);
73              printActionTemplate.setState(soloStateTemplate.getState());
74              printActionTemplate.setCustomState((soloStateTemplate.getCustomState()));
75          }
76          else if ( soloStateIndex != -1 )
77          {
78              // don't provide "solo" action separately without "print" mode
79              actionTemplates.remove(soloStateIndex);
80          }
81          // else if (printModeIndex != -1)
82          //   support switching to different modes once in "solo" state, even back to "print"
83          return super.getDecoratorActions(rc,pa,pw,pm,ws,decoration,actionTemplates, portlet,  fragment, accessController);
84      }
85      
86      protected DecoratorAction createAction(RequestContext rc, PortletWindow pw, Decoration decoration,
87                      DecoratorActionTemplate template)
88      {
89          DecoratorAction action = super.createAction(rc,pw,decoration,template);
90          if ( template.getState() != null && JetspeedActions.SOLO_STATE.equals(template.getState()))
91          {
92              // "solo" opens in a new popup winodw
93              action.setTarget("_blank");
94          }
95          return action;
96      }
97  }