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.HashMap; |
21 |
|
import java.util.Iterator; |
22 |
|
import java.util.List; |
23 |
|
import java.util.Locale; |
24 |
|
import java.util.MissingResourceException; |
25 |
|
import java.util.ResourceBundle; |
26 |
|
|
27 |
|
import javax.portlet.PortletMode; |
28 |
|
import javax.portlet.WindowState; |
29 |
|
|
30 |
|
import org.apache.jetspeed.JetspeedActions; |
31 |
|
import org.apache.jetspeed.container.url.PortalURL; |
32 |
|
import org.apache.jetspeed.om.common.portlet.PortletApplication; |
33 |
|
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite; |
34 |
|
import org.apache.jetspeed.om.page.ContentFragment; |
35 |
|
import org.apache.jetspeed.request.RequestContext; |
36 |
|
import org.apache.jetspeed.security.SecurityAccessController; |
37 |
|
import org.apache.pluto.om.window.PortletWindow; |
38 |
|
|
39 |
|
public abstract class AbstractDecoratorActionsFactory implements DecoratorActionsFactory |
40 |
|
{ |
41 |
0 |
private static ThreadLocal actionResourcesMap = new ThreadLocal(); |
42 |
0 |
private boolean editMaximizesOption = false; |
43 |
0 |
private boolean configMaximizesOption = false; |
44 |
0 |
private boolean editDefaultsMaximizesOption = false; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
public AbstractDecoratorActionsFactory() |
52 |
0 |
{ |
53 |
0 |
} |
54 |
|
|
55 |
|
public List getDecoratorActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode pm, |
56 |
|
WindowState ws, Decoration decoration, List actionTemplates,PortletDefinitionComposite portlet, |
57 |
|
ContentFragment fragment,SecurityAccessController accessController) |
58 |
|
{ |
59 |
|
DecoratorAction action; |
60 |
0 |
boolean checkConstraints=false; |
61 |
0 |
ArrayList actions = new ArrayList(); |
62 |
|
|
63 |
0 |
Iterator iter = actionTemplates.iterator(); |
64 |
0 |
while (iter.hasNext()) |
65 |
|
{ |
66 |
0 |
checkConstraints = false; |
67 |
0 |
DecoratorActionTemplate template = (DecoratorActionTemplate)iter.next(); |
68 |
|
|
69 |
0 |
if (template.getAction().equals(JetspeedActions.EDIT) || template.getAction().equals(JetspeedActions.HELP)) |
70 |
0 |
checkConstraints = true; |
71 |
0 |
if (checkConstraints && checkSecurityConstraint(portlet,fragment,accessController,template.getAction())) |
72 |
|
{ |
73 |
0 |
action = createAction(rc, pw, decoration,template ); |
74 |
0 |
if ( action != null) |
75 |
|
{ |
76 |
0 |
actions.add(action); |
77 |
|
} |
78 |
|
} |
79 |
0 |
else if (!checkConstraints) |
80 |
|
{ |
81 |
0 |
action = createAction(rc, pw, decoration,template ); |
82 |
0 |
if ( action != null) |
83 |
|
{ |
84 |
0 |
actions.add(action); |
85 |
|
} |
86 |
|
} |
87 |
0 |
} |
88 |
0 |
return actions; |
89 |
|
} |
90 |
|
|
91 |
|
public List getDecoratorActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode pm, |
92 |
|
WindowState ws, Decoration decoration, List actionTemplates) |
93 |
|
{ |
94 |
|
DecoratorAction action; |
95 |
0 |
ArrayList actions = new ArrayList(); |
96 |
0 |
Iterator iter = actionTemplates.iterator(); |
97 |
0 |
while (iter.hasNext()) |
98 |
|
{ |
99 |
0 |
action = createAction(rc, pw, decoration,(DecoratorActionTemplate)iter.next() ); |
100 |
0 |
if ( action != null) |
101 |
|
{ |
102 |
0 |
actions.add(action); |
103 |
|
} |
104 |
|
} |
105 |
0 |
return actions; |
106 |
|
} |
107 |
|
|
108 |
|
protected DecoratorAction createAction(RequestContext rc, PortletWindow pw, Decoration decoration, |
109 |
|
DecoratorActionTemplate template) |
110 |
|
{ |
111 |
0 |
String actionName = template.getAction(); |
112 |
|
|
113 |
0 |
PortalURL portalURL = rc.getPortalURL(); |
114 |
0 |
Boolean isAjaxRequest = (Boolean) rc |
115 |
|
.getAttribute(DecorationValve.IS_AJAX_DECORATION_REQUEST); |
116 |
|
|
117 |
|
WindowState ws; |
118 |
|
PortletMode pm; |
119 |
0 |
if (editMaximizesOption || configMaximizesOption || editDefaultsMaximizesOption) |
120 |
|
{ |
121 |
0 |
if (editMaximizesOption && template.getAction().equals(JetspeedActions.EDIT)) |
122 |
|
{ |
123 |
0 |
ws = WindowState.MAXIMIZED; |
124 |
0 |
pm = template.getCustomMode(); |
125 |
|
} |
126 |
0 |
else if (configMaximizesOption && template.getAction().equals(JetspeedActions.CONFIG)) |
127 |
|
{ |
128 |
0 |
ws = WindowState.MAXIMIZED; |
129 |
0 |
pm = template.getCustomMode(); |
130 |
|
} |
131 |
0 |
else if (editDefaultsMaximizesOption && template.getAction().equals(JetspeedActions.EDIT_DEFAULTS)) |
132 |
|
{ |
133 |
0 |
ws = WindowState.MAXIMIZED; |
134 |
0 |
pm = template.getCustomMode(); |
135 |
|
} |
136 |
0 |
else if (template.getAction().equals(JetspeedActions.VIEW)) |
137 |
|
{ |
138 |
0 |
ws = WindowState.NORMAL; |
139 |
0 |
pm = template.getCustomMode(); |
140 |
|
} |
141 |
0 |
else if (template.getAction().equals(JetspeedActions.NORMAL)) |
142 |
|
{ |
143 |
0 |
pm = PortletMode.VIEW; |
144 |
0 |
ws = template.getCustomState(); |
145 |
|
} |
146 |
|
else |
147 |
|
{ |
148 |
0 |
ws = template.getCustomState(); |
149 |
0 |
pm = template.getCustomMode(); |
150 |
|
} |
151 |
|
} |
152 |
|
else |
153 |
|
{ |
154 |
0 |
ws = template.getCustomState(); |
155 |
0 |
pm = template.getCustomMode(); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
0 |
String actionURL = rc.getResponse().encodeURL( |
160 |
|
(isAjaxRequest == null) ? portalURL.createPortletURL(pw, pm, ws, portalURL.isSecure()).toString() |
161 |
|
: portalURL.createNavigationalEncoding(pw, pm, ws)); |
162 |
|
|
163 |
0 |
String linkURL = decoration |
164 |
|
.getResource("images/" + actionName + ".gif"); |
165 |
|
|
166 |
0 |
boolean customAction = (template.getMode() != null && !template |
167 |
|
.getMode().equals(template.getCustomMode())) |
168 |
|
|| (template.getState() != null && !template.getState().equals( |
169 |
|
template.getCustomState())); |
170 |
|
|
171 |
0 |
HashMap resourcesMap = (HashMap)actionResourcesMap.get(); |
172 |
0 |
ResourceBundle bundle = DecoratorAction.getResourceBundle(rc.getLocale()); |
173 |
0 |
String localizedName = null; |
174 |
|
|
175 |
0 |
if (resourcesMap == null) |
176 |
|
{ |
177 |
0 |
resourcesMap = new HashMap(); |
178 |
0 |
actionResourcesMap.set(resourcesMap); |
179 |
0 |
resourcesMap.put(DecoratorAction.RESOURCE_BUNDLE, bundle); |
180 |
0 |
localizedName = DecoratorAction.getResourceString(bundle, actionName, actionName); |
181 |
0 |
resourcesMap.put(actionName,localizedName); |
182 |
|
} |
183 |
|
else |
184 |
|
{ |
185 |
0 |
localizedName = (String)resourcesMap.get(actionName); |
186 |
0 |
if (localizedName == null) |
187 |
|
{ |
188 |
0 |
localizedName = DecoratorAction.getResourceString(bundle, actionName, actionName); |
189 |
0 |
resourcesMap.put(actionName,localizedName); |
190 |
|
} |
191 |
|
} |
192 |
0 |
return new DecoratorAction(actionName, localizedName, localizedName, linkURL, actionURL, customAction, template.getActionType()); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
protected boolean checkSecurityConstraint( |
197 |
|
PortletDefinitionComposite portlet, ContentFragment fragment, |
198 |
|
SecurityAccessController accessController, String action) |
199 |
|
{ |
200 |
0 |
if (fragment.getType().equals(ContentFragment.PORTLET)) |
201 |
|
{ |
202 |
0 |
if (accessController != null) |
203 |
|
{ |
204 |
0 |
return accessController |
205 |
|
.checkPortletAccess(portlet, JetspeedActions |
206 |
|
.getContainerActionMask(action)); |
207 |
|
} |
208 |
|
} |
209 |
0 |
return true; |
210 |
|
} |
211 |
|
|
212 |
|
public void setMaximizeOnEdit(boolean maxOnEdit) |
213 |
|
{ |
214 |
0 |
this.editMaximizesOption = maxOnEdit; |
215 |
0 |
} |
216 |
|
|
217 |
|
public boolean getMaximizeOnEdit() |
218 |
|
{ |
219 |
0 |
return this.editMaximizesOption; |
220 |
|
} |
221 |
|
|
222 |
|
public void setMaximizeOnConfig(boolean maxOnConfig) |
223 |
|
{ |
224 |
0 |
this.configMaximizesOption = maxOnConfig; |
225 |
0 |
} |
226 |
|
|
227 |
|
public boolean getMaximizeOnConfig() |
228 |
|
{ |
229 |
0 |
return this.configMaximizesOption; |
230 |
|
} |
231 |
|
|
232 |
|
public void setMaximizeOnEditDefaults(boolean maxOnEditDefaults) |
233 |
|
{ |
234 |
0 |
this.editDefaultsMaximizesOption = maxOnEditDefaults; |
235 |
0 |
} |
236 |
|
|
237 |
|
public boolean getMaximizeOnEditDefaults() |
238 |
|
{ |
239 |
0 |
return this.editDefaultsMaximizesOption; |
240 |
|
} |
241 |
|
} |