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.om.folder.Folder; |
29 |
|
import org.apache.jetspeed.om.page.Link; |
30 |
|
import org.apache.jetspeed.page.PageManager; |
31 |
|
import org.apache.jetspeed.page.document.Node; |
32 |
|
import org.apache.jetspeed.request.RequestContext; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
public class UpdateLinkAction |
52 |
|
extends BaseSiteUpdateAction |
53 |
|
implements AjaxAction, AjaxBuilder, Constants |
54 |
|
{ |
55 |
0 |
protected Log log = LogFactory.getLog(UpdateLinkAction.class); |
56 |
|
|
57 |
|
public UpdateLinkAction(String template, |
58 |
|
String errorTemplate, |
59 |
|
PageManager pm, |
60 |
|
PortletActionSecurityBehavior securityBehavior) |
61 |
|
|
62 |
|
{ |
63 |
0 |
super(template, errorTemplate, pm, securityBehavior); |
64 |
0 |
} |
65 |
|
|
66 |
|
public boolean run(RequestContext requestContext, Map resultMap) |
67 |
|
throws AJAXException |
68 |
|
{ |
69 |
0 |
boolean success = true; |
70 |
0 |
String status = "success"; |
71 |
|
try |
72 |
|
{ |
73 |
0 |
resultMap.put(ACTION, "updatelink"); |
74 |
|
|
75 |
0 |
String method = getActionParameter(requestContext, "method"); |
76 |
0 |
if (method == null) |
77 |
|
{ |
78 |
0 |
throw new RuntimeException("Method not provided"); |
79 |
|
} |
80 |
0 |
resultMap.put("method", method); |
81 |
0 |
if (false == checkAccess(requestContext, JetspeedActions.EDIT)) |
82 |
|
{ |
83 |
0 |
success = false; |
84 |
0 |
resultMap.put(REASON, "Insufficient access to administer portal permissions"); |
85 |
0 |
return success; |
86 |
|
} |
87 |
0 |
int count = 0; |
88 |
0 |
String path = getActionParameter(requestContext, "path"); |
89 |
0 |
if (path == null) |
90 |
0 |
throw new AJAXException("Missing 'path' parameter"); |
91 |
0 |
Link link = null; |
92 |
0 |
if (!method.equals("add")) |
93 |
|
{ |
94 |
0 |
link = pageManager.getLink(path); |
95 |
|
} |
96 |
|
else |
97 |
|
{ |
98 |
0 |
if (pageManager.linkExists(path)) |
99 |
|
{ |
100 |
0 |
success = false; |
101 |
0 |
resultMap.put(REASON, "Can't create: Link already exists: " + path); |
102 |
0 |
return success; |
103 |
|
} |
104 |
|
} |
105 |
0 |
if (method.equals("info")) |
106 |
|
{ |
107 |
0 |
count = updateInformation(requestContext, resultMap, link, path); |
108 |
|
} |
109 |
0 |
else if (method.equals("update-meta")) |
110 |
|
{ |
111 |
0 |
count = updateMetadata(requestContext, resultMap, link); |
112 |
|
} |
113 |
0 |
else if (method.equals("add-meta")) |
114 |
|
{ |
115 |
0 |
count = insertMetadata(requestContext, resultMap, link); |
116 |
|
} |
117 |
0 |
else if (method.equals("remove-meta")) |
118 |
|
{ |
119 |
0 |
count = removeMetadata(requestContext, resultMap, link); |
120 |
|
} |
121 |
0 |
else if (method.equals("add-secref")) |
122 |
|
{ |
123 |
0 |
count = insertSecurityReference(requestContext, resultMap, link); |
124 |
|
} |
125 |
0 |
else if (method.equals("update-secref")) |
126 |
|
{ |
127 |
0 |
count = updateSecurityReference(requestContext, resultMap, link); |
128 |
|
} |
129 |
0 |
else if (method.equals("remove-secref")) |
130 |
|
{ |
131 |
0 |
count = removeSecurityReference(requestContext, resultMap, link); |
132 |
|
} |
133 |
0 |
else if (method.equals("remove-secdef")) |
134 |
|
{ |
135 |
0 |
count = removeSecurityDef(requestContext, resultMap, link); |
136 |
|
} |
137 |
0 |
else if (method.equals("add")) |
138 |
|
{ |
139 |
0 |
link = pageManager.newLink(path); |
140 |
0 |
link.setTitle(getActionParameter(requestContext, "title")); |
141 |
0 |
String s = getActionParameter(requestContext, "short-title"); |
142 |
0 |
if (!isBlank(s)) |
143 |
0 |
link.setShortTitle(s); |
144 |
0 |
link.setUrl(getActionParameter(requestContext, "url")); |
145 |
0 |
count++; |
146 |
0 |
} |
147 |
0 |
else if (method.equals("copy")) |
148 |
|
{ |
149 |
0 |
String destination = getActionParameter(requestContext, "destination"); |
150 |
0 |
String name = getActionParameter(requestContext, RESOURCE_NAME); |
151 |
0 |
destination = destination + Folder.PATH_SEPARATOR + name; |
152 |
0 |
Link newLink = pageManager.copyLink(link, destination); |
153 |
0 |
pageManager.updateLink(newLink); |
154 |
0 |
} |
155 |
0 |
else if (method.equals("move")) |
156 |
|
{ |
157 |
0 |
String destination = getActionParameter(requestContext, "destination"); |
158 |
0 |
String name = getActionParameter(requestContext, RESOURCE_NAME); |
159 |
0 |
destination = destination + Folder.PATH_SEPARATOR + name; |
160 |
0 |
Link newLink = pageManager.copyLink(link, destination); |
161 |
0 |
pageManager.updateLink(newLink); |
162 |
0 |
pageManager.removeLink(link); |
163 |
|
|
164 |
0 |
} |
165 |
0 |
else if (method.equals("remove")) |
166 |
|
{ |
167 |
0 |
pageManager.removeLink(link); |
168 |
|
} |
169 |
|
else |
170 |
|
{ |
171 |
0 |
success = false; |
172 |
0 |
resultMap.put(REASON, "Unsupported Site Update method: " + method); |
173 |
0 |
return success; |
174 |
|
} |
175 |
0 |
if (count > 0) |
176 |
|
{ |
177 |
0 |
pageManager.updateLink(link); |
178 |
|
} |
179 |
0 |
resultMap.put("count", Integer.toString(count)); |
180 |
0 |
resultMap.put(STATUS, status); |
181 |
|
} |
182 |
0 |
catch (Exception e) |
183 |
|
{ |
184 |
0 |
log.error("exception administering Site update", e); |
185 |
0 |
resultMap.put(REASON, e.toString()); |
186 |
0 |
success = false; |
187 |
0 |
} |
188 |
0 |
return success; |
189 |
|
} |
190 |
|
|
191 |
|
protected int updateInformation(RequestContext requestContext, Map resultMap, Node node, String path) |
192 |
|
throws AJAXException |
193 |
|
{ |
194 |
0 |
int count = 0; |
195 |
|
try |
196 |
|
{ |
197 |
0 |
Link link = (Link)node; |
198 |
0 |
String title = getActionParameter(requestContext, "title"); |
199 |
0 |
if (isFieldModclass="keyword">ified(title, link.getTitle())) |
200 |
0 |
link.setTitle(title); |
201 |
0 |
String shortTitle = getActionParameter(requestContext, "short-title"); |
202 |
0 |
if (isFieldModclass="keyword">ified(shortTitle, link.getShortTitle())) |
203 |
0 |
link.setShortTitle(shortTitle); |
204 |
0 |
String url = getActionParameter(requestContext, "url"); |
205 |
0 |
if (isFieldModclass="keyword">ified(url, link.getUrl())) |
206 |
0 |
link.setUrl(url); |
207 |
0 |
String target = getActionParameter(requestContext, "target"); |
208 |
0 |
if (isFieldModclass="keyword">ified(target, link.getTarget())) |
209 |
0 |
link.setTarget(target); |
210 |
0 |
String hidden = getActionParameter(requestContext, "hidden"); |
211 |
0 |
if (isBooleanModclass="keyword">ified(hidden, link.isHidden())) |
212 |
0 |
link.setHidden(!link.isHidden()); |
213 |
0 |
count++; |
214 |
|
} |
215 |
0 |
catch (Exception e) |
216 |
|
{ |
217 |
0 |
throw new AJAXException(e); |
218 |
0 |
} |
219 |
0 |
return count; |
220 |
|
} |
221 |
|
|
222 |
|
} |