1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.webui.component.explorer.control.UIActionBar;
22 import org.exoplatform.ecm.webui.component.explorer.control.UIAddressBar;
23 import org.exoplatform.ecm.webui.component.explorer.control.UIControl;
24 import org.exoplatform.ecm.webui.component.explorer.sidebar.UISideBar;
25 import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
26 import org.exoplatform.ecm.webui.utils.Utils;
27 import org.exoplatform.portal.webui.util.Util;
28 import org.exoplatform.services.cms.clipboard.ClipboardService;
29 import org.exoplatform.services.cms.drives.DriveData;
30 import org.exoplatform.services.cms.drives.ManageDriveService;
31 import org.exoplatform.services.cms.views.ManageViewService;
32 import org.exoplatform.services.jcr.RepositoryService;
33 import org.exoplatform.services.log.ExoLogger;
34 import org.exoplatform.services.log.Log;
35 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
36 import org.exoplatform.web.application.ApplicationMessage;
37 import org.exoplatform.webui.application.WebuiRequestContext;
38 import org.exoplatform.webui.application.portlet.PortletRequestContext;
39 import org.exoplatform.webui.config.annotation.ComponentConfig;
40 import org.exoplatform.webui.core.UIApplication;
41 import org.exoplatform.webui.core.UIContainer;
42 import org.exoplatform.webui.core.UIRightClickPopupMenu;
43 import org.exoplatform.webui.core.model.SelectItemOption;
44
45 import javax.jcr.AccessDeniedException;
46 import javax.jcr.NoSuchWorkspaceException;
47 import javax.jcr.Node;
48 import javax.jcr.Session;
49 import javax.portlet.PortletPreferences;
50 import javax.portlet.PortletRequest;
51 import java.util.ArrayList;
52 import java.util.List;
53 import java.util.MissingResourceException;
54 import java.util.ResourceBundle;
55
56
57
58 @ComponentConfig(
59 template = "app:/groovy/webui/component/explorer/UIJCRExplorerContainer.gtmpl"
60 )
61 public class UIJcrExplorerContainer extends UIContainer {
62 private static final Log LOG = ExoLogger.getLogger(UIJcrExplorerContainer.class.getName());
63 public UIJcrExplorerContainer() throws Exception {
64 addChild(UIJCRExplorer.class, null, null);
65 addChild(UIMultiUpload.class, null, null);
66 }
67
68 public String getUserAgent() {
69 PortletRequestContext requestContext = PortletRequestContext.getCurrentInstance();
70 PortletRequest portletRequest = requestContext.getRequest();
71 return portletRequest.getProperty("User-Agent");
72 }
73
74 public void initExplorer() throws Exception {
75 try {
76 UIJCRExplorerPortlet uiFEPortlet = getParent();
77 PortletPreferences preference = uiFEPortlet.getPortletPreferences();
78 initExplorerPreference(preference);
79 String driveName = preference.getValue("driveName", "");
80 String nodePath = preference.getValue("nodePath", "");
81 RepositoryService rservice = getApplicationComponent(RepositoryService.class);
82 String repoName = rservice.getCurrentRepository().getConfiguration().getName();
83 ManageDriveService dservice = getApplicationComponent(ManageDriveService.class);
84 DriveData drive = dservice.getDriveByName(driveName);
85 String userId = Util.getPortalRequestContext().getRemoteUser();
86 List<String> userRoles = Utils.getMemberships();
87 if(!uiFEPortlet.canUseConfigDrive(driveName)) {
88 drive = getAncestorOfType(UIJCRExplorerPortlet.class).getUserDrive();
89 }
90 UIApplication uiApp = getApplicationComponent(UIApplication.class);
91 List<String> viewList = new ArrayList<String>();
92 for (String role : userRoles) {
93 for (String viewName : drive.getViews().split(",")) {
94 if (!viewList.contains(viewName.trim())) {
95 Node viewNode = getApplicationComponent(ManageViewService.class)
96 .getViewByName(viewName.trim(), WCMCoreUtils.getSystemSessionProvider());
97 String permiss = viewNode.getProperty("exo:accessPermissions").getString();
98 if (permiss.contains("${userId}")) permiss = permiss.replace("${userId}", userId);
99 String[] viewPermissions = permiss.split(",");
100 if (permiss.equals("*")) viewList.add(viewName.trim());
101 if (drive.hasPermission(viewPermissions, role)) viewList.add(viewName.trim());
102 }
103 }
104 }
105 if (viewList.isEmpty()) {
106 return;
107 }
108 StringBuffer viewListStr = new StringBuffer();
109 List<SelectItemOption<String>> viewOptions = new ArrayList<SelectItemOption<String>>();
110 WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
111 ResourceBundle res = context.getApplicationResourceBundle();
112 String viewLabel = null;
113 for (String viewName : viewList) {
114 try {
115 viewLabel = res.getString("Views.label." + viewName) ;
116 } catch (MissingResourceException e) {
117 viewLabel = viewName;
118 }
119 viewOptions.add(new SelectItemOption<String>(viewLabel, viewName));
120 if(viewListStr.length() > 0) viewListStr.append(",").append(viewName);
121 else viewListStr.append(viewName);
122 }
123 drive.setViews(viewListStr.toString());
124 StringBuffer homePathBuf = new StringBuffer();
125 homePathBuf.append(drive.getHomePath());
126 if (homePathBuf.indexOf("${userId}") >= 0)
127 homePathBuf = new StringBuffer(org.exoplatform.services.cms.impl.Utils.getPersonalDrivePath(homePathBuf.toString(),
128 userId));
129
130
131
132 if(drive.getHomePath().startsWith("/Groups/spaces/") &&
133 (StringUtils.isBlank(nodePath) || nodePath.equals("Documents") || nodePath.equals("/Documents"))) nodePath = "/";
134 if (nodePath != null && nodePath.length() > 0 && !nodePath.equals("/"))
135 homePathBuf.append("/").append(nodePath);
136 String homePath = homePathBuf.toString().replaceAll("//", "/");
137 UIJCRExplorer uiJCRExplorer = getChild(UIJCRExplorer.class);
138
139 uiJCRExplorer.setDriveData(drive);
140 uiJCRExplorer.setIsReferenceNode(false);
141
142 Session session = WCMCoreUtils.getUserSessionProvider().getSession(drive.getWorkspace(), rservice.getCurrentRepository());
143 try {
144
145 session.getItem(homePath);
146 } catch(AccessDeniedException ace) {
147 Object[] args = { driveName };
148 uiApp.addMessage(new ApplicationMessage("UIDrivesArea.msg.access-denied", args,
149 ApplicationMessage.WARNING));
150 return;
151 } catch(NoSuchWorkspaceException nosuchWS) {
152 Object[] args = { driveName };
153 uiApp.addMessage(new ApplicationMessage("UIDrivesArea.msg.workspace-not-exist", args,
154 ApplicationMessage.WARNING));
155 return;
156 } catch(Exception e) {
157 JCRExceptionManager.process(uiApp, e);
158 return;
159 }
160
161 uiJCRExplorer.setRepositoryName(repoName);
162 uiJCRExplorer.setWorkspaceName(drive.getWorkspace());
163 uiJCRExplorer.setRootPath(homePath);
164 uiJCRExplorer.setSelectNode(drive.getWorkspace(), homePath);
165 Preference pref = uiJCRExplorer.getPreference();
166 pref.setShowSideBar(drive.getViewSideBar());
167 pref.setShowNonDocumentType(drive.getViewNonDocument());
168 pref.setShowPreferenceDocuments(drive.getViewPreferences());
169 pref.setAllowCreateFoder(drive.getAllowCreateFolders());
170 pref.setShowHiddenNode(drive.getShowHiddenNode());
171 UIControl uiControl = uiJCRExplorer.getChild(UIControl.class);
172 UIWorkingArea uiWorkingArea = uiJCRExplorer.getChild(UIWorkingArea.class);
173
174 UIAddressBar uiAddressBar = uiControl.getChild(UIAddressBar.class);
175 uiAddressBar.setViewList(viewList);
176 uiAddressBar.setSelectedViewName(viewList.get(0));
177 uiAddressBar.setRendered(uiFEPortlet.isShowTopBar());
178 UIActionBar uiActionbar = uiWorkingArea.getChild(UIActionBar.class);
179 boolean isShowActionBar = uiFEPortlet.isShowActionBar();
180 uiActionbar.setTabOptions(viewList.get(0));
181 uiActionbar.setRendered(isShowActionBar);
182 uiWorkingArea.setRenderedChildrenOfTypes(new Class[] { UIActionBar.class,
183 UIDocumentWorkspace.class });
184 uiJCRExplorer.refreshExplorer();
185 UIRightClickPopupMenu uiRightClickPopupMenu = uiWorkingArea.findFirstComponentOfType(UIRightClickPopupMenu.class);
186 if(uiRightClickPopupMenu!=null && !uiRightClickPopupMenu.isRendered())
187 uiRightClickPopupMenu.setRendered(true);
188 UISideBar uiSideBar = uiWorkingArea.findFirstComponentOfType(UISideBar.class);
189 uiSideBar.setRendered(true);
190 uiSideBar.initialize();
191 if (uiSideBar.isRendered()) {
192 uiSideBar.updateSideBarView();
193 }
194 } catch (Exception e) {
195 if (LOG.isErrorEnabled()) {
196 LOG.error("Unexpected error", e);
197 }
198 }
199 }
200
201 private void initExplorerPreference(PortletPreferences portletPref) {
202 UIJCRExplorer uiExplorer = getChild(UIJCRExplorer.class);
203 if (uiExplorer != null) {
204 Preference pref = uiExplorer.getPreference();
205 if (pref == null) {
206 pref = new Preference();
207 pref.setNodesPerPage(Integer.parseInt(portletPref.getValue(Preference.NODES_PER_PAGE, "20")));
208 uiExplorer.setPreferences(pref);
209 }
210 }
211 }
212
213 @Override
214 public void processRender(WebuiRequestContext context) throws Exception
215 {
216 super.processRender(context);
217 }
218
219 }