1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.layout.impl; |
18 |
|
|
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.Iterator; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import javax.portlet.PortletMode; |
24 |
|
import javax.portlet.WindowState; |
25 |
|
|
26 |
|
import org.apache.commons.logging.Log; |
27 |
|
import org.apache.commons.logging.LogFactory; |
28 |
|
import org.apache.jetspeed.JetspeedActions; |
29 |
|
import org.apache.jetspeed.ajax.AJAXException; |
30 |
|
import org.apache.jetspeed.ajax.AjaxAction; |
31 |
|
import org.apache.jetspeed.ajax.AjaxBuilder; |
32 |
|
import org.apache.jetspeed.container.state.MutableNavigationalState; |
33 |
|
import org.apache.jetspeed.container.window.PortletWindowAccessor; |
34 |
|
import org.apache.jetspeed.layout.PortletActionSecurityBehavior; |
35 |
|
import org.apache.jetspeed.om.page.ContentFragment; |
36 |
|
import org.apache.jetspeed.om.page.ContentPage; |
37 |
|
import org.apache.jetspeed.page.PageManager; |
38 |
|
import org.apache.jetspeed.request.RequestContext; |
39 |
|
import org.apache.pluto.om.window.PortletWindow; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
public class ChangePortletAction |
54 |
|
extends BasePortletAction |
55 |
|
implements AjaxAction, AjaxBuilder, Constants |
56 |
|
{ |
57 |
0 |
protected static final Log log = LogFactory.getLog(ChangePortletAction.class); |
58 |
|
protected String action; |
59 |
0 |
protected Map validWindowStates = new HashMap(); |
60 |
0 |
protected Map validPortletModes = new HashMap(); |
61 |
|
protected PortletWindowAccessor windowAccessor; |
62 |
|
|
63 |
|
public ChangePortletAction(String template, |
64 |
|
String errorTemplate, |
65 |
|
String action, |
66 |
|
PortletWindowAccessor windowAccessor) |
67 |
|
throws AJAXException |
68 |
|
{ |
69 |
0 |
this(template, errorTemplate, action, null, windowAccessor, class="keyword">null); |
70 |
0 |
} |
71 |
|
|
72 |
|
public ChangePortletAction(String template, |
73 |
|
String errorTemplate, |
74 |
|
String action, |
75 |
|
PageManager pageManager, |
76 |
|
PortletWindowAccessor windowAccessor, |
77 |
|
PortletActionSecurityBehavior securityBehavior) |
78 |
|
throws AJAXException |
79 |
|
{ |
80 |
0 |
super(template, errorTemplate, pageManager, securityBehavior); |
81 |
0 |
this.action = action; |
82 |
0 |
this.windowAccessor = windowAccessor; |
83 |
|
|
84 |
|
|
85 |
0 |
Iterator modes = JetspeedActions.getStandardPortletModes().iterator(); |
86 |
0 |
while (modes.hasNext()) |
87 |
|
{ |
88 |
0 |
String mode = modes.next().toString(); |
89 |
0 |
this.validPortletModes.put(mode, mode); |
90 |
0 |
} |
91 |
0 |
modes = JetspeedActions.getExtendedPortletModes().iterator(); |
92 |
0 |
while (modes.hasNext()) |
93 |
|
{ |
94 |
0 |
String mode = modes.next().toString(); |
95 |
0 |
this.validPortletModes.put(mode, mode); |
96 |
0 |
} |
97 |
0 |
Iterator states = JetspeedActions.getStandardWindowStates().iterator(); |
98 |
0 |
while (states.hasNext()) |
99 |
|
{ |
100 |
0 |
String state = states.next().toString(); |
101 |
0 |
this.validWindowStates.put(state, state); |
102 |
0 |
} |
103 |
0 |
states = JetspeedActions.getExtendedWindowStates().iterator(); |
104 |
0 |
while (states.hasNext()) |
105 |
|
{ |
106 |
0 |
String state = states.next().toString(); |
107 |
0 |
this.validWindowStates.put(state, state); |
108 |
0 |
} |
109 |
0 |
} |
110 |
|
|
111 |
|
public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException |
112 |
|
{ |
113 |
0 |
return runAction(requestContext, resultMap, true); |
114 |
|
} |
115 |
|
|
116 |
|
public boolean run(RequestContext requestContext, Map resultMap) |
117 |
|
throws AJAXException |
118 |
|
{ |
119 |
0 |
return runAction(requestContext, resultMap, false); |
120 |
|
} |
121 |
|
|
122 |
|
public boolean runAction(RequestContext requestContext, Map resultMap, class="keyword">boolean batch) |
123 |
|
{ |
124 |
0 |
boolean success = true; |
125 |
0 |
String status = "success"; |
126 |
|
try |
127 |
|
{ |
128 |
0 |
resultMap.put(ACTION, action); |
129 |
|
|
130 |
0 |
String portletId = getActionParameter(requestContext, PORTLETID); |
131 |
0 |
if (portletId == null) |
132 |
|
{ |
133 |
0 |
throw new Exception("portlet id not provided"); |
134 |
|
} |
135 |
0 |
resultMap.put(PORTLETID, portletId); |
136 |
|
|
137 |
0 |
String windowState = getActionParameter(requestContext, WINDOW_STATE); |
138 |
0 |
String portletMode = getActionParameter(requestContext, PORTLET_MODE); |
139 |
0 |
if (windowState == null && portletMode == class="keyword">null) |
140 |
|
{ |
141 |
0 |
throw new Exception("portlet window state or mode not provided"); |
142 |
|
} |
143 |
0 |
if (windowState != null && !isValidWindowState(windowState)) |
144 |
|
{ |
145 |
0 |
throw new Exception("portlet window state " + windowState + " is not supported"); |
146 |
|
} |
147 |
0 |
if (portletMode != null && !isValidPortletMode(portletMode)) |
148 |
|
{ |
149 |
0 |
throw new Exception("portlet mode " + portletMode + " is not supported"); |
150 |
|
} |
151 |
|
|
152 |
0 |
ContentPage page = requestContext.getPage(); |
153 |
0 |
ContentFragment fragment = page.getContentFragmentById(portletId); |
154 |
|
|
155 |
0 |
String oldState = fragment.getState(); |
156 |
0 |
String oldMode = fragment.getMode(); |
157 |
|
|
158 |
|
|
159 |
0 |
MutableNavigationalState navState = (MutableNavigationalState)requestContext.getPortalURL().getNavigationalState(); |
160 |
0 |
PortletWindow portletWindow = windowAccessor.getPortletWindow(fragment); |
161 |
0 |
if (portletWindow != null) |
162 |
|
{ |
163 |
0 |
oldState = navState.getState(portletWindow).toString(); |
164 |
0 |
oldMode = navState.getMode(portletWindow).toString(); |
165 |
0 |
if (windowState != null) |
166 |
|
{ |
167 |
0 |
navState.setState(portletWindow, new WindowState(windowState)); |
168 |
|
} |
169 |
0 |
if (portletMode != null) |
170 |
|
{ |
171 |
0 |
navState.setMode(portletWindow, new PortletMode(portletMode)); |
172 |
|
} |
173 |
0 |
navState.sync(requestContext); |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
0 |
if (checkAccess(requestContext, JetspeedActions.EDIT)) |
178 |
|
{ |
179 |
0 |
if (windowState != null) |
180 |
0 |
fragment.setState(windowState); |
181 |
0 |
if (portletMode != null) |
182 |
0 |
fragment.setMode(portletMode); |
183 |
|
|
184 |
0 |
if (pageManager != null && !batch) |
185 |
|
{ |
186 |
0 |
pageManager.updatePage(page); |
187 |
|
} |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
0 |
resultMap.put(STATUS, status); |
192 |
|
|
193 |
0 |
if (windowState != null) |
194 |
|
{ |
195 |
0 |
resultMap.put(OLD_WINDOW_STATE, oldState); |
196 |
0 |
resultMap.put(WINDOW_STATE, windowState); |
197 |
|
} |
198 |
|
|
199 |
0 |
if (portletMode != null) |
200 |
|
{ |
201 |
0 |
resultMap.put(OLD_PORTLET_MODE, oldMode); |
202 |
0 |
resultMap.put(PORTLET_MODE, portletMode); |
203 |
|
} |
204 |
|
|
205 |
|
} |
206 |
0 |
catch (Exception e) |
207 |
|
{ |
208 |
|
|
209 |
0 |
log.error("exception while moving a portlet", e); |
210 |
0 |
resultMap.put(REASON, e.toString()); |
211 |
|
|
212 |
0 |
success = false; |
213 |
0 |
} |
214 |
|
|
215 |
0 |
return success; |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
protected boolean isValidWindowState(String windowState) |
228 |
|
{ |
229 |
0 |
return this.validWindowStates.containsKey(windowState); |
230 |
|
} |
231 |
|
protected boolean isValidPortletMode(String portletMode) |
232 |
|
{ |
233 |
0 |
return this.validPortletModes.containsKey(portletMode); |
234 |
|
} |
235 |
|
|
236 |
|
} |