1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wcm.webui.selector.content.multi;
18
19 import javax.jcr.ItemNotFoundException;
20 import javax.jcr.Node;
21 import javax.jcr.RepositoryException;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.exoplatform.ecm.utils.text.Text;
25 import org.exoplatform.ecm.webui.selector.UISelectable;
26 import org.exoplatform.services.cms.drives.DriveData;
27 import org.exoplatform.services.cms.drives.ManageDriveService;
28 import org.exoplatform.services.cms.link.LinkManager;
29 import org.exoplatform.services.log.ExoLogger;
30 import org.exoplatform.services.log.Log;
31 import org.exoplatform.services.wcm.publication.WCMComposer;
32 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
33 import org.exoplatform.wcm.webui.Utils;
34 import org.exoplatform.wcm.webui.selector.content.UIContentBrowsePanel;
35 import org.exoplatform.wcm.webui.selector.content.UIContentSelector;
36 import org.exoplatform.webui.config.annotation.ComponentConfig;
37 import org.exoplatform.webui.config.annotation.EventConfig;
38 import org.exoplatform.webui.core.lifecycle.Lifecycle;
39 import org.exoplatform.webui.event.Event;
40 import org.exoplatform.webui.event.EventListener;
41
42
43
44 @ComponentConfig(
45 lifecycle = Lifecycle.class,
46 template = "classpath:groovy/wcm/webui/selector/content/multi/UIContentBrowsePanel.gtmpl",
47 events = {
48 @EventConfig(listeners = UIContentBrowsePanel.ChangeContentTypeActionListener.class),
49 @EventConfig(listeners = UIContentBrowsePanelMulti.SelectActionListener.class),
50 @EventConfig(listeners = UIContentBrowsePanelMulti.CloseActionListener.class),
51 @EventConfig(listeners = UIContentBrowsePanelMulti.SaveTemporaryActionListener.class)
52 }
53 )
54
55 public class UIContentBrowsePanelMulti extends UIContentBrowsePanel {
56
57 private static final Log LOG = ExoLogger.getLogger(UIContentBrowsePanelMulti.class.getName());
58
59
60 private String itemPaths;
61 private String itemTarget;
62
63 private String deleteConfirmationMsg = "UIBrowserPanel.Confirm.Delete";
64
65
66
67
68
69 public String getItemPaths() {
70 return itemPaths;
71 }
72 private String _initPath = "";
73 private String _initDrive = "";
74
75 public void setInitPath(String initDrive, String initPath) {
76 this._initPath = initPath;
77 this._initDrive = initDrive;
78 }
79
80 public String getInitDrive() { return this._initDrive; }
81 public String getInitPath() { return this._initPath; }
82
83
84
85
86
87
88 public void setItemPaths(String itemPaths) {
89 this.itemPaths = itemPaths;
90 setItemTargetPath(getTargetPath(itemPaths));
91 }
92
93 public void setItemTargetPath(String _itemTarget) {
94 this.itemTarget = _itemTarget;
95 }
96 public String getItemTargetPath(){
97 return this.itemTarget;
98 }
99
100
101
102
103
104 protected String getTargetPath(String savedItems) {
105 int i, n;
106 LinkManager linkManager;
107 String[] savedItemList =savedItems.split(";");
108 String savedItem;
109 n = savedItemList.length;
110 StringBuilder result = new StringBuilder("");
111 linkManager = WCMCoreUtils.getService(LinkManager.class);
112 for (i = 0; i<n; i++) {
113 savedItem = savedItemList[i];
114 String[] locations = (savedItem == null) ? null : savedItem.split(":");
115 Node node = (locations != null && locations.length >= 3) ? Utils.getViewableNodeByComposer(
116 locations[0], locations[1], locations[2]) : null;
117 savedItem = StringUtils.EMPTY;
118 if (node != null){
119 try {
120 savedItem = node.getPath();
121 if (linkManager.isLink(node)) {
122 node = linkManager.getTarget(node);
123 savedItem = node.getPath();
124 }
125 } catch (ItemNotFoundException e){
126 savedItem = StringUtils.EMPTY;
127 } catch (RepositoryException e){
128 savedItem = StringUtils.EMPTY;
129 }
130 }
131 result.append(savedItem).append(";");
132 }
133 return result.toString();
134 }
135
136
137
138
139
140
141
142
143
144
145 public static class SelectActionListener extends EventListener<UIContentBrowsePanelMulti> {
146
147
148
149
150 public void execute(Event<UIContentBrowsePanelMulti> event) throws Exception {
151 UIContentBrowsePanelMulti contentBrowsePanelMulti = event.getSource();
152 String returnFieldName = contentBrowsePanelMulti.getReturnFieldName();
153 ((UISelectable)(contentBrowsePanelMulti.getSourceComponent())).doSelect(returnFieldName, contentBrowsePanelMulti.getItemPaths());
154 }
155 }
156
157
158
159
160
161
162
163
164
165
166
167 public static class SaveTemporaryActionListener extends EventListener<UIContentBrowsePanelMulti> {
168
169
170
171
172 public void execute(Event<UIContentBrowsePanelMulti> event) throws Exception {
173 UIContentBrowsePanelMulti contentBrowsePanelMulti = event.getSource();
174 Node node = null;
175 String itemPathtemp = "";
176
177 String operationType = event.getRequestContext().getRequestParameter("oper");
178 String dPath = event.getRequestContext().getRequestParameter("path");
179 String iDriver = event.getRequestContext().getRequestParameter("driverName");
180 String iPath = event.getRequestContext().getRequestParameter("currentPath");
181 String tempIPath = iPath;
182 String[] locations = (iPath == null) ? null : iPath.split(":");
183 if (operationType.equals("clean") && contentBrowsePanelMulti.getItemPaths() != null) {
184 contentBrowsePanelMulti.setItemPaths("");
185 return;
186 }
187 if (iDriver != null && iDriver.length() > 0) {
188 if (locations != null && locations.length > 2)
189 node = Utils.getViewableNodeByComposer(Text.escapeIllegalJcrChars(locations[0]),
190 Text.escapeIllegalJcrChars(locations[1]),
191 Text.escapeIllegalJcrChars(locations[2]),
192 WCMComposer.BASE_VERSION);
193
194 if (node != null) {
195 iPath = fixPath(iDriver, node.getPath(), contentBrowsePanelMulti);
196 contentBrowsePanelMulti.setInitPath(iDriver, iPath);
197 } else {
198 contentBrowsePanelMulti.setInitPath(iDriver, iPath);
199 }
200 } else
201 contentBrowsePanelMulti.setInitPath("", "");
202 if (operationType.equals("add") && contentBrowsePanelMulti.getItemPaths() != null) {
203 itemPathtemp = contentBrowsePanelMulti.getItemPaths().concat(tempIPath).concat(";");
204 contentBrowsePanelMulti.setItemPaths(itemPathtemp);
205 }
206 else if (operationType.equals("delete") && contentBrowsePanelMulti.getItemPaths() != null) {
207 itemPathtemp = contentBrowsePanelMulti.getItemPaths();
208 itemPathtemp = StringUtils.remove(itemPathtemp, dPath.concat(";"));
209 contentBrowsePanelMulti.setItemPaths(itemPathtemp);
210 }
211 else
212 contentBrowsePanelMulti.setItemPaths(tempIPath.concat(";"));
213 UIContentSelector contentSelector = contentBrowsePanelMulti.getAncestorOfType(UIContentSelector.class);
214 contentSelector.setSelectedTab(contentBrowsePanelMulti.getId());
215 }
216
217 private String fixPath(String driveName,
218 String path,
219 UIContentBrowsePanelMulti uiBrowser) throws Exception {
220 if (path == null || path.length() == 0)
221 return "";
222 path = Text.escapeIllegalJcrChars(path);
223 ManageDriveService managerDriveService = uiBrowser.getApplicationComponent(ManageDriveService.class);
224 DriveData driveData = managerDriveService.getDriveByName(driveName);
225 if (!path.startsWith(driveData.getHomePath()))
226 return "";
227 if ("/".equals(driveData.getHomePath()))
228 return path;
229 return path.substring(driveData.getHomePath().length());
230 }
231 }
232
233 public String getDeleteConfirmationMsg() {
234 return org.exoplatform.ecm.webui.utils.Utils.getResourceBundle(org.exoplatform.ecm.webui.utils.Utils.LOCALE_WEBUI_DMS,
235 deleteConfirmationMsg,
236 UIContentBrowsePanelMulti.class.getClassLoader());
237 }
238
239 public String getLocaleMsg(String key) {
240 return org.exoplatform.ecm.webui.utils.Utils.getResourceBundle(org.exoplatform.ecm.webui.utils.Utils.LOCALE_WEBUI_DMS,
241 key,
242 UIContentBrowsePanelMulti.class.getClassLoader());
243 }
244
245
246
247
248
249
250
251
252
253 public static class CloseActionListener extends EventListener<UIContentBrowsePanelMulti> {
254
255
256
257
258 public void execute(Event<UIContentBrowsePanelMulti> event) throws Exception {
259 UIContentBrowsePanelMulti contentBrowsePanelMulti = event.getSource();
260 ((UISelectable)(contentBrowsePanelMulti.getSourceComponent())).doSelect(null, null);
261 }
262 }
263
264 }