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.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
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
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
79 actionTemplates.remove(soloStateIndex);
80 }
81
82
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
93 action.setTarget("_blank");
94 }
95 return action;
96 }
97 }