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.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 private static final DecoratorActionTemplate ABOUT_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.ABOUT_MODE);
38 private static final DecoratorActionTemplate CONFIG_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.CONFIG_MODE);
39 private static final DecoratorActionTemplate EDIT_DEFAULTS_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.EDIT_DEFAULTS_MODE);
40
41 private static final DecoratorActionTemplate PRINT_MODE_TEMPLATE = new DecoratorActionTemplate(JetspeedActions.PRINT_MODE);
42 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 {
49 ArrayList list = new ArrayList(JetspeedActions.getStandardPortletModes());
50 list.add(JetspeedActions.ABOUT_MODE);
51 list.add(JetspeedActions.CONFIG_MODE);
52 list.add(JetspeedActions.EDIT_DEFAULTS_MODE);
53
54 list.add(JetspeedActions.PRINT_MODE);
55 list.addAll(JetspeedActions.getStandardWindowStates());
56 list.add(JetspeedActions.SOLO_STATE);
57 supportedActions = Collections.unmodifiableList(list);
58
59 list = new ArrayList(JetspeedActions.getStandardPortletModes());
60 list.add(JetspeedActions.PRINT_MODE);
61 supportedSoloActions = Collections.unmodifiableList(list);
62 }
63
64 public List getSupportedActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode cm,
65 WindowState ws, Decoration decoration)
66 {
67
68 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 int printModeIndex = actionTemplates.indexOf(PRINT_MODE_TEMPLATE);
76 int soloStateIndex = actionTemplates.indexOf(SOLO_ACTION_TEMPLATE);
77
78 if ( printModeIndex != -1 && soloStateIndex != -1 )
79 {
80
81 DecoratorActionTemplate soloStateTemplate = (DecoratorActionTemplate)actionTemplates.remove(soloStateIndex);
82 DecoratorActionTemplate printActionTemplate = (DecoratorActionTemplate)actionTemplates.get(printModeIndex);
83 printActionTemplate.setState(soloStateTemplate.getState());
84 printActionTemplate.setCustomState((soloStateTemplate.getCustomState()));
85 }
86 else if ( soloStateIndex != -1 )
87 {
88
89 actionTemplates.remove(soloStateIndex);
90 }
91
92
93
94 int configModeIndex = actionTemplates.indexOf(CONFIG_MODE_TEMPLATE);
95 if (configModeIndex != -1)
96 {
97 try
98 {
99 ContentPage page = rc.getPage();
100 page.checkAccess(JetspeedActions.CONFIG);
101 }
102 catch (SecurityException e)
103 {
104 actionTemplates.remove(configModeIndex);
105 }
106 }
107
108 int editDefaultsModeIndex = actionTemplates.indexOf(EDIT_DEFAULTS_MODE_TEMPLATE);
109 if (editDefaultsModeIndex != -1)
110 {
111 try
112 {
113 ContentPage page = rc.getPage();
114 page.checkAccess(JetspeedActions.EDIT_DEFAULTS);
115 }
116 catch (SecurityException e)
117 {
118 actionTemplates.remove(editDefaultsModeIndex);
119 }
120 }
121
122 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 DecoratorAction action = super.createAction(rc,pw,decoration,template);
129 if ( template.getState() != null && JetspeedActions.SOLO_STATE.equals(template.getState()))
130 {
131
132 action.setTarget("_blank");
133 }
134 return action;
135 }
136 }