1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.exoplatform.ecm.webui.component.admin.taxonomy.action;
19
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.jcr.Node;
26 import javax.jcr.PathNotFoundException;
27 import javax.jcr.RepositoryException;
28 import javax.jcr.Session;
29 import javax.jcr.nodetype.ConstraintViolationException;
30
31 import org.exoplatform.ecm.resolver.JCRResourceResolver;
32 import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyManagerTrees;
33 import org.exoplatform.ecm.webui.component.admin.taxonomy.UITaxonomyTreeContainer;
34 import org.exoplatform.ecm.webui.component.admin.taxonomy.tree.info.UIPermissionTreeInfo;
35 import org.exoplatform.ecm.webui.form.UIDialogForm;
36 import org.exoplatform.ecm.webui.nodetype.selector.UINodeTypeSelector;
37 import org.exoplatform.ecm.webui.selector.ComponentSelector;
38 import org.exoplatform.ecm.webui.selector.UISelectable;
39 import org.exoplatform.ecm.webui.tree.selectone.UIOneNodePathSelector;
40 import org.exoplatform.ecm.webui.utils.DialogFormUtil;
41 import org.exoplatform.ecm.utils.lock.LockUtil;
42 import org.exoplatform.ecm.webui.utils.PermissionUtil;
43 import org.exoplatform.ecm.webui.utils.Utils;
44 import org.exoplatform.portal.webui.util.Util;
45 import org.exoplatform.resolver.ResourceResolver;
46 import org.exoplatform.services.cms.BasePath;
47 import org.exoplatform.services.cms.CmsService;
48 import org.exoplatform.services.cms.JcrInputProperty;
49 import org.exoplatform.services.cms.actions.ActionServiceContainer;
50 import org.exoplatform.services.cms.impl.DMSConfiguration;
51 import org.exoplatform.services.cms.taxonomy.TaxonomyService;
52 import org.exoplatform.services.cms.taxonomy.TaxonomyTreeData;
53 import org.exoplatform.services.cms.taxonomy.impl.TaxonomyAlreadyExistsException;
54 import org.exoplatform.services.cms.taxonomy.impl.TaxonomyNodeAlreadyExistsException;
55 import org.exoplatform.services.cms.templates.TemplateService;
56 import org.exoplatform.services.jcr.RepositoryService;
57 import org.exoplatform.services.jcr.access.AccessControlEntry;
58 import org.exoplatform.services.jcr.access.PermissionType;
59 import org.exoplatform.services.jcr.core.ExtendedNode;
60 import org.exoplatform.services.jcr.ext.common.SessionProvider;
61 import org.exoplatform.services.jcr.ext.hierarchy.NodeHierarchyCreator;
62 import org.exoplatform.services.log.ExoLogger;
63 import org.exoplatform.services.log.Log;
64 import org.exoplatform.services.security.IdentityConstants;
65 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
66 import org.exoplatform.web.application.ApplicationMessage;
67 import org.exoplatform.webui.application.WebuiRequestContext;
68 import org.exoplatform.webui.config.annotation.ComponentConfig;
69 import org.exoplatform.webui.config.annotation.ComponentConfigs;
70 import org.exoplatform.webui.config.annotation.EventConfig;
71 import org.exoplatform.webui.core.UIApplication;
72 import org.exoplatform.webui.core.UIComponent;
73 import org.exoplatform.webui.core.UIContainer;
74 import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
75 import org.exoplatform.webui.event.Event;
76 import org.exoplatform.webui.event.Event.Phase;
77 import org.exoplatform.webui.event.EventListener;
78 import org.exoplatform.webui.form.UIFormInputBase;
79 import org.exoplatform.webui.form.UIFormMultiValueInputSet;
80 import org.exoplatform.webui.form.UIFormStringInput;
81
82
83
84
85
86
87
88 @ComponentConfigs( {
89 @ComponentConfig(type = UIFormMultiValueInputSet.class, id = "WYSIWYGRichTextMultipleInputset", events = {
90 @EventConfig(listeners = UIDialogForm.AddActionListener.class, phase = Phase.DECODE),
91 @EventConfig(listeners = UIFormMultiValueInputSet.RemoveActionListener.class, phase = Phase.DECODE) }),
92 @ComponentConfig(lifecycle = UIFormLifecycle.class, events = {
93 @EventConfig(listeners = UIActionForm.SaveActionListener.class),
94 @EventConfig(listeners = UIActionForm.PreviousViewPermissionActionListener.class, phase = Phase.DECODE),
95 @EventConfig(listeners = UIActionForm.NextViewTreeActionListener.class, phase = Phase.DECODE),
96 @EventConfig(listeners = UIDialogForm.OnchangeActionListener.class, phase = Phase.DECODE),
97 @EventConfig(listeners = UIActionForm.ShowComponentActionListener.class, phase = Phase.DECODE),
98 @EventConfig(listeners = UIActionForm.AddActionListener.class, phase = Phase.DECODE),
99 @EventConfig(listeners = UIActionForm.RemoveActionListener.class, phase = Phase.DECODE),
100 @EventConfig(listeners = UIActionForm.RemoveReferenceActionListener.class,
101 confirm = "DialogFormField.msg.confirm-delete", phase = Phase.DECODE) }) })
102 public class UIActionForm extends UIDialogForm implements UISelectable {
103
104 private String parentPath_ = "";
105
106 private String nodeTypeName_ = null;
107
108 private boolean isAddNew_;
109
110 private String scriptPath_ = null;
111
112 private String rootPath_ = null;
113
114 public static final String POPUP_COMPONENT = "PopupComponent";
115
116 public static final String EXO_ACTIONS = "exo:actions";
117 private static final Log LOG = ExoLogger.getLogger(UIActionForm.class.getName());
118 public UIActionForm() throws Exception {
119 setActions(new String[] { "PreviousViewPermission", "Save", "NextViewTree"});
120 }
121
122 public void createNewAction(Node parentNode, String actionType, boolean isAddNew) throws Exception {
123 reset();
124 nodeTypeName_ = actionType;
125 isAddNew_ = isAddNew;
126 componentSelectors.clear();
127 properties.clear();
128 getChildren().clear();
129 if (parentNode != null) parentPath_ = parentNode.getPath();
130 }
131
132 public void doSelect(String selectField, Object value) throws Exception {
133 isUpdateSelect = true;
134 UIComponent uicomponent = getChildById(selectField);
135 if (UIFormStringInput.class.isInstance(uicomponent))
136 ((UIFormStringInput)uicomponent).setValue(value.toString());
137 else if (UIFormMultiValueInputSet.class.isInstance(uicomponent)) {
138 ((UIFormMultiValueInputSet)uicomponent).setValue((ArrayList<String>)value);
139 }
140 UIActionTaxonomyManager uiManager = getAncestorOfType(UIActionTaxonomyManager.class);
141 uiManager.removeChildById(POPUP_COMPONENT);
142 }
143
144 public String getCurrentPath() throws Exception {
145 return parentPath_;
146 }
147
148 public void setCurrentPath(String path) {
149 parentPath_ = path;
150 }
151
152 public String getWorkspace() {
153 return getTaxoTreeData().getTaxoTreeWorkspace();
154 }
155
156 public String getRepositoryName() {
157 return getTaxoTreeData().getRepository();
158 }
159
160 public TaxonomyTreeData getTaxoTreeData() {
161 return getAncestorOfType(UITaxonomyTreeContainer.class).getTaxonomyTreeData();
162 }
163
164 private String getTaxonomyTreeHomePath() throws Exception{
165 TaxonomyTreeData taxoTreeData = getTaxoTreeData();
166 String workspace = taxoTreeData.getTaxoTreeWorkspace();
167 String homePath = taxoTreeData.getTaxoTreeHomePath();
168 String systemWorkspace = getAncestorOfType(UITaxonomyManagerTrees.class).getDmsSystemWorkspaceName();
169 if (workspace.equals(systemWorkspace) && homePath.length() == 0) {
170 homePath = getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH);
171 taxoTreeData.setTaxoTreeHomePath(homePath);
172 }
173 return (workspace + ":" + homePath);
174 }
175
176 private String getJcrPath(String path) {
177 NodeHierarchyCreator nodeHierarchyCreator = getApplicationComponent(NodeHierarchyCreator.class);
178 return nodeHierarchyCreator.getJcrPath(path);
179 }
180
181 public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) {
182 DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class);
183 String workspace = dmsConfiguration.getConfig().getSystemWorkspace();
184 return new JCRResourceResolver(workspace);
185 }
186
187 public String getTemplate() {
188 return getDialogPath();
189 }
190
191 public String getDialogPath() {
192 TemplateService templateService = getApplicationComponent(TemplateService.class);
193 String userName = Util.getPortalRequestContext().getRemoteUser();
194 String dialogPath = null;
195 if (nodeTypeName_ != null) {
196 try {
197 dialogPath = templateService.getTemplatePathByUser(true, nodeTypeName_, userName);
198 } catch (Exception e) {
199 if (LOG.isErrorEnabled()) {
200 LOG.error("Unexpected error", e);
201 }
202 }
203 }
204 return dialogPath;
205 }
206
207 public void onchange(Event<?> event) throws Exception {
208 setIsUpdateSelect(false);
209 }
210
211 public void renderField(String name) throws Exception {
212 UIComponent uiInput = findComponentById(name);
213 if ("homePath".equals(name)) {
214 TaxonomyTreeData taxoTreeData = getTaxoTreeData();
215 String homPath = getTaxonomyTreeHomePath();
216 if (homPath.endsWith("/"))
217 homPath = homPath.substring(0, homPath.length() - 1);
218 ((UIFormStringInput) uiInput).setValue(homPath + "/" + taxoTreeData.getTaxoTreeName());
219 }
220 super.renderField(name);
221 }
222
223 public String getTenmplateNodeType() {
224 return nodeTypeName_;
225 }
226
227 public String getPath() {
228 return scriptPath_;
229 }
230
231 public void setRootPath(String rootPath) {
232 rootPath_ = rootPath;
233 }
234
235 public String getRootPath() {
236 return rootPath_;
237 }
238
239 private void setPermissionAction(Node currentNode) throws Exception {
240 Session session = getSession();
241 Node exoActionNode = currentNode.getNode(EXO_ACTIONS);
242 if (PermissionUtil.canChangePermission(exoActionNode)) {
243 if (exoActionNode.canAddMixin("exo:privilegeable")) {
244 exoActionNode.addMixin("exo:privilegeable");
245 }
246 Map<String, String[]> perMap = new HashMap<String, String[]>();
247 List<String> permsList = new ArrayList<String>();
248 List<String> idList = new ArrayList<String>();
249 String identity = null;
250 for (AccessControlEntry accessEntry : ((ExtendedNode) currentNode).getACL().getPermissionEntries()) {
251 identity = accessEntry.getIdentity();
252 if (!idList.contains(identity)) {
253 idList.add(identity);
254 permsList = ((ExtendedNode) currentNode).getACL().getPermissions(identity);
255 if (IdentityConstants.SYSTEM.equals(identity)) {
256 if (!permsList.contains(PermissionType.REMOVE)) {
257 permsList.add(PermissionType.REMOVE);
258 }
259 } else {
260 permsList.remove(PermissionType.REMOVE);
261 }
262 perMap.put(accessEntry.getIdentity(), permsList.toArray(new String[permsList.size()]));
263 }
264 }
265
266 ((ExtendedNode) exoActionNode).setPermissions(perMap);
267 currentNode.save();
268 session.save();
269 }
270 }
271
272 public static class SaveActionListener extends EventListener<UIActionForm> {
273 public void execute(Event<UIActionForm> event) throws Exception {
274 UIActionForm uiActionForm = event.getSource();
275 UITaxonomyTreeContainer uiTaxonomyTreeContainer = uiActionForm.getAncestorOfType(UITaxonomyTreeContainer.class);
276 UIPermissionTreeInfo uiPermissionInfo = uiTaxonomyTreeContainer.findFirstComponentOfType(UIPermissionTreeInfo.class);
277 TaxonomyTreeData taxoTreeData = uiActionForm.getTaxoTreeData();
278 UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiActionForm.getAncestorOfType(UITaxonomyManagerTrees.class);
279 TaxonomyService taxonomyService = uiTaxonomyTreeContainer.getApplicationComponent(TaxonomyService.class);
280 String repository = uiActionForm.getApplicationComponent(RepositoryService.class)
281 .getCurrentRepository()
282 .getConfiguration()
283 .getName();
284 String dmsSysWorkspace = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class)
285 .getDmsSystemWorkspaceName();
286 UIApplication uiApp = uiTaxonomyTreeContainer.getAncestorOfType(UIApplication.class);
287 String name = taxoTreeData.getTaxoTreeName();
288 String workspace = taxoTreeData.getTaxoTreeWorkspace();
289 String homePath = taxoTreeData.getTaxoTreeHomePath();
290 if (homePath == null) {
291 homePath = "";
292 }
293 boolean isEditTree = taxoTreeData.isEdit();
294 if (homePath.length() == 0) {
295 if (dmsSysWorkspace.equals(workspace)) {
296 homePath = uiActionForm.getJcrPath(BasePath.TAXONOMIES_TREE_STORAGE_PATH);
297 } else {
298 uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.homepath-emty", null,
299 ApplicationMessage.WARNING));
300
301 return;
302 }
303 }
304 UIFormStringInput targetPathInput = uiActionForm.getUIStringInput("targetPath");
305 if (targetPathInput != null) {
306 String targetPath = targetPathInput.getValue();
307 if ((targetPath == null) || (targetPath.length() == 0)) {
308 uiApp.addMessage(new ApplicationMessage("UITaxonomyTreeMainForm.msg.targetPath-emty", null,
309 ApplicationMessage.WARNING));
310
311 return;
312 }
313 }
314 boolean isChangeLocation = false;
315 try {
316 if (!isEditTree) {
317 uiTaxonomyTreeContainer.addTaxonomyTree(name, workspace, homePath, uiPermissionInfo.getPermBeans());
318 } else {
319 isChangeLocation = uiTaxonomyTreeContainer.updateTaxonomyTree(name,
320 workspace,
321 homePath,
322 taxoTreeData.getTaxoTreeActionName());
323 }
324 } catch (PathNotFoundException e) {
325 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.path-invalid", null,
326 ApplicationMessage.WARNING));
327
328 return;
329 } catch (TaxonomyAlreadyExistsException e) {
330 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.taxonomy-existed", null,
331 ApplicationMessage.WARNING));
332
333 return;
334 } catch (TaxonomyNodeAlreadyExistsException e) {
335 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.taxonomy-node-existed", null,
336 ApplicationMessage.WARNING));
337
338 return;
339 } catch (ConstraintViolationException cViolationException) {
340 Object[] args = {name, homePath, workspace};
341 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.constraint-violation-exception", args,
342 ApplicationMessage.WARNING));
343
344 return;
345 }
346
347 Node currentNode = taxonomyService.getTaxonomyTree(name, true);
348 Map<String, JcrInputProperty> sortedInputs = DialogFormUtil.prepareMap(uiActionForm
349 .getChildren(), uiActionForm.getInputProperties(), uiActionForm.getInputOptions());
350 ActionServiceContainer actionServiceContainer = uiActionForm.getApplicationComponent(ActionServiceContainer.class);
351
352
353 if (uiActionForm.nodeTypeName_.equals(taxoTreeData.getTaxoTreeActionTypeName()) && !isChangeLocation) {
354 String actionNameInput = (String) (sortedInputs.get("/node/exo:name")).getValue();
355 if (!Utils.isNameValid(actionNameInput, Utils.SPECIALCHARACTER)) {
356 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.name-not-allowed", null,
357 ApplicationMessage.WARNING));
358
359 return;
360 }
361
362 try {
363 CmsService cmsService = uiActionForm.getApplicationComponent(CmsService.class);
364 Node storedHomeNode = uiActionForm.getNode().getParent();
365 cmsService.storeNode(uiActionForm.nodeTypeName_, storedHomeNode, sortedInputs, false);
366 storedHomeNode.getSession().save();
367 } catch (Exception e) {
368 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.canotChangeActionId", null,
369 ApplicationMessage.WARNING));
370
371 return;
372 }
373 } else {
374
375 if (!isChangeLocation) {
376 if (actionServiceContainer.hasActions(currentNode)) {
377 actionServiceContainer.removeAction(currentNode, taxoTreeData.getTaxoTreeActionName(), repository);
378 }
379 }
380
381 Session session = currentNode.getSession();
382 if (uiActionForm.getCurrentPath().length() == 0) {
383 uiActionForm.setCurrentPath(currentNode.getPath());
384 }
385 if (!PermissionUtil.canAddNode(currentNode) || !PermissionUtil.canSetProperty(currentNode)) {
386 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.no-permission-add", null));
387
388 return;
389 }
390 if (currentNode.isLocked()) {
391 String lockToken = LockUtil.getLockToken(currentNode);
392 if (lockToken != null)
393 session.addLockToken(lockToken);
394 }
395
396 try {
397 JcrInputProperty rootProp = sortedInputs.get("/node");
398 String actionName = (String) (sortedInputs.get("/node/exo:name")).getValue();
399 if (!Utils.isNameValid(actionName, Utils.SPECIALCHARACTER)) {
400 if (!isEditTree) {
401 Node taxonomyTreeNode = taxonomyService.getTaxonomyTree(name, true);
402 actionServiceContainer.removeAction(taxonomyTreeNode, repository);
403 taxonomyService.removeTaxonomyTree(name);
404 }
405 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.name-not-allowed", null,
406 ApplicationMessage.WARNING));
407
408 return;
409 }
410
411 if (rootProp == null) {
412 rootProp = new JcrInputProperty();
413 rootProp.setJcrPath("/node");
414 rootProp.setValue(actionName);
415 sortedInputs.put("/node", rootProp);
416 } else {
417 rootProp.setValue(actionName);
418 }
419 if (currentNode.hasNode(EXO_ACTIONS)) {
420 if (currentNode.getNode(EXO_ACTIONS).hasNode(actionName)) {
421 Object[] args = { actionName };
422 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.existed-action", args,
423 ApplicationMessage.WARNING));
424
425 return;
426 }
427 }
428 if (currentNode.isNew()) {
429 String[] args = { currentNode.getPath() };
430 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.unable-add-action", args));
431
432 return;
433 }
434 boolean alreadyExistEXO_ACTION = currentNode.hasNode(Utils.EXO_ACTIONS);
435 actionServiceContainer.addAction(currentNode, uiActionForm.nodeTypeName_, sortedInputs);
436 session.save();
437
438 uiActionForm.setPermissionAction(currentNode);
439 Node actionNode = actionServiceContainer.getAction(currentNode, actionName);
440 taxoTreeData.setTaxoTreeActionName(actionNode.getName());
441 uiActionForm.setIsOnchange(false);
442 uiActionForm.setNodePath(actionNode.getPath());
443 uiActionForm.createNewAction(currentNode, actionNode.getPrimaryNodeType().getName(), false);
444 uiActionForm.reset();
445 if (!alreadyExistEXO_ACTION)
446 addPermission(currentNode.getNode(Utils.EXO_ACTIONS), Utils.EXO_PERMISSIONS,
447 Util.getPortalRequestContext().getRemoteUser(), uiActionForm);
448 session.save();
449
450 } catch (ConstraintViolationException cex) {
451 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.constraint-violation-exception",
452 null,
453 ApplicationMessage.WARNING));
454
455 return;
456 } catch (RepositoryException repo) {
457 String key = "UIActionForm.msg.repository-exception";
458 uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING));
459
460 return;
461 } catch (NumberFormatException nume) {
462 String key = "UIActionForm.msg.numberformat-exception";
463 uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING));
464
465 return;
466 } catch (Exception e) {
467 if (LOG.isErrorEnabled()) {
468 LOG.error("Unexpected error", e);
469 }
470 uiApp.addMessage(new ApplicationMessage("UIActionForm.msg.unable-add", null));
471 return;
472 }
473 }
474 taxoTreeData.setEdit(true);
475 uiTaxonomyTreeContainer.refresh();
476 uiTaxonomyTreeContainer.viewStep(4);
477 uiTaxonomyManagerTrees.update();
478 event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees);
479 }
480
481 private void addPermission(Node node, String propertyName, String userId, UIActionForm uiForm) throws Exception {
482 if (PermissionUtil.canChangePermission(node)) {
483 if (node.canAddMixin("exo:privilegeable")) {
484 node.addMixin("exo:privilegeable");
485 }
486 String removePermission = PermissionType.REMOVE;
487 List<String> permissionList = ((ExtendedNode)node).getACL().getPermissions(userId);
488
489 if (permissionList == null)
490 permissionList = new ArrayList<String>();
491
492 permissionList.add(removePermission);
493
494 ((ExtendedNode)node).setPermission(userId, permissionList.toArray(new String[]{}));
495 node.getSession().save();
496 }
497 }
498 }
499
500 public static class PreviousViewPermissionActionListener extends EventListener<UIActionForm> {
501 public void execute(Event<UIActionForm> event) throws Exception {
502 UITaxonomyTreeContainer uiTaxonomyTreeContainer = event.getSource().getAncestorOfType(UITaxonomyTreeContainer.class);
503 UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class);
504 uiTaxonomyTreeContainer.viewStep(2);
505 event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees);
506 }
507 }
508
509 public static class NextViewTreeActionListener extends EventListener<UIActionForm> {
510 public void execute(Event<UIActionForm> event) throws Exception {
511 UITaxonomyTreeContainer uiTaxonomyTreeContainer = event.getSource().getAncestorOfType(UITaxonomyTreeContainer.class);
512 UITaxonomyManagerTrees uiTaxonomyManagerTrees = uiTaxonomyTreeContainer.getAncestorOfType(UITaxonomyManagerTrees.class);
513 TaxonomyTreeData taxoTreeData = uiTaxonomyTreeContainer.getTaxonomyTreeData();
514 UIApplication uiApp = uiTaxonomyTreeContainer.getAncestorOfType(UIApplication.class);
515 if (taxoTreeData.isEdit()) {
516 uiTaxonomyTreeContainer.viewStep(4);
517 } else {
518 String key = "UIActionForm.msg.not-created-tree";
519 uiApp.addMessage(new ApplicationMessage(key, null, ApplicationMessage.WARNING));
520
521 return;
522 }
523 event.getRequestContext().addUIComponentToUpdateByAjax(uiTaxonomyManagerTrees);
524 }
525 }
526
527 public static class ShowComponentActionListener extends EventListener<UIActionForm> {
528 public void execute(Event<UIActionForm> event) throws Exception {
529 UIActionForm uiForm = event.getSource();
530 UIActionTaxonomyManager uiManager = uiForm.getAncestorOfType(UIActionTaxonomyManager.class);
531 uiForm.isShowingComponent = true;
532 String fieldName = event.getRequestContext().getRequestParameter(OBJECTID);
533 Map fieldPropertiesMap = uiForm.componentSelectors.get(fieldName);
534 String classPath = (String) fieldPropertiesMap.get("selectorClass");
535 String rootPath = (String) fieldPropertiesMap.get("rootPath");
536 ClassLoader cl = Thread.currentThread().getContextClassLoader();
537 Class clazz = Class.forName(classPath, true, cl);
538 UIComponent uiComp = uiManager.createUIComponent(clazz, null, null);
539 String repositoryName = uiForm.getApplicationComponent(RepositoryService.class)
540 .getCurrentRepository()
541 .getConfiguration()
542 .getName();
543 String selectorParams = (String) fieldPropertiesMap.get("selectorParams");
544 if (uiComp instanceof UIOneNodePathSelector) {
545 SessionProvider provider = WCMCoreUtils.getSystemSessionProvider();
546 String wsFieldName = (String) fieldPropertiesMap.get("workspaceField");
547 String wsName = "";
548 if (wsFieldName != null && wsFieldName.length() > 0) {
549 wsName = (String) uiForm.<UIFormInputBase> getUIInput(wsFieldName).getValue();
550 ((UIOneNodePathSelector) uiComp).setIsDisable(wsName, true);
551 }
552 String[] filterType = new String[] {Utils.NT_FOLDER, Utils.NT_UNSTRUCTURED};
553 ((UIOneNodePathSelector) uiComp).setAcceptedNodeTypesInPathPanel(filterType);
554 ((UIOneNodePathSelector) uiComp).setAcceptedNodeTypesInTree(filterType);
555 if (selectorParams != null) {
556 String[] arrParams = selectorParams.split(",");
557 if (arrParams.length == 4) {
558 wsName = arrParams[1];
559 rootPath = arrParams[2];
560 ((UIOneNodePathSelector) uiComp).setIsDisable(wsName, true);
561 if (arrParams[3].indexOf(";") > -1) {
562 ((UIOneNodePathSelector) uiComp).setAcceptedMimeTypes(arrParams[3].split(";"));
563 } else {
564 ((UIOneNodePathSelector) uiComp).setAcceptedMimeTypes(new String[] { arrParams[3] });
565 }
566 }
567 }
568 if (rootPath == null)
569 rootPath = "/";
570 ((UIOneNodePathSelector) uiComp).setRootNodeLocation(repositoryName, wsName, rootPath);
571 ((UIOneNodePathSelector) uiComp).setShowRootPathSelect(true);
572 ((UIOneNodePathSelector) uiComp).init(provider);
573 } else if (uiComp instanceof UINodeTypeSelector) {
574 ((UINodeTypeSelector)uiComp).setRepositoryName(repositoryName);
575 UIFormMultiValueInputSet uiFormMultiValueInputSet = uiForm.getChildById(fieldName);
576 List values = uiFormMultiValueInputSet.getValue();
577 ((UINodeTypeSelector)uiComp).init(1, values);
578 }
579 uiManager.initPopupComponent(uiComp, UIActionForm.POPUP_COMPONENT);
580 String param = "returnField=" + fieldName;
581 String[] params = selectorParams == null ? new String[]{param} : new String[]{param, "selectorParams=" + selectorParams};
582 ((ComponentSelector)uiComp).setSourceComponent(uiForm, params);
583 if (uiForm.isAddNew_) {
584 UIContainer uiParent = uiManager.getParent();
585 uiParent.setRenderedChild(uiManager.getId());
586 }
587 event.getRequestContext().addUIComponentToUpdateByAjax(uiManager);
588 }
589 }
590
591 public static class RemoveReferenceActionListener extends EventListener<UIActionForm> {
592 public void execute(Event<UIActionForm> event) throws Exception {
593 UIActionForm uiForm = event.getSource() ;
594 uiForm.isRemovePreference = true;
595 String fieldName = event.getRequestContext().getRequestParameter(OBJECTID) ;
596 UIComponent uicomponent = uiForm.getChildById(fieldName);
597 if (UIFormStringInput.class.isInstance(uicomponent))
598 ((UIFormStringInput)uicomponent).setValue(null);
599 else if (UIFormMultiValueInputSet.class.isInstance(uicomponent)) {
600 ((UIFormMultiValueInputSet)uicomponent).setValue(new ArrayList<String>());
601 }
602 event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent()) ;
603 }
604 }
605
606 public static class AddActionListener extends EventListener<UIActionForm> {
607 public void execute(Event<UIActionForm> event) throws Exception {
608 UIActionForm uiForm = event.getSource();
609 event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent());
610 }
611 }
612
613 public static class RemoveActionListener extends EventListener<UIActionForm> {
614 public void execute(Event<UIActionForm> event) throws Exception {
615 UIActionForm uiForm = event.getSource();
616 event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent());
617 }
618 }
619
620 }