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.Map; |
20 |
|
|
21 |
|
import org.apache.commons.logging.Log; |
22 |
|
import org.apache.commons.logging.LogFactory; |
23 |
|
import org.apache.jetspeed.JetspeedActions; |
24 |
|
import org.apache.jetspeed.ajax.AJAXException; |
25 |
|
import org.apache.jetspeed.ajax.AjaxAction; |
26 |
|
import org.apache.jetspeed.ajax.AjaxBuilder; |
27 |
|
import org.apache.jetspeed.layout.PortletActionSecurityBehavior; |
28 |
|
import org.apache.jetspeed.layout.PortletPlacementContext; |
29 |
|
import org.apache.jetspeed.om.page.Fragment; |
30 |
|
import org.apache.jetspeed.om.page.Page; |
31 |
|
import org.apache.jetspeed.page.PageManager; |
32 |
|
import org.apache.jetspeed.pipeline.PipelineException; |
33 |
|
import org.apache.jetspeed.request.RequestContext; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public class RemovePortletAction |
48 |
|
extends BasePortletAction |
49 |
|
implements AjaxAction, AjaxBuilder, Constants |
50 |
|
{ |
51 |
0 |
protected static final Log log = LogFactory.getLog(RemovePortletAction.class); |
52 |
|
|
53 |
|
public RemovePortletAction(String template, String errorTemplate) |
54 |
|
throws PipelineException |
55 |
|
{ |
56 |
0 |
this(template, errorTemplate, null, class="keyword">null); |
57 |
0 |
} |
58 |
|
|
59 |
|
public RemovePortletAction(String template, |
60 |
|
String errorTemplate, |
61 |
|
PageManager pageManager, |
62 |
|
PortletActionSecurityBehavior securityBehavior) |
63 |
|
throws PipelineException |
64 |
|
{ |
65 |
0 |
super(template, errorTemplate, pageManager, securityBehavior); |
66 |
0 |
} |
67 |
|
|
68 |
|
public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException |
69 |
|
{ |
70 |
0 |
return runAction(requestContext, resultMap, true); |
71 |
|
} |
72 |
|
|
73 |
|
public boolean run(RequestContext requestContext, Map resultMap) |
74 |
|
throws AJAXException |
75 |
|
{ |
76 |
0 |
return runAction(requestContext, resultMap, false); |
77 |
|
} |
78 |
|
|
79 |
|
public boolean runAction(RequestContext requestContext, Map resultMap, class="keyword">boolean batch) |
80 |
|
{ |
81 |
0 |
boolean success = true; |
82 |
0 |
String status = "success"; |
83 |
|
try |
84 |
|
{ |
85 |
0 |
resultMap.put(ACTION, "remove"); |
86 |
|
|
87 |
0 |
String portletId = getActionParameter(requestContext, PORTLETID); |
88 |
0 |
if (portletId == null) |
89 |
|
{ |
90 |
0 |
success = false; |
91 |
0 |
resultMap.put(REASON, "Portlet ID not provided"); |
92 |
0 |
return success; |
93 |
|
} |
94 |
0 |
resultMap.put(PORTLETID, portletId); |
95 |
0 |
if (false == checkAccess(requestContext, JetspeedActions.EDIT)) |
96 |
|
{ |
97 |
0 |
Page page = requestContext.getPage(); |
98 |
0 |
Fragment fragment = page.getFragmentById(portletId); |
99 |
0 |
if (fragment == null) |
100 |
|
{ |
101 |
0 |
success = false; |
102 |
0 |
resultMap.put(REASON, "Fragment not found"); |
103 |
0 |
return success; |
104 |
|
} |
105 |
0 |
int column = fragment.getLayoutColumn(); |
106 |
0 |
int row = fragment.getLayoutRow(); |
107 |
0 |
if (!createNewPageOnEdit(requestContext)) |
108 |
|
{ |
109 |
0 |
success = false; |
110 |
0 |
resultMap.put(REASON, "Insufficient access to edit page"); |
111 |
0 |
return success; |
112 |
|
} |
113 |
0 |
status = "refresh"; |
114 |
|
|
115 |
0 |
Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage()); |
116 |
0 |
if (newFragment == null) |
117 |
|
{ |
118 |
0 |
success = false; |
119 |
0 |
resultMap.put(REASON, "Failed to find new fragment"); |
120 |
0 |
return success; |
121 |
|
} |
122 |
0 |
portletId = newFragment.getId(); |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
0 |
PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext); |
127 |
0 |
Fragment fragment = placement.getFragmentById(portletId); |
128 |
0 |
if (fragment == null) |
129 |
|
{ |
130 |
0 |
success = false; |
131 |
0 |
resultMap.put(REASON, "Fragment not found"); |
132 |
0 |
return success; |
133 |
|
} |
134 |
0 |
placement.remove(fragment); |
135 |
0 |
Page page = placement.syncPageFragments(); |
136 |
0 |
page.removeFragmentById(fragment.getId()); |
137 |
0 |
if (!batch) |
138 |
|
{ |
139 |
0 |
if (pageManager != null) |
140 |
0 |
pageManager.updatePage(page); |
141 |
|
} |
142 |
|
|
143 |
0 |
resultMap.put(PORTLETID, portletId); |
144 |
0 |
resultMap.put(STATUS, status); |
145 |
0 |
resultMap.put(OLDCOL, String.valueOf(fragment.getLayoutColumn())); |
146 |
0 |
resultMap.put(OLDROW, String.valueOf(fragment.getLayoutRow())); |
147 |
|
} |
148 |
0 |
catch (Exception e) |
149 |
|
{ |
150 |
|
|
151 |
0 |
log.error("exception while adding a portlet", e); |
152 |
0 |
resultMap.put(REASON, e.toString()); |
153 |
|
|
154 |
0 |
success = false; |
155 |
0 |
} |
156 |
|
|
157 |
0 |
return success; |
158 |
|
} |
159 |
|
} |