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 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
public AbstractDecoratorActionsFactory() |
50 |
0 |
{ |
51 |
0 |
} |
52 |
|
|
53 |
|
public List getDecoratorActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode pm, |
54 |
|
WindowState ws, Decoration decoration, List actionTemplates,PortletDefinitionComposite portlet, |
55 |
|
ContentFragment fragment,SecurityAccessController accessController) |
56 |
|
{ |
57 |
|
DecoratorAction action; |
58 |
0 |
boolean checkConstraints=false; |
59 |
0 |
ArrayList actions = new ArrayList(); |
60 |
|
|
61 |
0 |
Iterator iter = actionTemplates.iterator(); |
62 |
0 |
while (iter.hasNext()) |
63 |
|
{ |
64 |
0 |
checkConstraints = false; |
65 |
0 |
DecoratorActionTemplate template = (DecoratorActionTemplate)iter.next(); |
66 |
|
|
67 |
0 |
if (template.getAction().equals(JetspeedActions.EDIT) || template.getAction().equals(JetspeedActions.HELP)) |
68 |
0 |
checkConstraints = true; |
69 |
0 |
if (checkConstraints && checkSecurityConstraint(portlet,fragment,accessController,template.getAction())) |
70 |
|
{ |
71 |
0 |
action = createAction(rc, pw, decoration,template ); |
72 |
0 |
if ( action != null) |
73 |
|
{ |
74 |
0 |
actions.add(action); |
75 |
|
} |
76 |
|
} |
77 |
0 |
else if (!checkConstraints) |
78 |
|
{ |
79 |
0 |
action = createAction(rc, pw, decoration,template ); |
80 |
0 |
if ( action != null) |
81 |
|
{ |
82 |
0 |
actions.add(action); |
83 |
|
} |
84 |
|
} |
85 |
0 |
} |
86 |
0 |
return actions; |
87 |
|
} |
88 |
|
|
89 |
|
public List getDecoratorActions(RequestContext rc, PortletApplication pa, PortletWindow pw, PortletMode pm, |
90 |
|
WindowState ws, Decoration decoration, List actionTemplates) |
91 |
|
{ |
92 |
|
DecoratorAction action; |
93 |
0 |
ArrayList actions = new ArrayList(); |
94 |
0 |
Iterator iter = actionTemplates.iterator(); |
95 |
0 |
while (iter.hasNext()) |
96 |
|
{ |
97 |
0 |
action = createAction(rc, pw, decoration,(DecoratorActionTemplate)iter.next() ); |
98 |
0 |
if ( action != null) |
99 |
|
{ |
100 |
0 |
actions.add(action); |
101 |
|
} |
102 |
|
} |
103 |
0 |
return actions; |
104 |
|
} |
105 |
|
|
106 |
|
protected DecoratorAction createAction(RequestContext rc, PortletWindow pw, Decoration decoration, |
107 |
|
DecoratorActionTemplate template) |
108 |
|
{ |
109 |
0 |
String actionName = template.getAction(); |
110 |
|
|
111 |
0 |
PortalURL portalURL = rc.getPortalURL(); |
112 |
0 |
Boolean isAjaxRequest = (Boolean) rc |
113 |
|
.getAttribute(DecorationValve.IS_AJAX_DECORATION_REQUEST); |
114 |
|
|
115 |
|
WindowState ws; |
116 |
|
PortletMode pm; |
117 |
0 |
if (editMaximizesOption) |
118 |
|
{ |
119 |
0 |
if (template.getAction().equals(JetspeedActions.EDIT)) |
120 |
|
{ |
121 |
0 |
ws = WindowState.MAXIMIZED; |
122 |
0 |
pm = template.getCustomMode(); |
123 |
|
} |
124 |
0 |
else if (template.getAction().equals(JetspeedActions.VIEW)) |
125 |
|
{ |
126 |
0 |
ws = WindowState.NORMAL; |
127 |
0 |
pm = template.getCustomMode(); |
128 |
|
} |
129 |
0 |
else if (template.getAction().equals(JetspeedActions.NORMAL)) |
130 |
|
{ |
131 |
0 |
pm = PortletMode.VIEW; |
132 |
0 |
ws = template.getCustomState(); |
133 |
|
} |
134 |
|
else |
135 |
|
{ |
136 |
0 |
ws = template.getCustomState(); |
137 |
0 |
pm = template.getCustomMode(); |
138 |
|
} |
139 |
|
} |
140 |
|
else |
141 |
|
{ |
142 |
0 |
ws = template.getCustomState(); |
143 |
0 |
pm = template.getCustomMode(); |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
0 |
String actionURL = rc.getResponse().encodeURL( |
148 |
|
(isAjaxRequest == null) ? portalURL.createPortletURL(pw, pm, ws, portalURL.isSecure()).toString() |
149 |
|
: portalURL.createNavigationalEncoding(pw, pm, ws)); |
150 |
|
|
151 |
0 |
String linkURL = decoration |
152 |
|
.getResource("images/" + actionName + ".gif"); |
153 |
|
|
154 |
0 |
boolean customAction = (template.getMode() != null && !template |
155 |
|
.getMode().equals(template.getCustomMode())) |
156 |
|
|| (template.getState() != null && !template.getState().equals( |
157 |
|
template.getCustomState())); |
158 |
|
|
159 |
0 |
HashMap resourcesMap = (HashMap)actionResourcesMap.get(); |
160 |
0 |
ResourceBundle bundle = null; |
161 |
0 |
String localizedName = null; |
162 |
|
|
163 |
0 |
if (resourcesMap == null) |
164 |
|
{ |
165 |
0 |
resourcesMap = new HashMap(); |
166 |
0 |
actionResourcesMap.set(resourcesMap); |
167 |
0 |
bundle = DecoratorAction.getResourceBundle(rc.getLocale()); |
168 |
0 |
resourcesMap.put(DecoratorAction.RESOURCE_BUNDLE, bundle); |
169 |
0 |
localizedName = DecoratorAction.getResourceString(bundle, actionName, actionName); |
170 |
0 |
resourcesMap.put(actionName,localizedName); |
171 |
|
} |
172 |
|
else |
173 |
|
{ |
174 |
0 |
localizedName = (String)resourcesMap.get(actionName); |
175 |
0 |
if (localizedName == null) |
176 |
|
{ |
177 |
0 |
localizedName = DecoratorAction.getResourceString(bundle, actionName, actionName); |
178 |
0 |
resourcesMap.put(actionName,localizedName); |
179 |
|
} |
180 |
|
} |
181 |
0 |
return new DecoratorAction(actionName, localizedName, localizedName, linkURL, actionURL, customAction, template.getActionType()); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
protected boolean checkSecurityConstraint( |
186 |
|
PortletDefinitionComposite portlet, ContentFragment fragment, |
187 |
|
SecurityAccessController accessController, String action) |
188 |
|
{ |
189 |
0 |
if (fragment.getType().equals(ContentFragment.PORTLET)) |
190 |
|
{ |
191 |
0 |
if (accessController != null) |
192 |
|
{ |
193 |
0 |
return accessController |
194 |
|
.checkPortletAccess(portlet, JetspeedActions |
195 |
|
.getContainerActionMask(action)); |
196 |
|
} |
197 |
|
} |
198 |
0 |
return true; |
199 |
|
} |
200 |
|
|
201 |
|
public void setMaximizeOnEdit(boolean maxOnEdit) |
202 |
|
{ |
203 |
0 |
this.editMaximizesOption = maxOnEdit; |
204 |
0 |
} |
205 |
|
|
206 |
|
public boolean getMaximizeOnEdit() |
207 |
|
{ |
208 |
0 |
return this.editMaximizesOption; |
209 |
|
} |
210 |
|
|
211 |
|
} |