View Javadoc
1   /*
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17    package org.exoplatform.ecm.webui.component.explorer;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.exoplatform.ecm.jcr.model.Preference;
21  import org.exoplatform.ecm.utils.text.Text;
22  import org.exoplatform.ecm.webui.component.explorer.control.UIActionBar;
23  import org.exoplatform.ecm.webui.component.explorer.control.UIAddressBar;
24  import org.exoplatform.ecm.webui.component.explorer.control.UIControl;
25  import org.exoplatform.ecm.webui.component.explorer.control.action.AddDocumentActionComponent;
26  import org.exoplatform.ecm.webui.component.explorer.control.action.EditDocumentActionComponent;
27  import org.exoplatform.ecm.webui.component.explorer.control.action.EditPropertyActionComponent;
28  import org.exoplatform.ecm.webui.component.explorer.sidebar.UITreeExplorer;
29  import org.exoplatform.ecm.webui.component.explorer.versions.UIVersionInfo;
30  import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
31  import org.exoplatform.ecm.webui.utils.Utils;
32  import org.exoplatform.portal.application.PortalRequestContext;
33  import org.exoplatform.portal.webui.util.Util;
34  import org.exoplatform.services.cms.documents.AutoVersionService;
35  import org.exoplatform.services.cms.drives.DriveData;
36  import org.exoplatform.services.cms.drives.ManageDriveService;
37  import org.exoplatform.services.cms.drives.impl.ManageDriveServiceImpl;
38  import org.exoplatform.services.cms.link.NodeFinder;
39  import org.exoplatform.services.cms.views.ManageViewService;
40  import org.exoplatform.services.jcr.RepositoryService;
41  import org.exoplatform.services.log.ExoLogger;
42  import org.exoplatform.services.log.Log;
43  import org.exoplatform.services.security.ConversationState;
44  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
45  import org.exoplatform.web.application.ApplicationMessage;
46  import org.exoplatform.webui.application.WebuiApplication;
47  import org.exoplatform.webui.application.WebuiRequestContext;
48  import org.exoplatform.webui.application.portlet.PortletRequestContext;
49  import org.exoplatform.webui.config.annotation.ComponentConfig;
50  import org.exoplatform.webui.core.UIApplication;
51  import org.exoplatform.webui.core.UIPopupContainer;
52  import org.exoplatform.webui.core.UIPortletApplication;
53  import org.exoplatform.webui.core.UIRightClickPopupMenu;
54  import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
55  import org.exoplatform.webui.core.model.SelectItemOption;
56  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
57  
58  import javax.jcr.*;
59  import javax.portlet.PortletMode;
60  import javax.portlet.PortletPreferences;
61  import java.util.*;
62  import java.util.regex.Matcher;
63  import java.util.regex.Pattern;
64  
65  @ComponentConfig(
66      lifecycle = UIApplicationLifecycle.class
67  )
68  public class UIJCRExplorerPortlet extends UIPortletApplication {
69  
70    /**
71     * Logger.
72     */
73    private static final Log LOG  = ExoLogger.getLogger(UIJCRExplorerPortlet.class.getName());
74  
75    final static public String ISDIRECTLY_DRIVE   = "isDirectlyDrive";
76  
77    final static public String DRIVE_NAME         = "driveName";
78  
79    final static public String USECASE            = "usecase";
80  
81    final static public String JAILED             = "jailed";
82  
83    final static public String SELECTION          = "selection";
84  
85    final static public String PERSONAL           = "personal";
86  
87    final static public String PARAMETERIZE       = "parameterize";
88  
89    final static public String PARAMETERIZE_PATH  = "nodePath";
90  
91    final static public String SHOW_TOP_BAR       = "showTopBar";
92  
93    final static public String SHOW_ACTION_BAR    = "showActionBar";
94  
95    final static public String SHOW_SIDE_BAR      = "showSideBar";
96  
97    final static public String SHOW_FILTER_BAR    = "showFilterBar";
98  
99    final static private String DOC_NOT_FOUND    = "doc-not-found";
100 
101   private NodeFinder nodeFinder;
102 
103   private String backTo ="";
104 
105   private boolean flagSelect = false;
106 
107   private Pattern driveParameteriedPathPattern = Pattern.compile(".*\\$\\{(.*)\\}.*");
108 
109   public UIJCRExplorerPortlet() throws Exception {
110     if (Util.getPortalRequestContext().getRemoteUser() != null) {
111       UIJcrExplorerContainer explorerContainer = addChild(UIJcrExplorerContainer.class, null, null);
112       explorerContainer.initExplorer();
113       addChild(UIJcrExplorerEditContainer.class, null, null).setRendered(false);
114     }
115     nodeFinder = getApplicationComponent(NodeFinder.class);
116   }
117 
118   public boolean isFlagSelect() { return flagSelect; }
119 
120   public void setFlagSelect(boolean flagSelect) { this.flagSelect = flagSelect; }
121 
122   public boolean isShowTopBar() {
123     PortletPreferences portletpref = getPortletPreferences();
124     return Boolean.valueOf(portletpref.getValue(UIJCRExplorerPortlet.SHOW_TOP_BAR, "false"));
125   }
126 
127   public boolean isShowActionBar() {
128     PortletPreferences portletpref = getPortletPreferences();
129     return Boolean.valueOf(portletpref.getValue(UIJCRExplorerPortlet.SHOW_ACTION_BAR, "false")) &&
130            (!this.findFirstComponentOfType(UIJCRExplorer.class).isAddingDocument() ||
131              this.findFirstComponentOfType(UIWorkingArea.class).getChild(UIActionBar.class).hasBackButton());
132   }
133 
134   public boolean isShowSideBar() {
135     PortletPreferences portletpref = getPortletPreferences();
136     return Boolean.valueOf(portletpref.getValue(UIJCRExplorerPortlet.SHOW_SIDE_BAR, "false"));
137   }
138 
139   public boolean isShowFilterBar() {
140     PortletPreferences portletpref = getPortletPreferences();
141     return Boolean.valueOf(portletpref.getValue(UIJCRExplorerPortlet.SHOW_FILTER_BAR, "false"));
142   }
143   public String getBacktoValue() {
144     return backTo;
145   }
146   public void  processRender(WebuiApplication app, WebuiRequestContext context) throws Exception {
147     if (Util.getPortalRequestContext().getRemoteUser() == null) {
148       ((PortletRequestContext)context).getWriter().write(
149         String.format("<p style='text-align:center'>%s</p>",
150         context.getApplicationResourceBundle().getString("UIJCRExplorerPortlet.msg.anonymous-access-denied")));
151       return;
152     }
153     
154     UIJcrExplorerContainer explorerContainer = getChild(UIJcrExplorerContainer.class);
155     UIJcrExplorerEditContainer editContainer = getChild(UIJcrExplorerEditContainer.class);
156     PortletRequestContext portletReqContext = (PortletRequestContext) context ;
157     Map<String, String> map = getElementByContext(context);
158     PortalRequestContext pcontext = Util.getPortalRequestContext();
159     String backToValue = Util.getPortalRequestContext().getRequestParameter(org.exoplatform.ecm.webui.utils.Utils.URL_BACKTO);
160     
161     if (!portletReqContext.useAjax()) {
162         backTo = backToValue;
163     }
164     HashMap<String, String> changeDrive = (HashMap<String, String>)pcontext.getAttribute("jcrexplorer-show-document");
165     if (changeDrive!=null) {
166       map = changeDrive;
167       context.setAttribute("jcrexplorer-show-document", null);
168     }
169     if (portletReqContext.getApplicationMode() == PortletMode.VIEW) {
170       if (map.size() > 0) {
171         showDocument(context, map);
172       } else {
173         initwhenDirect(explorerContainer, editContainer);
174       }
175       explorerContainer.setRendered(true);
176       UIJCRExplorer uiExplorer = explorerContainer.getChild(UIJCRExplorer.class);
177       if(uiExplorer != null) {
178         try {
179           uiExplorer.getSession();
180           try {
181             uiExplorer.getSession().getItem(uiExplorer.getRootPath());
182           } catch(PathNotFoundException e) {
183             reloadWhenBroken(uiExplorer);
184             super.processRender(app, context);
185             return;
186           }
187         } catch(RepositoryException repo) {
188           super.processRender(app, context);
189         }
190       }
191       getChild(UIJcrExplorerEditContainer.class).setRendered(false);
192     } else if(portletReqContext.getApplicationMode() == PortletMode.HELP) {
193       if (LOG.isDebugEnabled()) LOG.debug("\n\n>>>>>>>>>>>>>>>>>>> IN HELP  MODE \n");
194     } else if(portletReqContext.getApplicationMode() == PortletMode.EDIT) {
195       explorerContainer.setRendered(false);
196       getChild(UIJcrExplorerEditContainer.class).setRendered(true);
197     }
198 
199 //    RenderResponse response = context.getResponse();
200 //    Element elementS = response.createElement("script");
201 //    elementS.setAttribute("type", "text/javascript");
202 //    elementS.setAttribute("src", "/eXoWCMResources/javascript/eXo/wcm/backoffice/public/Components.js");
203 //    response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT,elementS);
204     UIJCRExplorer uiExplorer = explorerContainer.getChild(UIJCRExplorer.class);
205     UITreeExplorer uiTreeExplorer = uiExplorer.findFirstComponentOfType(UITreeExplorer.class);
206     AutoVersionService autoVersionService = WCMCoreUtils.getService(AutoVersionService.class);
207     context.getJavascriptManager().
208     require("SHARED/multiUpload", "multiUpload").require("SHARED/jquery", "gj")
209       .addScripts("multiUpload.setLocation('" + 
210                uiExplorer.getWorkspaceName()  + "','" + 
211                uiExplorer.getDriveData().getName()  + "','" +
212                uiTreeExplorer.getLabel()  + "','" +
213                Text.escapeIllegalJcrChars(uiExplorer.getCurrentPath()) + "','" +
214                org.exoplatform.services.cms.impl.Utils.getPersonalDrivePath(uiExplorer.getDriveData().getHomePath(),
215                ConversationState.getCurrent().getIdentity().getUserId())+ "', '"+
216               autoVersionService.isVersionSupport(uiExplorer.getCurrentPath(), uiExplorer.getCurrentWorkspace())+"');")
217       .addScripts("gj(document).ready(function() { gj(\"*[rel='tooltip']\").tooltip();});");
218     super.processRender(app, context);
219   }
220 
221   public void initwhenDirect(UIJcrExplorerContainer explorerContainer,
222       UIJcrExplorerEditContainer editContainer) throws Exception {
223     if (editContainer.getChild(UIJcrExplorerEditForm.class).isFlagSelectRender()) {
224       explorerContainer.initExplorer();
225       editContainer.getChild(UIJcrExplorerEditForm.class).setFlagSelectRender(false);
226     }
227   }
228 
229   public String getPreferenceRepository() {
230     PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance() ;
231     PortletPreferences portletPref = pcontext.getRequest().getPreferences() ;
232     String repository = portletPref.getValue(Utils.REPOSITORY, "") ;
233     return repository ;
234   }
235 
236   public String getPreferenceTrashHomeNodePath() {
237     return getPortletPreferences().getValue(Utils.TRASH_HOME_NODE_PATH, "");
238   }
239 
240   public String getPreferenceTrashRepository() {
241     return getPortletPreferences().getValue(Utils.TRASH_REPOSITORY, "");
242   }
243 
244   public String getPreferenceTrashWorkspace() {
245     return getPortletPreferences().getValue(Utils.TRASH_WORKSPACE, "");
246   }
247 
248   public PortletPreferences getPortletPreferences() {
249     PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();
250     return pcontext.getRequest().getPreferences();
251   }
252   
253   public DriveData getUserDrive() throws Exception {
254     ManageDriveService manageDriveService = getApplicationComponent(ManageDriveService.class);
255     String userId = Util.getPortalRequestContext().getRemoteUser();
256     for(DriveData userDrive : manageDriveService.getPersonalDrives(userId)) {
257       if(userDrive.getHomePath().endsWith("/Private")) {
258         return userDrive;
259       }
260     }
261     return null;
262   }  
263   
264   public boolean canUseConfigDrive(String driveName) throws Exception {
265     ManageDriveService dservice = getApplicationComponent(ManageDriveService.class);
266     String userId = Util.getPortalRequestContext().getRemoteUser();
267     List<String> userRoles = Utils.getMemberships();
268     for(DriveData drive : dservice.getDriveByUserRoles(userId, userRoles)) {
269       if(drive.getName().equals(driveName)) return true;
270     }
271     return false;
272   }
273 
274   public void reloadWhenBroken(UIJCRExplorer uiExplorer) {
275     uiExplorer.getChild(UIControl.class).setRendered(false);
276     UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
277     uiWorkingArea.setRenderedChild(UIDrivesArea.class);
278     UIRightClickPopupMenu uiRightClickPopupMenu = uiWorkingArea.getChild(UIRightClickPopupMenu.class);
279     if(uiRightClickPopupMenu!=null)
280       uiRightClickPopupMenu.setRendered(true);
281   }
282 
283   private Map<String, String> getElementByContext(WebuiRequestContext context) {
284     HashMap<String, String> mapParam = new HashMap<>();
285     //In case access by ajax request
286     if (context.useAjax()) return mapParam;
287     PortalRequestContext pcontext = Util.getPortalRequestContext();
288     Matcher matcher;
289 
290     Map<String, String[]> requestParams = pcontext.getRequest().getParameterMap();
291     for(String requestParamName : requestParams.keySet()) {
292       if (requestParamName.equals("path")) {
293         String nodePathParam = pcontext.getRequestParameter("path");
294         String currentRepo = WCMCoreUtils.getRepository().getConfiguration().getName();
295         String userId = Util.getPortalRequestContext().getRemoteUser();
296         if (nodePathParam != null && nodePathParam.length() > 0) {
297           Pattern patternUrl = Pattern.compile("([^/]+)/(.*)");
298           matcher = patternUrl.matcher(nodePathParam);
299           if (matcher.find()) {
300             mapParam.put("repository", currentRepo);
301             mapParam.put("drive", matcher.group(1));
302             mapParam.put("path", matcher.group(2));
303             mapParam.put("userId",userId);
304           } else {
305             patternUrl = Pattern.compile("(.*)");
306             matcher = patternUrl.matcher(nodePathParam);
307             if (matcher.find()) {
308               mapParam.put("repository", currentRepo);
309               mapParam.put("drive", matcher.group(1));
310               mapParam.put("path", "/");
311             }
312           }
313         }
314       } else {
315         mapParam.put(requestParamName, pcontext.getRequest().getParameter(requestParamName));
316       }
317     }
318 
319     return mapParam;
320   }
321 
322   private void showDocument(WebuiRequestContext context, Map<String, String> map) throws Exception {
323     String repositoryName = String.valueOf(map.get("repository"));
324     String driveName = String.valueOf(map.get("drive"));
325     if (driveName.equals(DOC_NOT_FOUND)) {
326       UIApplication uiApp = findFirstComponentOfType(UIApplication.class);
327       uiApp.addMessage(new ApplicationMessage("UIDrivesArea.msg.not-found", null, ApplicationMessage.WARNING));
328       return;
329     }
330     String path = String.valueOf(map.get("path"));
331     if (path.indexOf("&") > 0) {
332       path = path.substring(0, path.indexOf("&"));
333     }
334     if(!path.equals("/")) {
335       ArrayList<String> encodeNameArr = new ArrayList<String>();
336       for(String name : path.split("/")) {
337         if(name.length() > 0) {
338           encodeNameArr.add(Text.escapeIllegalJcrChars(name));
339         }
340       }
341       StringBuilder encodedPath = new StringBuilder();
342       for(String encodedName : encodeNameArr) {
343         encodedPath.append("/").append(encodedName);
344       }
345       path = encodedPath.toString();
346     }
347     UIApplication uiApp = findFirstComponentOfType(UIApplication.class);
348     ManageDriveService manageDrive = getApplicationComponent(ManageDriveService.class);
349     DriveData driveData = null;
350     try {
351       driveData = manageDrive.getDriveByName(driveName);
352       if (driveData == null) throw new PathNotFoundException();
353     } catch (PathNotFoundException e) {
354       Object[] args = { driveName };
355 
356       return;
357     }
358     RepositoryService rservice = getApplicationComponent(RepositoryService.class);
359     String userId = Util.getPortalRequestContext().getRemoteUser();
360     List<String> viewList = new ArrayList<String>();
361 
362     for (String role : Utils.getMemberships()) {
363       for (String viewName : driveData.getViews().split(",")) {
364         if (!viewList.contains(viewName.trim())) {
365           Node viewNode =
366             getApplicationComponent(ManageViewService.class).getViewByName(viewName.trim(),
367                 WCMCoreUtils.getSystemSessionProvider());
368           String permiss = viewNode.getProperty("exo:accessPermissions").getString();
369           if (permiss.contains("${userId}")) permiss = permiss.replace("${userId}", userId);
370           String[] viewPermissions = permiss.split(",");
371           if (permiss.equals("*")) viewList.add(viewName.trim());
372           if (driveData.hasPermission(viewPermissions, role)) viewList.add(viewName.trim());
373         }
374       }
375     }
376     StringBuffer viewListStr = new StringBuffer();
377     List<SelectItemOption<String>> viewOptions = new ArrayList<SelectItemOption<String>>();
378     ResourceBundle res = context.getApplicationResourceBundle();
379     String viewLabel = null;
380     for (String viewName : viewList) {
381       try {
382         viewLabel = res.getString("Views.label." + viewName);
383       } catch (MissingResourceException e) {
384         viewLabel = viewName;
385       }
386       viewOptions.add(new SelectItemOption<String>(viewLabel, viewName));
387       if (viewListStr.length() > 0)
388         viewListStr.append(",").append(viewName);
389       else
390         viewListStr.append(viewName);
391     }
392     driveData.setViews(viewListStr.toString());
393 
394     String homePath = driveData.getHomePath();
395     Matcher matcher = driveParameteriedPathPattern.matcher(homePath);
396     if(matcher.matches()) {
397       // if the drive is a virtual drive containing, the paramterized value is available as request parameter
398       String drivePathParamName = matcher.group(1);
399       String drivePathParamValue = map.get(drivePathParamName);
400       driveData.getParameters().put(drivePathParamName, drivePathParamValue);
401       // we need to get the real drive home path
402       if(StringUtils.isNotEmpty(drivePathParamValue)) {
403         if(ManageDriveServiceImpl.DRIVE_PARAMATER_USER_ID.equals(drivePathParamName)) {
404           // User id parameter is a special case since it must be replaced by its distributed format
405           homePath = org.exoplatform.services.cms.impl.Utils.getPersonalDrivePath(homePath, drivePathParamValue);
406         } else {
407           // we update the drive homePath with the real value
408           homePath = StringUtils.replaceOnce(homePath, "${" + drivePathParamName + "}", drivePathParamValue);
409         }
410       }
411     }
412 
413     // we extract the absolute path of the file (remove the drive name)
414     String contentRealPath = path;
415     int firstSlash = path.indexOf("/");
416     if(firstSlash >= 0) {
417       contentRealPath = path.substring(firstSlash);
418     }
419 
420     setFlagSelect(true);
421     UIJCRExplorer uiExplorer = findFirstComponentOfType(UIJCRExplorer.class);
422 
423     uiExplorer.setDriveData(driveData);
424     uiExplorer.setIsReferenceNode(false);
425 
426     try {
427       Session session = 
428         WCMCoreUtils.getUserSessionProvider().getSession(driveData.getWorkspace(), rservice.getCurrentRepository());
429       nodeFinder.getItem(session, contentRealPath);
430     } catch(AccessDeniedException ace) {
431       Object[] args = { driveName };
432       uiApp.addMessage(new ApplicationMessage("UIDrivesArea.msg.access-denied", args,
433           ApplicationMessage.WARNING));
434       return;
435     } catch(NoSuchWorkspaceException nosuchWS) {
436       Object[] args = { driveName };
437       uiApp.addMessage(new ApplicationMessage("UIDrivesArea.msg.workspace-not-exist", args,
438           ApplicationMessage.WARNING));
439       return;
440     } catch(Exception e) {
441       JCRExceptionManager.process(uiApp, e);
442       return;
443     }
444     uiExplorer.setRepositoryName(repositoryName);
445     uiExplorer.setWorkspaceName(driveData.getWorkspace());
446     uiExplorer.setRootPath(homePath);
447     String addressPath = contentRealPath.replaceAll("/+", "/");
448     // handle special case of docs in Public Personal Documents and the symlink "Public"
449     if(driveData.getName().equals(ManageDriveServiceImpl.PERSONAL_DRIVE_NAME) &&
450             !addressPath.startsWith(homePath)) {
451       String publicHomePath = homePath.replace("/" + ManageDriveServiceImpl.PERSONAL_DRIVE_PRIVATE_FOLDER_NAME, "/" + ManageDriveServiceImpl.PERSONAL_DRIVE_PUBLIC_FOLDER_NAME);
452       if(addressPath.startsWith(publicHomePath)) {
453         addressPath = addressPath.replace("/" + ManageDriveServiceImpl.PERSONAL_DRIVE_PUBLIC_FOLDER_NAME, "/Private/" + ManageDriveServiceImpl.PERSONAL_DRIVE_PUBLIC_FOLDER_NAME);
454       }
455     }
456     Preference pref = uiExplorer.getPreference();
457     pref.setShowSideBar(driveData.getViewSideBar());
458     pref.setShowNonDocumentType(driveData.getViewNonDocument());
459     pref.setShowPreferenceDocuments(driveData.getViewPreferences());
460     pref.setAllowCreateFoder(driveData.getAllowCreateFolders());
461     pref.setShowHiddenNode(driveData.getShowHiddenNode());
462     uiExplorer.setIsReferenceNode(false);
463     UIControl uiControl = uiExplorer.getChild(UIControl.class);
464 
465     UIAddressBar uiAddressBar = uiControl.getChild(UIAddressBar.class);
466     uiAddressBar.setViewList(viewList);
467     uiAddressBar.setSelectedViewName(viewList.get(0));
468     uiAddressBar.setRendered(isShowTopBar());
469 
470     UIWorkingArea uiWorkingArea = findFirstComponentOfType(UIWorkingArea.class);
471     UIActionBar uiActionbar = uiWorkingArea.getChild(UIActionBar.class);
472     boolean isShowActionBar = isShowActionBar() ;
473     uiActionbar.setTabOptions(viewList.get(0));
474     uiActionbar.setRendered(isShowActionBar);
475     uiExplorer.clearNodeHistory(addressPath);
476     uiExplorer.setSelectNode(driveData.getWorkspace(), addressPath, homePath);
477     UIDocumentWorkspace uiDocWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
478     uiDocWorkspace.setRenderedChild(UIDocumentContainer.class);
479     uiDocWorkspace.setRendered(true);
480 
481     UIDrivesArea uiDrive = uiWorkingArea.getChild(UIDrivesArea.class);
482     if (uiDrive != null) uiDrive.setRendered(false);
483     context.addUIComponentToUpdateByAjax(uiDocWorkspace);
484     UIPopupContainer popupAction = getChild(UIPopupContainer.class);
485     if (popupAction != null && popupAction.isRendered()) {
486       popupAction.deActivate();
487       context.addUIComponentToUpdateByAjax(popupAction);
488     }
489 
490     Boolean isEdit = Boolean.valueOf(Util.getPortalRequestContext().getRequestParameter("edit"));
491     Node selectedNode = uiExplorer.getCurrentNode();
492     if (isEdit) {
493       if (uiExplorer.getCurrentPath().equals(addressPath)) {
494         if(canManageNode(selectedNode, uiApp, uiExplorer, uiActionbar, context, EditDocumentActionComponent.getFilters())) {
495           EditDocumentActionComponent.editDocument(null, context, this, uiExplorer, selectedNode, uiApp);
496         }else if(canManageNode(selectedNode, uiApp, uiExplorer, uiActionbar, context, EditPropertyActionComponent.getFilters())) {
497           EditPropertyActionComponent.editDocument(null, context, this, uiExplorer, selectedNode, uiApp);
498         }
499       } else {
500         uiApp.addMessage(new ApplicationMessage("UIJCRExplorerPortlet.msg.file-access-denied", null, ApplicationMessage.WARNING));
501         
502       }
503     }
504     boolean isAddNew = Boolean.valueOf(Util.getPortalRequestContext().getRequestParameter("addNew"));
505 
506     if(!isAddNew && !isEdit) {
507       showVersionHistory(selectedNode, uiWorkingArea);
508     }
509 
510     if (!isEdit && isAddNew) {
511       if (canManageNode(selectedNode, uiApp, uiExplorer, uiActionbar, context, AddDocumentActionComponent.getFilters())) {
512         AddDocumentActionComponent.addDocument(null, uiExplorer, uiApp, this, context);
513       } else {
514         uiApp.addMessage(new ApplicationMessage("UIJCRExplorerPortlet.msg.file-access-denied",
515                                                 null,
516                                                 ApplicationMessage.WARNING));
517       }
518     }
519     uiExplorer.refreshExplorer(null, (isAddNew && isEdit));
520   }
521 
522   private void showVersionHistory(Node selectedNode, UIWorkingArea uiWorkingArea) throws Exception {
523     Boolean isDisplayVersionHistory = Boolean.valueOf(Util.getPortalRequestContext().getRequestParameter("versions"));
524     if (isDisplayVersionHistory && selectedNode.isNodeType(Utils.MIX_VERSIONABLE)) {
525       UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
526       if (uiDocumentWorkspace != null) {
527         UIVersionInfo uiVersionInfo = uiDocumentWorkspace.getChild(UIVersionInfo.class);
528         if (uiVersionInfo != null) {
529           uiVersionInfo.setCurrentNode(selectedNode);
530           uiVersionInfo.setRootOwner(selectedNode.getProperty(Utils.EXO_LASTMODIFIER).getString());
531           uiVersionInfo.activate();
532           uiDocumentWorkspace.setRenderedChild(UIVersionInfo.class);
533         }
534       }
535     }
536   }
537 
538   private boolean canManageNode(Node selectedNode,
539                                 UIApplication uiApp,
540                                 UIJCRExplorer uiExplorer,
541                                 UIActionBar uiActionBar,
542                                 Object context,
543                                 List<UIExtensionFilter> filters) throws Exception {
544     Map<String, Object> ctx = new HashMap<String, Object>();
545     ctx.put(UIActionBar.class.getName(), uiActionBar);
546     ctx.put(UIJCRExplorer.class.getName(), uiExplorer);
547     ctx.put(UIApplication.class.getName(), uiApp);
548     ctx.put(Node.class.getName(), selectedNode);
549     ctx.put(WebuiRequestContext.class.getName(), context);
550     for (UIExtensionFilter filter : filters)
551       try {
552         if (!filter.accept(ctx))
553           return false;
554       } catch (Exception e) {
555         return false;
556       }
557     return true;
558   }
559 }
560