1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.component.explorer.control.action;
18
19 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
20 import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
21 import org.exoplatform.ecm.webui.component.explorer.control.filter.CanSetPropertyFilter;
22 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter;
23 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsDocumentFilter;
24 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsContainBinaryFilter;
25 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsEditableFilter;
26 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter;
27 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter;
28 import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter;
29 import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
30 import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
31 import org.exoplatform.web.application.ApplicationMessage;
32 import org.exoplatform.webui.application.WebuiRequestContext;
33 import org.exoplatform.webui.config.annotation.ComponentConfig;
34 import org.exoplatform.webui.config.annotation.EventConfig;
35 import org.exoplatform.webui.core.UIApplication;
36 import org.exoplatform.webui.core.UIComponent;
37 import org.exoplatform.webui.event.Event;
38 import org.exoplatform.webui.ext.filter.UIExtensionFilter;
39 import org.exoplatform.webui.ext.filter.UIExtensionFilters;
40 import org.exoplatform.webui.ext.manager.UIAbstractManager;
41 import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
42
43 import javax.jcr.AccessDeniedException;
44 import javax.jcr.Node;
45 import javax.jcr.PathNotFoundException;
46 import javax.jcr.RepositoryException;
47 import javax.jcr.Session;
48 import javax.jcr.ValueFormatException;
49 import java.util.Arrays;
50 import java.util.List;
51 import java.util.regex.Matcher;
52
53
54
55
56
57
58
59
60 @ComponentConfig(
61 events = {
62 @EventConfig(listeners = EditPropertyActionComponent.EditPropertyActionListener.class)
63 }
64 )
65
66 public class EditPropertyActionComponent extends UIAbstractManagerComponent {
67
68 private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {
69 new IsDocumentFilter(), new IsEditableFilter(), new CanSetPropertyFilter(),
70 new IsNotLockedFilter(), new IsCheckedOutFilter(), new IsNotInTrashFilter(), new IsNotEditingDocumentFilter(),
71 new IsContainBinaryFilter() });
72
73 @UIExtensionFilters
74 public static List<UIExtensionFilter> getFilters() {
75 return FILTERS;
76 }
77
78 public static class EditPropertyActionListener extends UIActionBarActionListener<EditPropertyActionComponent> {
79 public void processEvent(Event<EditPropertyActionComponent> event) throws Exception {
80 EditPropertyActionComponent uicomp = event.getSource();
81 String nodePath = event.getRequestContext().getRequestParameter(OBJECTID);
82 UIJCRExplorer uiExplorer = uicomp.getAncestorOfType(UIJCRExplorer.class);
83 Node selectedNode = null;
84 if (nodePath != null && nodePath.length() != 0) {
85 Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(nodePath);
86 String wsName = null;
87 if (matcher.find()) {
88 wsName = matcher.group(1);
89 nodePath = matcher.group(2);
90 } else {
91 throw new IllegalArgumentException("The ObjectId is invalid '" + nodePath + "'");
92 }
93 Session session = uiExplorer.getSessionByWorkspace(wsName);
94 UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class);
95 try {
96
97 selectedNode = uiExplorer.getNodeByPath(nodePath, session);
98 } catch (PathNotFoundException path) {
99 uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.path-not-found-exception", null,
100 ApplicationMessage.WARNING));
101
102 return;
103 } catch (AccessDeniedException ace) {
104 uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.null-exception", null,
105 ApplicationMessage.WARNING));
106
107 return;
108 } catch (Exception e) {
109 JCRExceptionManager.process(uiApp, e);
110 return;
111 }
112 }
113 if (selectedNode == null) selectedNode = uiExplorer.getCurrentNode();
114 uiExplorer.setSelectNode(selectedNode.getPath());
115 UIApplication uiApp = uicomp.getAncestorOfType(UIApplication.class);
116 editDocument(event, null, uicomp, uiExplorer, selectedNode, uiApp);
117 }
118 }
119
120 @SuppressWarnings("unchecked")
121 public static void editDocument(Event <? extends UIComponent> event,
122 WebuiRequestContext context,
123 UIComponent comp,
124 UIJCRExplorer uiExplorer,
125 Node selectedNode,
126 UIApplication uiApp) throws Exception{
127 EditDocumentActionComponent.editDocument(event, context, comp, uiExplorer, selectedNode, uiApp);
128 }
129
130 @Override
131 public Class<? extends UIAbstractManager> getUIAbstractManagerClass() {
132 return null;
133 }
134 }