1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.component.explorer.sidebar ;
18
19 import java.util.HashSet;
20 import java.util.List;
21 import java.util.MissingResourceException;
22 import java.util.ResourceBundle;
23
24 import javax.jcr.AccessDeniedException;
25 import javax.jcr.Item;
26 import javax.jcr.ItemNotFoundException;
27 import javax.jcr.Node;
28 import javax.jcr.NodeIterator;
29 import javax.jcr.PathNotFoundException;
30 import javax.jcr.RepositoryException;
31 import javax.jcr.Session;
32 import javax.jcr.nodetype.NodeType;
33 import javax.jcr.query.Row;
34 import javax.portlet.PortletPreferences;
35
36 import org.apache.commons.lang.StringUtils;
37 import org.apache.ws.commons.util.Base64;
38 import org.exoplatform.commons.api.search.data.SearchResult;
39 import org.exoplatform.commons.utils.PageList;
40 import org.exoplatform.container.xml.PortalContainerInfo;
41 import org.exoplatform.ecm.jcr.model.Preference;
42 import org.exoplatform.ecm.webui.component.explorer.DocumentProviderUtils;
43 import org.exoplatform.ecm.webui.component.explorer.UIDocumentContainer;
44 import org.exoplatform.ecm.webui.component.explorer.UIDocumentWorkspace;
45 import org.exoplatform.ecm.webui.component.explorer.UIDrivesArea;
46 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
47 import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet;
48 import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
49 import org.exoplatform.ecm.webui.component.explorer.UIDocumentInfo;
50 import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
51 import org.exoplatform.services.cms.clipboard.ClipboardService;
52 import org.exoplatform.services.cms.documents.AutoVersionService;
53 import org.exoplatform.services.cms.drives.DriveData;
54 import org.exoplatform.services.cms.drives.impl.ManageDriveServiceImpl;
55 import org.exoplatform.services.cms.impl.Utils;
56 import org.exoplatform.services.cms.link.LinkManager;
57 import org.exoplatform.services.cms.link.LinkUtils;
58 import org.exoplatform.services.cms.link.NodeFinder;
59 import org.exoplatform.services.cms.templates.TemplateService;
60 import org.exoplatform.services.jcr.RepositoryService;
61 import org.exoplatform.services.log.ExoLogger;
62 import org.exoplatform.services.log.Log;
63 import org.exoplatform.services.organization.OrganizationService;
64 import org.exoplatform.services.organization.User;
65 import org.exoplatform.services.security.ConversationState;
66 import org.exoplatform.services.wcm.core.NodetypeConstant;
67 import org.exoplatform.services.wcm.search.base.SearchDataCreator;
68 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
69 import org.exoplatform.web.application.ApplicationMessage;
70 import org.exoplatform.web.application.RequestContext;
71 import org.exoplatform.webui.application.portlet.PortletRequestContext;
72 import org.exoplatform.webui.config.annotation.ComponentConfig;
73 import org.exoplatform.webui.config.annotation.EventConfig;
74 import org.exoplatform.webui.core.UIApplication;
75 import org.exoplatform.webui.core.UIComponent;
76 import org.exoplatform.webui.core.UIContainer;
77 import org.exoplatform.webui.core.UIRightClickPopupMenu;
78 import org.exoplatform.webui.core.UIPageIterator;
79 import org.exoplatform.webui.event.Event;
80 import org.exoplatform.webui.event.EventListener;
81 import org.exoplatform.services.wcm.search.base.LazyPageList;
82
83
84
85
86
87
88
89 @ComponentConfig(
90 template = "app:/groovy/webui/component/explorer/sidebar/UITreeExplorer.gtmpl",
91 events = {
92 @EventConfig(listeners = UITreeExplorer.ExpandActionListener.class),
93 @EventConfig(listeners = UITreeExplorer.CollapseActionListener.class),
94 @EventConfig(listeners = UITreeExplorer.ExpandTreeActionListener.class)
95 }
96 )
97
98 public class UITreeExplorer extends UIContainer {
99
100 private class TreeNodeDataCreater implements SearchDataCreator<TreeNode>{
101
102 @Override
103 public TreeNode createData(Node node, Row row, SearchResult searchResult){
104 try {
105 return new TreeNode(node);
106 } catch (RepositoryException e) {
107 return null;
108 }
109 }
110 }
111
112
113
114 private static final Log LOG = ExoLogger.getLogger(UITreeExplorer.class.getName());
115 private TreeNode treeRoot_ ;
116 private String expandPath = null;
117 private boolean isExpand = false;
118 public UITreeExplorer() throws Exception {
119 }
120
121
122 public UIRightClickPopupMenu getContextMenu() {
123 return getAncestorOfType(UIWorkingArea.class).getChild(UIRightClickPopupMenu.class) ;
124 }
125
126 UIWorkingArea getWorkingArea() {
127 return getAncestorOfType(UIWorkingArea.class);
128 }
129
130 private UISideBar getSideBar() {
131 return getWorkingArea().findFirstComponentOfType(UISideBar.class);
132 }
133
134 UIComponent getCustomAction() throws Exception {
135 return getAncestorOfType(UIWorkingArea.class).getCustomAction();
136 }
137
138 public TreeNode getRootTreeNode() { return treeRoot_ ; }
139
140 public String getRootActionList() throws Exception {
141 ClipboardService clipboardService = WCMCoreUtils.getService(ClipboardService.class);
142 String userId = ConversationState.getCurrent().getIdentity().getUserId();
143
144 UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class);
145 if (!clipboardService.getClipboardList(userId, false).isEmpty()) {
146 return getContextMenu().getJSOnclickShowPopup(uiExplorer.getCurrentDriveWorkspace() + ":"
147 + uiExplorer.getRootPath(),
148 "Paste").toString();
149 }
150 return "" ;
151 }
152
153 public boolean isDirectlyDrive() {
154 PortletPreferences portletPref =
155 getAncestorOfType(UIJCRExplorerPortlet.class).getPortletPreferences();
156 String usecase = portletPref.getValue("usecase", "").trim();
157 if ("selection".equals(usecase)) {
158 return false;
159 }
160 return true;
161 }
162
163 public String getDriveName() {
164 return getAncestorOfType(UIJCRExplorer.class).getDriveData().getName() ;
165 }
166
167 public String getLabel() {
168 RequestContext context = RequestContext.getCurrentInstance();
169 ResourceBundle res = context.getApplicationResourceBundle();
170 DriveData driveData = getAncestorOfType(UIJCRExplorer.class).getDriveData();
171 String id = driveData.getName();
172 String path = driveData.getHomePath();
173
174 String driveLabelKey = "Drives.label." + id.replace(".", "").replace(" ", "");
175 try {
176 if (ManageDriveServiceImpl.USER_DRIVE_NAME.equals(id)) {
177
178 driveLabelKey = "Drives.label.UserDocuments";
179 String userDisplayName = "";
180
181 String userIdPath = driveData.getParameters().get(ManageDriveServiceImpl.DRIVE_PARAMATER_USER_ID);
182 String userId = userIdPath != null ? userIdPath.substring(userIdPath.lastIndexOf("/") + 1) : null;
183 if (StringUtils.isNotEmpty(userId)) {
184 userDisplayName = userId;
185 User user = this.getApplicationComponent(OrganizationService.class).getUserHandler().findUserByName(userId);
186 if (user != null) {
187 userDisplayName = user.getDisplayName();
188 }
189 }
190 try {
191 return res.getString(driveLabelKey).replace("{0}", userDisplayName);
192 } catch (MissingResourceException mre) {
193 LOG.error("Cannot get resource string for " + driveLabelKey);
194 }
195
196 } else {
197 try {
198 return res.getString(driveLabelKey);
199 } catch (MissingResourceException ex) {
200 try {
201 RepositoryService repoService = WCMCoreUtils.getService(RepositoryService.class);
202 Node groupNode = (Node)WCMCoreUtils.getSystemSessionProvider().getSession(
203 repoService.getCurrentRepository().getConfiguration().getDefaultWorkspaceName(),
204 repoService.getCurrentRepository()).getItem(path);
205 return groupNode.getProperty(NodetypeConstant.EXO_LABEL).getString();
206 } catch(Exception e) {
207 return id.replace(".", " / ");
208 }
209 }
210 }
211 } catch (Exception ex) {
212 LOG.warn("Can not find resource string for " + driveLabelKey, ex);
213 }
214 return id.replace(".", " / ");
215 }
216
217 public boolean isAllowNodeTypesOnTree(Node node) throws RepositoryException {
218 DriveData currentDrive = getAncestorOfType(UIJCRExplorer.class).getDriveData();
219 String allowNodeTypesOnTree = currentDrive.getAllowNodeTypesOnTree();
220 if ((allowNodeTypesOnTree == null) || (allowNodeTypesOnTree.equals("*"))) return true;
221 String[] arrayAllowNodeTypesOnTree = allowNodeTypesOnTree.split(",");
222 for (String itemAllowNodeTypes : arrayAllowNodeTypesOnTree) {
223 if ((itemAllowNodeTypes.trim().length() > 0) && node.isNodeType(itemAllowNodeTypes.trim())) return true;
224 }
225 return false;
226 }
227
228 public String getActionsList(Node node) throws Exception {
229 if(node == null) return "" ;
230 UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class);
231 try {
232 NodeFinder nodeFinder = getApplicationComponent(NodeFinder.class);
233 nodeFinder.getItem(uiExplorer.getSession(), node.getPath());
234
235 return getAncestorOfType(UIWorkingArea.class).getActionsExtensionList(node) ;
236 } catch(PathNotFoundException pne) {
237 uiExplorer.refreshExplorerWithoutClosingPopup();
238 return "";
239 }
240 }
241
242 public List<Node> getCustomActions(Node node) throws Exception {
243 return getAncestorOfType(UIWorkingArea.class).getCustomActions(node) ;
244 }
245
246 public boolean isPreferenceNode(Node node) {
247 return getAncestorOfType(UIWorkingArea.class).isPreferenceNode(node) ;
248 }
249
250 @SuppressWarnings("unchecked")
251 public List<TreeNode> getRenderedChildren(TreeNode treeNode) throws Exception {
252 if(isPaginated(treeNode)) {
253 UITreeNodePageIterator pageIterator = findComponentById(treeNode.getPath());
254 return pageIterator.getCurrentPageData();
255 }
256 if(isShowChildren(treeNode) && treeNode.getChildrenSize() > 0 && treeNode.getChildren().size() == 0) {
257 UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class);
258 treeNode.setChildren(jcrExplorer.getChildrenList(treeNode.getPath(), false));
259 return treeNode.getChildren();
260 }
261 return treeNode.getChildren();
262 }
263
264 public boolean isSystemWorkspace() throws Exception {
265 return getAncestorOfType(UIJCRExplorer.class).isSystemWorkspace() ;
266 }
267
268 public UITreeNodePageIterator getUIPageIterator(String id) throws Exception {
269 return findComponentById(id);
270 }
271
272 public boolean isSymLink(Node node) throws RepositoryException {
273 LinkManager linkManager = getApplicationComponent(LinkManager.class);
274 return linkManager.isLink(node);
275 }
276
277 public String getViewTemplate(String nodeTypeName, String templateName) throws Exception {
278 TemplateService tempServ = getApplicationComponent(TemplateService.class) ;
279 return tempServ.getTemplatePath(false, nodeTypeName, templateName) ;
280 }
281
282 public boolean isPaginated(TreeNode treeNode) {
283 UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class) ;
284 int nodePerPages = jcrExplorer.getPreference().getNodesPerPage();
285 return (treeNode.getChildrenSize()>nodePerPages) && (findComponentById(treeNode.getPath()) != null) ;
286 }
287
288 public String getPortalName() {
289 PortalContainerInfo containerInfo = WCMCoreUtils.getService(PortalContainerInfo.class);
290 return containerInfo.getContainerName();
291 }
292
293 public String getServerPath() {
294 PortletRequestContext portletRequestContext = PortletRequestContext.getCurrentInstance() ;
295 String prefixWebDAV = portletRequestContext.getRequest().getScheme() + "://" +
296 portletRequestContext.getRequest().getServerName() + ":" +
297 String.format("%s",portletRequestContext.getRequest().getServerPort()) ;
298 return prefixWebDAV ;
299 }
300
301 public boolean isShowChildren(TreeNode treeNode){
302 UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class);
303 String currentPath = jcrExplorer.getCurrentPath();
304 return treeNode.isExpanded() || currentPath.startsWith(treeNode.getPath());
305 }
306
307 public String getRepository() {
308 return getAncestorOfType(UIJCRExplorer.class).getRepositoryName();
309 }
310
311 public String getEncodeCurrentPath() {
312 return encodeBase64(getAncestorOfType(UIJCRExplorer.class).getCurrentPath());
313 }
314
315 public String getEncodeExpandPath() {
316 if(expandPath != null)
317 return encodeBase64(expandPath);
318 else return null;
319 }
320
321 public boolean getIsExpand() {
322 return isExpand;
323 }
324
325 public static String encodeBase64(String value) {
326 value = value == null ? "" : value;
327 return Base64.encode(value.getBytes()).replaceAll(Base64.LINE_SEPARATOR,"");
328 }
329
330
331
332
333
334
335
336
337
338 private void addTreeNodePageIteratorAsChild(String id,
339 PageList<TreeNode> pageList,
340 String selectedPath,
341 String currentPath) throws Exception {
342 if (findComponentById(id) == null) {
343 UITreeNodePageIterator nodePageIterator = addChild(UITreeNodePageIterator.class, null, id);
344 nodePageIterator.setPageList(pageList);
345 nodePageIterator.setSelectedPath(selectedPath);
346 } else {
347 UITreeNodePageIterator existedComponent = findComponentById(id);
348 int currentPage = existedComponent.getCurrentPage();
349 existedComponent.setPageList(pageList);
350 if (!selectedPath.equalsIgnoreCase(currentPath)) {
351 if (currentPage <= existedComponent.getAvailablePage()) {
352 existedComponent.setCurrentPage(currentPage);
353 }
354 }
355 }
356 }
357
358 private Node getRootNode() throws Exception {
359 UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ;
360 return uiExplorer.getRootNode();
361 }
362
363 private void buildTree(String path) throws Exception {
364 if(getSideBar() == null || !getSideBar().isRenderComponent("Explorer")) {
365 return;
366 }
367 UIJCRExplorer jcrExplorer = getAncestorOfType(UIJCRExplorer.class);
368 int nodePerPages = jcrExplorer.getPreference().getNodesPerPage();
369 TreeNode treeRoot = new TreeNode(getRootNode());
370 if (path == null)
371 path = jcrExplorer.getCurrentPath();
372 String[] arr = path.replaceFirst(treeRoot.getPath(), "").split("/");
373 TreeNode temp = treeRoot;
374 StringBuffer subPath = null;
375 String rootPath = treeRoot.getPath();
376 StringBuffer prefix = new StringBuffer(rootPath);
377 if (!rootPath.equals("/")) {
378 prefix.append("/");
379 }
380 HashSet<String> emptySet = new HashSet<String>();
381
382 if (temp.getChildrenSize() > nodePerPages) {
383 LazyPageList<TreeNode> pageList = DocumentProviderUtils.getInstance().getPageList(jcrExplorer.getWorkspaceName(),
384 rootPath,
385 jcrExplorer.getPreference(),
386 emptySet,
387 emptySet,
388 new TreeNodeDataCreater());
389 addTreeNodePageIteratorAsChild(treeRoot.getPath(), pageList, rootPath, path);
390 } else temp.setChildren(jcrExplorer.getChildrenList(rootPath, false));
391
392 for (String nodeName : arr) {
393 if (nodeName.length() == 0)
394 continue;
395 temp = temp.getChildByName(nodeName);
396 if (temp == null) {
397 treeRoot_ = treeRoot;
398 return;
399 }
400 if (subPath == null) {
401 subPath = new StringBuffer();
402 subPath.append(prefix).append(nodeName);
403 } else {
404 subPath.append("/").append(nodeName);
405 }
406 if (temp.getChildrenSize() > nodePerPages) {
407 LazyPageList<TreeNode> pageList = DocumentProviderUtils.getInstance().getPageList(jcrExplorer.getWorkspaceName(),
408 subPath.toString(),
409 jcrExplorer.getPreference(),
410 emptySet,
411 emptySet,
412 new TreeNodeDataCreater());
413 addTreeNodePageIteratorAsChild(temp.getPath(), pageList, subPath.toString(), path);
414 } else temp.setChildren(jcrExplorer.getChildrenList(subPath.toString(), false));
415 }
416 treeRoot_ = treeRoot;
417 }
418
419 public void buildTree() throws Exception {
420 buildTree(null);
421
422 }
423
424 public boolean isDocumentNodeType(Node node) throws Exception {
425 TemplateService templateService = getApplicationComponent(TemplateService.class);
426 return templateService.isManagedNodeType(node.getPrimaryNodeType().getName());
427 }
428
429 public String getSelectedPath() throws Exception {
430 UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class) ;
431 return encodeBase64(uiExplorer.getCurrentPath());
432 }
433
434
435 static public class ExpandActionListener extends EventListener<UITreeExplorer> {
436 public void execute(Event<UITreeExplorer> event) throws Exception {
437 UITreeExplorer uiTreeExplorer = event.getSource();
438 String path = event.getRequestContext().getRequestParameter(OBJECTID) ;
439 uiTreeExplorer.isExpand = false;
440 UIJCRExplorer uiExplorer = uiTreeExplorer.getAncestorOfType(UIJCRExplorer.class) ;
441 UIApplication uiApp = uiTreeExplorer.getAncestorOfType(UIApplication.class) ;
442 String workspaceName = event.getRequestContext().getRequestParameter("workspaceName");
443 Item item = null;
444 try {
445 Session session = uiExplorer.getSessionByWorkspace(workspaceName);
446
447 NodeFinder nodeFinder = uiTreeExplorer.getApplicationComponent(NodeFinder.class);
448 item = nodeFinder.getItem(session, path);
449 } catch(PathNotFoundException pa) {
450 uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null,
451 ApplicationMessage.WARNING)) ;
452
453 return ;
454 } catch(ItemNotFoundException inf) {
455 uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found", null,
456 ApplicationMessage.WARNING)) ;
457
458 return ;
459 } catch(AccessDeniedException ace) {
460 uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.access-denied", null,
461 ApplicationMessage.WARNING)) ;
462
463 return ;
464 } catch(RepositoryException e) {
465 if (LOG.isErrorEnabled()) {
466 LOG.error("Repository cannot be found");
467 }
468 uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.repository-error", null,
469 ApplicationMessage.WARNING)) ;
470
471 return ;
472 } catch (Exception e) {
473 JCRExceptionManager.process(uiApp, e);
474 return;
475 }
476 if (isInTrash(item))
477 return;
478
479 UIWorkingArea uiWorkingArea = uiExplorer.getChild(UIWorkingArea.class);
480 UIDocumentWorkspace uiDocumentWorkspace = uiWorkingArea.getChild(UIDocumentWorkspace.class);
481 AutoVersionService autoVersionService = WCMCoreUtils.getService(AutoVersionService.class);
482 if(!uiDocumentWorkspace.isRendered()) {
483 uiWorkingArea.getChild(UIDrivesArea.class).setRendered(false);
484 uiDocumentWorkspace.setRendered(true);
485 } else {
486 uiDocumentWorkspace.setRenderedChild(UIDocumentContainer.class);
487 }
488 uiExplorer.setSelectNode(workspaceName, path);
489
490
491
492 UIPageIterator contentPageIterator = uiExplorer.findComponentById(UIDocumentInfo.CONTENT_PAGE_ITERATOR_ID);
493 if(contentPageIterator != null) {
494 contentPageIterator.setCurrentPage(1);
495 }
496 uiExplorer.updateAjax(event);
497 event.getRequestContext().getJavascriptManager().
498 require("SHARED/multiUpload", "multiUpload").
499 addScripts("multiUpload.setLocation('" +
500 uiExplorer.getWorkspaceName() + "','" +
501 uiExplorer.getDriveData().getName() + "','" +
502 uiTreeExplorer.getLabel() + "','" +
503 uiExplorer.getCurrentPath() + "','" +
504 Utils.getPersonalDrivePath(uiExplorer.getDriveData().getHomePath(),
505 ConversationState.getCurrent().getIdentity().getUserId()) + "', '"+
506 autoVersionService.isVersionSupport(uiExplorer.getCurrentPath(), uiExplorer.getCurrentWorkspace())+"');");
507 }
508
509 }
510
511 private static boolean isInTrash(Item item) throws RepositoryException {
512 return (item instanceof Node) && Utils.isInTrash((Node) item);
513 }
514
515 static public class ExpandTreeActionListener extends EventListener<UITreeExplorer> {
516 public void execute(Event<UITreeExplorer> event) throws Exception {
517 UITreeExplorer uiTreeExplorer = event.getSource();
518 String path = event.getRequestContext().getRequestParameter(OBJECTID);
519 uiTreeExplorer.expandPath = path;
520 uiTreeExplorer.isExpand = true;
521 UIJCRExplorer uiExplorer = uiTreeExplorer.getAncestorOfType(UIJCRExplorer.class);
522 UIApplication uiApp = uiTreeExplorer.getAncestorOfType(UIApplication.class);
523 String workspaceName = event.getRequestContext().getRequestParameter("workspaceName");
524 Item item = null;
525 try {
526 Session session = uiExplorer.getSessionByWorkspace(workspaceName);
527
528 NodeFinder nodeFinder = uiTreeExplorer.getApplicationComponent(NodeFinder.class);
529 item = nodeFinder.getItem(session, path);
530 } catch (PathNotFoundException pa) {
531 uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found",
532 null,
533 ApplicationMessage.WARNING));
534
535 return;
536 } catch (ItemNotFoundException inf) {
537 uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.path-not-found",
538 null,
539 ApplicationMessage.WARNING));
540
541 return;
542 } catch (AccessDeniedException ace) {
543 uiApp.addMessage(new ApplicationMessage("UIDocumentInfo.msg.access-denied",
544 null,
545 ApplicationMessage.WARNING));
546
547 return;
548 } catch(RepositoryException e) {
549 if (LOG.isErrorEnabled()) {
550 LOG.error("Repository cannot be found");
551 }
552 uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.repository-error", null,
553 ApplicationMessage.WARNING)) ;
554
555 return ;
556 } catch (Exception e) {
557 JCRExceptionManager.process(uiApp, e);
558 return;
559 }
560 if (isInTrash(item))
561 return;
562 if (uiExplorer.getPreference().isShowSideBar()
563 && uiExplorer.getAncestorOfType(UIJCRExplorerPortlet.class).isShowSideBar()) {
564 uiTreeExplorer.buildTree(path);
565 }
566 }
567 }
568
569 static public class CollapseActionListener extends EventListener<UITreeExplorer> {
570 public void execute(Event<UITreeExplorer> event) throws Exception {
571 UITreeExplorer treeExplorer = event.getSource();
572 UIApplication uiApp = treeExplorer.getAncestorOfType(UIApplication.class);
573 try {
574 String path = event.getRequestContext().getRequestParameter(OBJECTID) ;
575 UIJCRExplorer uiExplorer = treeExplorer.getAncestorOfType(UIJCRExplorer.class) ;
576 path = LinkUtils.getParentPath(path) ;
577 uiExplorer.setSelectNode(path) ;
578 uiExplorer.updateAjax(event) ;
579 } catch(RepositoryException e) {
580 if (LOG.isErrorEnabled()) {
581 LOG.error("Repository cannot be found");
582 }
583 uiApp.addMessage(new ApplicationMessage("UITreeExplorer.msg.repository-error", null,
584 ApplicationMessage.WARNING)) ;
585
586 return ;
587 } catch (Exception e) {
588 JCRExceptionManager.process(uiApp, e);
589 return;
590 }
591 }
592 }
593
594
595
596
597
598
599
600
601 public boolean hasChildNode(Node node) throws Exception {
602 if(!node.hasNodes()) return false;
603 UIJCRExplorer uiExplorer = getAncestorOfType(UIJCRExplorer.class);
604 Preference preferences = uiExplorer.getPreference();
605 if(!isFolderType(node) && !preferences.isJcrEnable() && !node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.EXO_TAXONOMY))
606 return false;
607 NodeIterator iterator = node.getNodes();
608 while(iterator.hasNext()) {
609 Node tmpNode = iterator.nextNode();
610
611 if (!preferences.isShowHiddenNode() && !preferences.isShowNonDocumentType()) {
612 if(!tmpNode.isNodeType(org.exoplatform.ecm.webui.utils.Utils.EXO_HIDDENABLE) && isDocumentOrFolderType(tmpNode))
613 return true;
614 }
615
616 else if (preferences.isShowHiddenNode() && !preferences.isShowNonDocumentType()) {
617 if(isDocumentOrFolderType(tmpNode)) return true;
618 }
619
620 else if (!preferences.isShowHiddenNode() && preferences.isShowNonDocumentType()) {
621 if(!tmpNode.isNodeType(org.exoplatform.ecm.webui.utils.Utils.EXO_HIDDENABLE))
622 return true;
623 }
624
625 else return true;
626 }
627 return false;
628 }
629
630
631
632
633
634
635
636 private boolean isDocumentOrFolderType(Node node) throws Exception {
637 if(node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_FOLDER) ||
638 node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_UNSTRUCTURED)) return true;
639 TemplateService templateService = getApplicationComponent(TemplateService.class);
640 NodeType nodeType = node.getPrimaryNodeType();
641 return templateService.getDocumentTemplates().contains(nodeType.getName());
642 }
643 private boolean isFolderType(Node node) throws Exception {
644 if(node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_FOLDER) ||
645 node.isNodeType(org.exoplatform.ecm.webui.utils.Utils.NT_UNSTRUCTURED)) return true;
646 return false;
647 }
648 }