1 17 package org.alfresco.web.bean; 18 19 import java.text.MessageFormat ; 20 import java.util.ArrayList ; 21 import java.util.Collections ; 22 import java.util.HashSet ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.Set ; 26 27 import javax.faces.application.FacesMessage; 28 import javax.faces.context.FacesContext; 29 import javax.faces.event.ActionEvent; 30 import javax.transaction.UserTransaction ; 31 32 import org.alfresco.config.Config; 33 import org.alfresco.config.ConfigElement; 34 import org.alfresco.config.ConfigService; 35 import org.alfresco.model.ContentModel; 36 import org.alfresco.service.cmr.dictionary.DictionaryService; 37 import org.alfresco.service.cmr.dictionary.TypeDefinition; 38 import org.alfresco.service.cmr.lock.LockService; 39 import org.alfresco.service.cmr.model.FileFolderService; 40 import org.alfresco.service.cmr.repository.ChildAssociationRef; 41 import org.alfresco.service.cmr.repository.ContentData; 42 import org.alfresco.service.cmr.repository.InvalidNodeRefException; 43 import org.alfresco.service.cmr.repository.NodeRef; 44 import org.alfresco.service.cmr.repository.NodeService; 45 import org.alfresco.service.cmr.repository.Path; 46 import org.alfresco.service.cmr.search.LimitBy; 47 import org.alfresco.service.cmr.search.ResultSet; 48 import org.alfresco.service.cmr.search.ResultSetRow; 49 import org.alfresco.service.cmr.search.SearchParameters; 50 import org.alfresco.service.cmr.search.SearchService; 51 import org.alfresco.service.cmr.security.PermissionService; 52 import org.alfresco.service.namespace.QName; 53 import org.alfresco.service.namespace.RegexQNamePattern; 54 import org.alfresco.web.app.AlfrescoNavigationHandler; 55 import org.alfresco.web.app.Application; 56 import org.alfresco.web.app.context.IContextListener; 57 import org.alfresco.web.app.context.UIContextService; 58 import org.alfresco.web.app.servlet.DownloadContentServlet; 59 import org.alfresco.web.app.servlet.FacesHelper; 60 import org.alfresco.web.bean.repository.MapNode; 61 import org.alfresco.web.bean.repository.Node; 62 import org.alfresco.web.bean.repository.NodePropertyResolver; 63 import org.alfresco.web.bean.repository.QNameNodeMap; 64 import org.alfresco.web.bean.repository.Repository; 65 import org.alfresco.web.bean.wizard.NewSpaceWizard; 66 import org.alfresco.web.config.ViewsConfigElement; 67 import org.alfresco.web.ui.common.Utils; 68 import org.alfresco.web.ui.common.Utils.URLMode; 69 import org.alfresco.web.ui.common.component.IBreadcrumbHandler; 70 import org.alfresco.web.ui.common.component.UIActionLink; 71 import org.alfresco.web.ui.common.component.UIBreadcrumb; 72 import org.alfresco.web.ui.common.component.UIModeList; 73 import org.alfresco.web.ui.common.component.UIStatusMessage; 74 import org.alfresco.web.ui.common.component.data.UIRichList; 75 import org.alfresco.web.ui.repo.component.IRepoBreadcrumbHandler; 76 import org.alfresco.web.ui.repo.component.UINodeDescendants; 77 import org.alfresco.web.ui.repo.component.UINodePath; 78 import org.alfresco.web.ui.repo.component.UISimpleSearch; 79 import org.apache.log4j.Logger; 80 import org.apache.log4j.Priority; 81 82 88 public class BrowseBean implements IContextListener 89 { 90 93 96 public BrowseBean() 97 { 98 UIContextService.getInstance(FacesContext.getCurrentInstance()).registerBean(this); 99 100 initFromClientConfig(); 101 } 102 103 104 107 110 public void setNodeService(NodeService nodeService) 111 { 112 this.nodeService = nodeService; 113 } 114 115 118 public void setSearchService(SearchService searchService) 119 { 120 this.searchService = searchService; 121 } 122 123 126 public void setLockService(LockService lockService) 127 { 128 this.lockService = lockService; 129 } 130 131 134 public void setNavigator(NavigationBean navigator) 135 { 136 this.navigator = navigator; 137 } 138 139 142 public void setDictionaryService(DictionaryService dictionaryService) 143 { 144 this.dictionaryService = dictionaryService; 145 } 146 147 150 public void setFileFolderService(FileFolderService fileFolderService) 151 { 152 this.fileFolderService = fileFolderService; 153 } 154 155 158 public String getBrowseViewMode() 159 { 160 return this.browseViewMode; 161 } 162 163 166 public void setBrowseViewMode(String browseViewMode) 167 { 168 this.browseViewMode = browseViewMode; 169 } 170 171 174 public boolean isDashboardView() 175 { 176 return this.dashboardView; 177 } 178 179 182 public void setDashboardView(boolean dashboardView) 183 { 184 this.dashboardView = dashboardView; 185 if (dashboardView == true) 186 { 187 FacesContext fc = FacesContext.getCurrentInstance(); 188 fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "dashboard"); 189 } 190 else 191 { 192 navigateBrowseScreen(); 193 } 194 } 195 196 199 public int getBrowsePageSize() 200 { 201 return this.browsePageSize; 202 } 203 204 207 public void setBrowsePageSize(int browsePageSize) 208 { 209 this.browsePageSize = browsePageSize; 210 } 211 212 215 public int getMinimumSearchLength() 216 { 217 return Application.getClientConfig(FacesContext.getCurrentInstance()). 218 getSearchMinimum(); 219 } 220 221 224 public Node getActionSpace() 225 { 226 return this.actionSpace; 227 } 228 229 232 public void setActionSpace(Node actionSpace) 233 { 234 if (actionSpace != null) 235 { 236 for (NodeEventListener listener : getNodeEventListeners()) 237 { 238 listener.created(actionSpace, actionSpace.getType()); 239 } 240 } 241 this.actionSpace = actionSpace; 242 } 243 244 247 public Node getDocument() 248 { 249 return this.document; 250 } 251 252 255 public void setDocument(Node document) 256 { 257 if (document != null) 258 { 259 for (NodeEventListener listener : getNodeEventListeners()) 260 { 261 listener.created(document, document.getType()); 262 } 263 } 264 this.document = document; 265 } 266 267 270 public void setContentRichList(UIRichList browseRichList) 271 { 272 this.contentRichList = browseRichList; 273 if (this.contentRichList != null) 274 { 275 this.contentRichList.setInitialSortColumn( 276 this.viewsConfig.getDefaultSortColumn(PAGE_NAME_BROWSE)); 277 this.contentRichList.setInitialSortDescending( 278 this.viewsConfig.hasDescendingSort(PAGE_NAME_BROWSE)); 279 } 280 if (externalForceRefresh) 284 { 285 this.contentRichList.setValue(null); 286 externalForceRefresh = false; 287 } 288 } 289 290 293 public UIRichList getContentRichList() 294 { 295 return this.contentRichList; 296 } 297 298 301 public void setSpacesRichList(UIRichList detailsRichList) 302 { 303 this.spacesRichList = detailsRichList; 304 if (this.spacesRichList != null) 305 { 306 this.spacesRichList.setInitialSortColumn( 308 this.viewsConfig.getDefaultSortColumn(PAGE_NAME_BROWSE)); 309 this.spacesRichList.setInitialSortDescending( 310 this.viewsConfig.hasDescendingSort(PAGE_NAME_BROWSE)); 311 } 312 if (externalForceRefresh) 313 { 314 this.spacesRichList.setValue(null); 315 } 316 } 317 318 321 public UIRichList getSpacesRichList() 322 { 323 return this.spacesRichList; 324 } 325 326 329 public UIStatusMessage getStatusMessage() 330 { 331 return this.statusMessage; 332 } 333 334 337 public void setStatusMessage(UIStatusMessage statusMessage) 338 { 339 this.statusMessage = statusMessage; 340 } 341 342 345 public String getDeleteMessage() 346 { 347 return this.deleteMessage; 348 } 349 350 353 public void setDeleteMessage(String deleteMessage) 354 { 355 this.deleteMessage = deleteMessage; 356 } 357 358 363 public List <Node> getNodes() 364 { 365 if (this.containerNodes == null) 370 { 371 if (this.navigator.getSearchContext() == null) 372 { 373 queryBrowseNodes(this.navigator.getCurrentNodeId()); 374 } 375 else 376 { 377 searchBrowseNodes(this.navigator.getSearchContext()); 378 } 379 } 380 List <Node> result = this.containerNodes; 381 382 384 return result; 385 } 386 387 392 public List <Node> getContent() 393 { 394 if (this.contentNodes == null) 396 { 397 if (this.navigator.getSearchContext() == null) 398 { 399 queryBrowseNodes(this.navigator.getCurrentNodeId()); 400 } 401 else 402 { 403 searchBrowseNodes(this.navigator.getSearchContext()); 404 } 405 } 406 List <Node> result = this.contentNodes; 407 408 410 return result; 411 } 412 413 424 public void setupCommonBindingProperties(Node node) 425 { 426 node.addPropertyResolver("locked", this.resolverlocked); 428 node.addPropertyResolver("owner", this.resolverOwner); 429 node.addPropertyResolver("workingCopy", this.resolverWorkingCopy); 430 node.addPropertyResolver("url", this.resolverUrl); 431 node.addPropertyResolver("fileType16", this.resolverFileType16); 432 node.addPropertyResolver("fileType32", this.resolverFileType32); 433 node.addPropertyResolver("size", this.resolverSize); 434 node.addPropertyResolver("cancelCheckOut", this.resolverCancelCheckOut); 435 node.addPropertyResolver("checkIn", this.resolverCheckIn); 436 node.addPropertyResolver("editLinkType", this.resolverEditLinkType); 437 node.addPropertyResolver("webdavUrl", this.resolverWebdavUrl); 438 node.addPropertyResolver("cifsPath", this.resolverCifsPath); 439 } 440 441 442 445 448 public void contextUpdated() 449 { 450 invalidateComponents(); 451 } 452 453 454 457 460 public void addNodeEventListener(NodeEventListener listener) 461 { 462 getNodeEventListeners().add(listener); 463 } 464 465 468 public void removeNodeEventListener(NodeEventListener listener) 469 { 470 getNodeEventListeners().remove(listener); 471 } 472 473 474 477 482 public void viewModeChanged(ActionEvent event) 483 { 484 UIModeList viewList = (UIModeList)event.getComponent(); 485 486 String viewMode = viewList.getValue().toString(); 488 489 if (VIEWMODE_DASHBOARD.equals(viewMode) == false) 490 { 491 setBrowsePageSize(this.viewsConfig.getDefaultPageSize(PAGE_NAME_BROWSE, 493 viewMode)); 494 495 if (logger.isDebugEnabled()) 496 logger.debug("Browse view page size set to: " + getBrowsePageSize()); 497 498 if (isDashboardView() == true) 500 { 501 setDashboardView(false); 502 } 503 504 setBrowseViewMode(viewMode); 506 } 507 else 508 { 509 setDashboardView(true); 511 } 512 } 513 514 515 518 523 private void queryBrowseNodes(String parentNodeId) 524 { 525 long startTime = 0; 526 if (logger.isDebugEnabled()) 527 startTime = System.currentTimeMillis(); 528 529 UserTransaction tx = null; 530 try 531 { 532 FacesContext context = FacesContext.getCurrentInstance(); 533 tx = Repository.getUserTransaction(context, true); 534 tx.begin(); 535 536 NodeRef parentRef; 537 if (parentNodeId == null) 538 { 539 parentRef = this.nodeService.getRootNode(Repository.getStoreRef()); 541 } 542 else 543 { 544 parentRef = new NodeRef(Repository.getStoreRef(), parentNodeId); 546 } 547 548 List <ChildAssociationRef> childRefs = this.nodeService.getChildAssocs(parentRef, 549 ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); 550 this.containerNodes = new ArrayList <Node>(childRefs.size()); 551 this.contentNodes = new ArrayList <Node>(childRefs.size()); 552 for (ChildAssociationRef ref: childRefs) 553 { 554 NodeRef nodeRef = ref.getChildRef(); 556 557 if (this.nodeService.exists(nodeRef)) 558 { 559 QName type = this.nodeService.getType(nodeRef); 561 562 TypeDefinition typeDef = this.dictionaryService.getType(type); 564 565 if (typeDef != null) 566 { 567 if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_FOLDER) == true && 569 this.dictionaryService.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) 570 { 571 MapNode node = new MapNode(nodeRef, this.nodeService, true); 573 node.addPropertyResolver("icon", this.resolverSpaceIcon); 574 node.addPropertyResolver("smallIcon", this.resolverSmallIcon); 575 576 for (NodeEventListener listener : getNodeEventListeners()) 577 { 578 listener.created(node, type); 579 } 580 581 this.containerNodes.add(node); 582 } 583 else if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)) 584 { 585 MapNode node = new MapNode(nodeRef, this.nodeService, true); 587 588 setupCommonBindingProperties(node); 589 590 for (NodeEventListener listener : getNodeEventListeners()) 591 { 592 listener.created(node, type); 593 } 594 595 this.contentNodes.add(node); 596 } 597 } 598 else 599 { 600 if (logger.isEnabledFor(Priority.WARN)) 601 logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type); 602 } 603 } 604 } 605 606 tx.commit(); 608 } 609 catch (InvalidNodeRefException refErr) 610 { 611 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 612 FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object [] {refErr.getNodeRef()}) ); 613 this.containerNodes = Collections.<Node>emptyList(); 614 this.contentNodes = Collections.<Node>emptyList(); 615 try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} 616 } 617 catch (Throwable err) 618 { 619 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 620 FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err); 621 this.containerNodes = Collections.<Node>emptyList(); 622 this.contentNodes = Collections.<Node>emptyList(); 623 try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} 624 } 625 626 if (logger.isDebugEnabled()) 627 { 628 long endTime = System.currentTimeMillis(); 629 logger.debug("Time to query and build map nodes: " + (endTime - startTime) + "ms"); 630 } 631 } 632 633 638 private void searchBrowseNodes(SearchContext searchContext) 639 { 640 long startTime = 0; 641 if (logger.isDebugEnabled()) 642 startTime = System.currentTimeMillis(); 643 644 String query = searchContext.buildQuery(getMinimumSearchLength()); 646 if (query == null) 647 { 648 Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_SEARCH_MINIMUM), 651 new Object [] {getMinimumSearchLength()})); 652 this.containerNodes = Collections.<Node>emptyList(); 653 this.contentNodes = Collections.<Node>emptyList(); 654 return; 655 } 656 657 UserTransaction tx = null; 659 ResultSet results = null; 660 try 661 { 662 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true); 663 tx.begin(); 664 665 SearchParameters sp = new SearchParameters(); 667 sp.setLanguage(SearchService.LANGUAGE_LUCENE); 668 sp.setQuery(query); 669 sp.addStore(Repository.getStoreRef()); 670 671 int searchLimit = Application.getClientConfig(FacesContext.getCurrentInstance()).getSearchMaxResults(); 672 if(searchLimit > 0) 673 { 674 sp.setLimitBy(LimitBy.FINAL_SIZE); 675 sp.setLimit(searchLimit); 676 } 677 678 results = this.searchService.query(sp); 679 if (logger.isDebugEnabled()) 680 logger.debug("Search results returned: " + results.length()); 681 682 this.containerNodes = new ArrayList <Node>(results.length()); 684 this.contentNodes = new ArrayList <Node>(results.length()); 685 if (results.length() != 0) 686 { 687 for (ResultSetRow row: results) 688 { 689 NodeRef nodeRef = row.getNodeRef(); 690 691 if (this.nodeService.exists(nodeRef)) 692 { 693 QName type = this.nodeService.getType(nodeRef); 695 696 TypeDefinition typeDef = this.dictionaryService.getType(type); 698 699 if (typeDef != null) 700 { 701 if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_FOLDER) && 703 this.dictionaryService.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) 704 { 705 MapNode node = new MapNode(nodeRef, this.nodeService, true); 707 708 node.addPropertyResolver("path", this.resolverPath); 709 node.addPropertyResolver("displayPath", this.resolverDisplayPath); 710 node.addPropertyResolver("icon", this.resolverSpaceIcon); 711 node.addPropertyResolver("smallIcon", this.resolverSmallIcon); 712 713 for (NodeEventListener listener : getNodeEventListeners()) 714 { 715 listener.created(node, type); 716 } 717 718 this.containerNodes.add(node); 719 } 720 else if (this.dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)) 721 { 722 MapNode node = new MapNode(nodeRef, this.nodeService, true); 724 725 setupCommonBindingProperties(node); 726 727 node.addPropertyResolver("path", this.resolverPath); 728 node.addPropertyResolver("displayPath", this.resolverDisplayPath); 729 730 for (NodeEventListener listener : getNodeEventListeners()) 731 { 732 listener.created(node, type); 733 } 734 735 this.contentNodes.add(node); 736 } 737 } 738 else 739 { 740 if (logger.isEnabledFor(Priority.WARN)) 741 logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type); 742 } 743 } 744 else 745 { 746 if (logger.isEnabledFor(Priority.WARN)) 747 logger.warn("Missing object returned from search indexes: id = " + nodeRef + " search query: " + query); 748 } 749 } 750 } 751 752 tx.commit(); 754 } 755 catch (InvalidNodeRefException refErr) 756 { 757 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 758 FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object [] {refErr.getNodeRef()}) ); 759 this.containerNodes = Collections.<Node>emptyList(); 760 this.contentNodes = Collections.<Node>emptyList(); 761 try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} 762 } 763 catch (Throwable err) 764 { 765 logger.info("Search failed for: " + query); 766 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 767 FacesContext.getCurrentInstance(), Repository.ERROR_SEARCH), new Object [] {err.getMessage()}), err ); 768 this.containerNodes = Collections.<Node>emptyList(); 769 this.contentNodes = Collections.<Node>emptyList(); 770 try { if (tx != null) {tx.rollback();} } catch (Exception tex) {} 771 } 772 finally 773 { 774 if (results != null) 775 { 776 results.close(); 777 } 778 } 779 780 if (logger.isDebugEnabled()) 781 { 782 long endTime = System.currentTimeMillis(); 783 logger.debug("Time to query and build map nodes: " + (endTime - startTime) + "ms"); 784 } 785 } 786 787 788 791 public NodePropertyResolver resolverlocked = new NodePropertyResolver() { 792 public Object get(Node node) { 793 return Repository.isNodeLocked(node, lockService); 794 } 795 }; 796 797 public NodePropertyResolver resolverOwner = new NodePropertyResolver() { 798 public Object get(Node node) { 799 return Repository.isNodeOwner(node, lockService); 800 } 801 }; 802 803 public NodePropertyResolver resolverCancelCheckOut = new NodePropertyResolver() { 804 public Object get(Node node) { 805 return node.hasAspect(ContentModel.ASPECT_WORKING_COPY) && node.hasPermission(PermissionService.CANCEL_CHECK_OUT); 806 } 807 }; 808 809 public NodePropertyResolver resolverCheckIn = new NodePropertyResolver() { 810 public Object get(Node node) { 811 return node.hasAspect(ContentModel.ASPECT_WORKING_COPY) && node.hasPermission(PermissionService.CHECK_IN); 812 } 813 }; 814 815 public NodePropertyResolver resolverWorkingCopy = new NodePropertyResolver() { 816 public Object get(Node node) { 817 return node.hasAspect(ContentModel.ASPECT_WORKING_COPY); 818 } 819 }; 820 821 public NodePropertyResolver resolverDownload = new NodePropertyResolver() { 822 public Object get(Node node) { 823 return DownloadContentServlet.generateDownloadURL(node.getNodeRef(), node.getName()); 824 } 825 }; 826 827 public NodePropertyResolver resolverUrl = new NodePropertyResolver() { 828 public Object get(Node node) { 829 return DownloadContentServlet.generateBrowserURL(node.getNodeRef(), node.getName()); 830 } 831 }; 832 833 public NodePropertyResolver resolverWebdavUrl = new NodePropertyResolver() { 834 public Object get(Node node) 835 { 836 return Utils.generateURL(FacesContext.getCurrentInstance(), node, URLMode.WEBDAV); 837 } 838 }; 839 840 public NodePropertyResolver resolverCifsPath = new NodePropertyResolver() { 841 public Object get(Node node) 842 { 843 return Utils.generateURL(FacesContext.getCurrentInstance(), node, URLMode.CIFS); 844 } 845 }; 846 847 public NodePropertyResolver resolverFileType16 = new NodePropertyResolver() { 848 public Object get(Node node) { 849 return Utils.getFileTypeImage(node.getName(), true); 850 } 851 }; 852 853 public NodePropertyResolver resolverFileType32 = new NodePropertyResolver() { 854 public Object get(Node node) { 855 return Utils.getFileTypeImage(node.getName(), false); 856 } 857 }; 858 859 public NodePropertyResolver resolverPath = new NodePropertyResolver() { 860 public Object get(Node node) { 861 return nodeService.getPath(node.getNodeRef()); 862 } 863 }; 864 865 public NodePropertyResolver resolverDisplayPath = new NodePropertyResolver() { 866 public Object get(Node node) { 867 return Repository.getDisplayPath( (Path)node.getProperties().get("path") ); 869 } 870 }; 871 872 public NodePropertyResolver resolverSpaceIcon = new NodePropertyResolver() { 873 public Object get(Node node) { 874 QNameNodeMap props = (QNameNodeMap)node.getProperties(); 875 String icon = (String )props.getRaw("app:icon"); 876 return (icon != null ? icon : NewSpaceWizard.SPACE_ICON_DEFAULT); 877 } 878 }; 879 880 public NodePropertyResolver resolverSmallIcon = new NodePropertyResolver() { 881 public Object get(Node node) { 882 QNameNodeMap props = (QNameNodeMap)node.getProperties(); 883 String icon = (String )props.getRaw("app:icon"); 884 return (icon != null ? icon + "-16" : SPACE_SMALL_DEFAULT); 885 } 886 }; 887 888 public NodePropertyResolver resolverMimetype = new NodePropertyResolver() { 889 public Object get(Node node) { 890 ContentData content = (ContentData)node.getProperties().get(ContentModel.PROP_CONTENT); 891 return (content != null ? content.getMimetype() : null); 892 } 893 }; 894 895 public NodePropertyResolver resolverSize = new NodePropertyResolver() { 896 public Object get(Node node) { 897 ContentData content = (ContentData)node.getProperties().get(ContentModel.PROP_CONTENT); 898 return (content != null ? new Long (content.getSize()) : null); 899 } 900 }; 901 902 public NodePropertyResolver resolverEditLinkType = new NodePropertyResolver() { 903 public Object get(Node node) 904 { 905 String editLinkType = "http"; 906 907 if (node.hasAspect(ContentModel.ASPECT_INLINEEDITABLE) == false) 910 { 911 editLinkType = Application.getClientConfig( 912 FacesContext.getCurrentInstance()).getEditLinkType(); 913 if (editLinkType == null) 914 { 915 editLinkType = "http"; 916 } 917 } 918 919 return editLinkType; 920 } 921 }; 922 923 924 927 931 public void search(ActionEvent event) 932 { 933 UISimpleSearch search = (UISimpleSearch)event.getComponent(); 935 this.navigator.setSearchContext(search.getSearchContext()); 936 937 navigateBrowseScreen(); 938 } 939 940 943 public void closeSearch(ActionEvent event) 944 { 945 this.navigator.setCurrentNodeId( this.navigator.getCurrentNodeId() ); 947 } 948 949 953 public void clickSpace(ActionEvent event) 954 { 955 UIActionLink link = (UIActionLink)event.getComponent(); 956 Map <String , String > params = link.getParameterMap(); 957 String id = params.get("id"); 958 if (id != null && id.length() != 0) 959 { 960 try 961 { 962 NodeRef ref = new NodeRef(Repository.getStoreRef(), id); 963 clickSpace(ref); 964 } 965 catch (InvalidNodeRefException refErr) 966 { 967 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 968 FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object [] {id}) ); 969 } 970 } 971 } 972 973 978 public void clickSpace(NodeRef nodeRef) 979 { 980 updateUILocation(nodeRef); 982 } 983 984 987 public void clickSpacePath(ActionEvent event) 988 { 989 UINodePath.PathElementEvent pathEvent = (UINodePath.PathElementEvent)event; 990 NodeRef ref = pathEvent.NodeReference; 991 try 992 { 993 this.updateUILocation(ref); 995 } 996 catch (InvalidNodeRefException refErr) 997 { 998 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 999 FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object [] {ref.getId()}) ); 1000 } 1001 } 1002 1003 1007 public void clickDescendantSpace(ActionEvent event) 1008 { 1009 UINodeDescendants.NodeSelectedEvent nodeEvent = (UINodeDescendants.NodeSelectedEvent)event; 1010 NodeRef nodeRef = nodeEvent.NodeReference; 1011 if (nodeRef == null) 1012 { 1013 throw new IllegalStateException ("NodeRef returned from UINodeDescendants.NodeSelectedEvent cannot be null!"); 1014 } 1015 1016 if (logger.isDebugEnabled()) 1017 logger.debug("Selected noderef Id: " + nodeRef.getId()); 1018 1019 try 1020 { 1021 List <IBreadcrumbHandler> location = this.navigator.getLocation(); 1024 ChildAssociationRef parentAssocRef = nodeService.getPrimaryParent(nodeRef); 1025 1026 if (logger.isDebugEnabled()) 1027 { 1028 logger.debug("Selected item getPrimaryParent().getChildRef() noderef Id: " + parentAssocRef.getChildRef().getId()); 1029 logger.debug("Selected item getPrimaryParent().getParentRef() noderef Id: " + parentAssocRef.getParentRef().getId()); 1030 logger.debug("Current value getNavigator().getCurrentNodeId() noderef Id: " + this.navigator.getCurrentNodeId()); 1031 } 1032 1033 if (nodeEvent.IsParent == false) 1034 { 1035 updateUILocation(parentAssocRef.getParentRef()); 1038 1039 updateUILocation(nodeRef); 1041 } 1042 else 1043 { 1044 updateUILocation(nodeRef); 1046 } 1047 } 1048 catch (InvalidNodeRefException refErr) 1049 { 1050 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 1051 FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object [] {nodeRef.getId()}) ); 1052 } 1053 } 1054 1055 1062 public void setupSpaceAction(ActionEvent event) 1063 { 1064 UIActionLink link = (UIActionLink)event.getComponent(); 1065 Map <String , String > params = link.getParameterMap(); 1066 String id = params.get("id"); 1067 setupSpaceAction(id, true); 1068 } 1069 1070 1075 public void setupSpaceAction(String id, boolean invalidate) 1076 { 1077 if (id != null && id.length() != 0) 1078 { 1079 if (logger.isDebugEnabled()) 1080 logger.debug("Setup for action, setting current space to: " + id); 1081 1082 try 1083 { 1084 NodeRef ref = new NodeRef(Repository.getStoreRef(), id); 1086 Node node = new Node(ref); 1087 1088 node.addPropertyResolver("icon", this.resolverSpaceIcon); 1090 1091 setActionSpace(node); 1093 1094 this.navigator.setupDispatchContext(node); 1096 } 1097 catch (InvalidNodeRefException refErr) 1098 { 1099 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 1100 FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object [] {id}) ); 1101 } 1102 } 1103 else 1104 { 1105 setActionSpace(null); 1106 } 1107 1108 if (invalidate == true) 1110 { 1111 UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans(); 1113 } 1114 } 1115 1116 1120 public void setupDeleteAction(ActionEvent event) 1121 { 1122 String message = null; 1123 1124 setupSpaceAction(event); 1125 1126 Node node = getActionSpace(); 1127 if (node != null) 1128 { 1129 NodeRef companyRootRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId()); 1130 if (node.getNodeRef().equals(companyRootRef)) 1131 { 1132 message = Application.getMessage(FacesContext.getCurrentInstance(), MSG_DELETE_COMPANYROOT); 1133 } 1134 } 1135 1136 setDeleteMessage(message); 1137 } 1138 1139 1144 public void setupContentAction(ActionEvent event) 1145 { 1146 UIActionLink link = (UIActionLink)event.getComponent(); 1147 Map <String , String > params = link.getParameterMap(); 1148 setupContentAction(params.get("id"), true); 1149 } 1150 1151 1156 public void setupContentAction(String id, boolean invalidate) 1157 { 1158 if (id != null && id.length() != 0) 1159 { 1160 if (logger.isDebugEnabled()) 1161 logger.debug("Setup for action, setting current document to: " + id); 1162 1163 try 1164 { 1165 NodeRef ref = new NodeRef(Repository.getStoreRef(), id); 1167 Node node = new Node(ref); 1168 1169 node.addPropertyResolver("url", this.resolverDownload); 1171 node.addPropertyResolver("fileType32", this.resolverFileType32); 1172 node.addPropertyResolver("mimetype", this.resolverMimetype); 1173 node.addPropertyResolver("size", this.resolverSize); 1174 node.addPropertyResolver("cancelCheckOut", this.resolverCancelCheckOut); 1175 node.addPropertyResolver("checkIn", this.resolverCheckIn); 1176 1177 for (NodeEventListener listener : getNodeEventListeners()) 1178 { 1179 listener.created(node, node.getType()); 1180 } 1181 1182 DocumentDetailsBean docDetails = (DocumentDetailsBean)FacesContext.getCurrentInstance(). 1184 getExternalContext().getSessionMap().get("DocumentDetailsBean"); 1185 if (docDetails != null) 1186 { 1187 docDetails.reset(); 1188 } 1189 1190 setDocument(node); 1192 1193 this.navigator.setupDispatchContext(node); 1195 } 1196 catch (InvalidNodeRefException refErr) 1197 { 1198 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 1199 FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object [] {id}) ); 1200 } 1201 } 1202 else 1203 { 1204 setDocument(null); 1205 } 1206 1207 if (invalidate == true) 1209 { 1210 UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans(); 1212 } 1213 } 1214 1215 1220 public String deleteSpaceOK() 1221 { 1222 String outcome = null; 1223 1224 Node node = getActionSpace(); 1225 if (node != null) 1226 { 1227 try 1228 { 1229 if (logger.isDebugEnabled()) 1230 logger.debug("Trying to delete space: " + node.getId()); 1231 1232 this.nodeService.deleteNode(node.getNodeRef()); 1233 1234 List <IBreadcrumbHandler> location = navigator.getLocation(); 1236 IBreadcrumbHandler handler = location.get(location.size() - 1); 1237 if (handler instanceof BrowseBreadcrumbHandler) 1238 { 1239 if ( ((BrowseBreadcrumbHandler)handler).getNodeRef().equals(node.getNodeRef()) == true ) 1241 { 1242 location.remove(location.size() - 1); 1243 1244 if (location.size() != 0) 1246 { 1247 handler = location.get(location.size() - 1); 1248 if (handler instanceof BrowseBreadcrumbHandler) 1249 { 1250 navigator.setCurrentNodeId(((BrowseBreadcrumbHandler)handler).getNodeRef().getId()); 1252 } 1253 else 1254 { 1255 navigator.setCurrentNodeId(Application.getCurrentUser(FacesContext.getCurrentInstance()).getHomeSpaceId()); 1257 } 1258 } 1259 } 1260 } 1261 1262 String statusMsg = MessageFormat.format( 1264 Application.getMessage(FacesContext.getCurrentInstance(), "status_space_deleted"), 1265 new Object []{node.getName()}); 1266 Utils.addStatusMessage(FacesMessage.SEVERITY_INFO, statusMsg); 1267 1268 setActionSpace(null); 1270 1271 outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME + 1273 AlfrescoNavigationHandler.DIALOG_SEPARATOR + "browse"; 1274 } 1275 catch (Throwable err) 1276 { 1277 Utils.addErrorMessage(Application.getMessage( 1278 FacesContext.getCurrentInstance(), MSG_ERROR_DELETE_SPACE) + err.getMessage(), err); 1279 } 1280 } 1281 else 1282 { 1283 logger.warn("WARNING: deleteSpaceOK called without a current Space!"); 1284 } 1285 1286 return outcome; 1287 } 1288 1289 1294 public String deleteFileOK() 1295 { 1296 String outcome = null; 1297 1298 Node node = getDocument(); 1299 if (node != null) 1300 { 1301 try 1302 { 1303 if (logger.isDebugEnabled()) 1304 logger.debug("Trying to delete content node: " + node.getId()); 1305 1306 this.nodeService.deleteNode(node.getNodeRef()); 1307 1308 setDocument(null); 1310 1311 outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME + 1313 AlfrescoNavigationHandler.DIALOG_SEPARATOR + "browse"; 1314 } 1315 catch (Throwable err) 1316 { 1317 Utils.addErrorMessage(Application.getMessage( 1318 FacesContext.getCurrentInstance(), MSG_ERROR_DELETE_FILE) + err.getMessage(), err); 1319 } 1320 } 1321 else 1322 { 1323 logger.warn("WARNING: deleteFileOK called without a current Document!"); 1324 } 1325 1326 return outcome; 1327 } 1328 1329 1334 public void externalAccessRefresh() 1335 { 1336 this.externalForceRefresh = true; 1337 } 1338 1339 1340 1343 1346 private void initFromClientConfig() 1347 { 1348 ConfigService config = Application.getConfigService(FacesContext.getCurrentInstance()); 1349 1350 this.viewsConfig = (ViewsConfigElement)config.getConfig("Views"). 1351 getConfigElement(ViewsConfigElement.CONFIG_ELEMENT_ID); 1352 1353 this.browseViewMode = this.viewsConfig.getDefaultView(PAGE_NAME_BROWSE); 1354 this.browsePageSize = this.viewsConfig.getDefaultPageSize(PAGE_NAME_BROWSE, 1355 this.browseViewMode); 1356 } 1357 1358 1361 private Set <NodeEventListener> getNodeEventListeners() 1362 { 1363 if (this.nodeEventListeners == null) 1364 { 1365 this.nodeEventListeners = new HashSet <NodeEventListener>(); 1366 1367 FacesContext fc = FacesContext.getCurrentInstance(); 1368 1369 Config listenerConfig = Application.getConfigService(fc).getConfig("Node Event Listeners"); 1370 if (listenerConfig != null) 1371 { 1372 ConfigElement listenerElement = listenerConfig.getConfigElement("node-event-listeners"); 1373 if (listenerElement != null) 1374 { 1375 for (ConfigElement child : listenerElement.getChildren()) 1376 { 1377 if (child.getName().equals("listener")) 1378 { 1379 String listenerName = child.getValue().trim(); 1381 Object bean = FacesHelper.getManagedBean(fc, listenerName); 1382 if (bean instanceof NodeEventListener) 1383 { 1384 addNodeEventListener((NodeEventListener)bean); 1385 } 1386 } 1387 } 1388 } 1389 } 1390 } 1391 return this.nodeEventListeners; 1392 } 1393 1394 1400 public void updateUILocation(NodeRef ref) 1401 { 1402 List <IBreadcrumbHandler> location = this.navigator.getLocation(); 1405 if (location.size() != 0) 1406 { 1407 boolean foundNode = false; 1410 for (int i=0; i<location.size(); i++) 1411 { 1412 IBreadcrumbHandler element = location.get(i); 1413 if (element instanceof IRepoBreadcrumbHandler) 1414 { 1415 NodeRef nodeRef = ((IRepoBreadcrumbHandler)element).getNodeRef(); 1416 if (ref.equals(nodeRef) == true) 1417 { 1418 int count = location.size(); 1426 for (int n=i+1; n<count; n++) 1427 { 1428 location.remove(i+1); 1429 } 1430 1431 foundNode = true; 1432 break; 1433 } 1434 } 1435 } 1436 1437 if (foundNode == false) 1439 { 1440 String name = Repository.getNameForNode(this.nodeService, ref); 1441 location.add(new BrowseBreadcrumbHandler(ref, name)); 1442 } 1443 } 1444 else 1445 { 1446 String name = Repository.getNameForNode(this.nodeService, ref); 1448 location.add(new BrowseBreadcrumbHandler(ref, name)); 1449 } 1450 1451 this.navigator.setCurrentNodeId(ref.getId()); 1453 1454 this.navigator.setupDispatchContext(new Node(ref)); 1456 1457 navigateBrowseScreen(); 1458 } 1459 1460 1463 private void invalidateComponents() 1464 { 1465 if (logger.isDebugEnabled()) 1466 logger.debug("Invalidating browse components..."); 1467 1468 if (this.contentRichList != null) 1470 { 1471 this.contentRichList.setValue(null); 1472 if (this.navigator.getSearchContext() != null) 1473 { 1474 this.contentRichList.clearSort(); 1476 } 1477 } 1478 if (this.spacesRichList != null) 1479 { 1480 this.spacesRichList.setValue(null); 1481 if (this.navigator.getSearchContext() != null) 1482 { 1483 this.spacesRichList.clearSort(); 1485 } 1486 } 1487 1488 this.containerNodes = null; 1490 this.contentNodes = null; 1491 } 1492 1493 1496 private boolean isViewCurrent() 1497 { 1498 return (FacesContext.getCurrentInstance().getViewRoot().getViewId().equals(BROWSE_VIEW_ID)); 1499 } 1500 1501 1504 private void navigateBrowseScreen() 1505 { 1506 String outcome = null; 1507 1508 if (isViewCurrent() == false) 1509 { 1510 outcome = "browse"; 1511 } 1512 1513 FacesContext fc = FacesContext.getCurrentInstance(); 1514 fc.getApplication().getNavigationHandler().handleNavigation(fc, null, outcome); 1515 } 1516 1517 1518 1521 1524 private class BrowseBreadcrumbHandler implements IRepoBreadcrumbHandler 1525 { 1526 private static final long serialVersionUID = 3833183653173016630L; 1527 1528 1534 public BrowseBreadcrumbHandler(NodeRef nodeRef, String label) 1535 { 1536 this.label = label; 1537 this.nodeRef = nodeRef; 1538 } 1539 1540 1543 public String toString() 1544 { 1545 return this.label; 1546 } 1547 1548 1551 @SuppressWarnings ("unchecked") 1552 public String navigationOutcome(UIBreadcrumb breadcrumb) 1553 { 1554 navigator.setCurrentNodeId(this.nodeRef.getId()); 1557 navigator.setLocation( (List )breadcrumb.getValue() ); 1558 1559 navigator.setupDispatchContext(new Node(this.nodeRef)); 1561 1562 return (isViewCurrent() ? null : "browse"); 1564 } 1565 1566 public NodeRef getNodeRef() 1567 { 1568 return this.nodeRef; 1569 } 1570 1571 private NodeRef nodeRef; 1572 private String label; 1573 } 1574 1575 1576 1579 1580 public static final String BROWSE_VIEW_ID = "/jsp/browse/browse.jsp"; 1581 1582 1583 public static final String SPACE_SMALL_DEFAULT = "space_small"; 1584 1585 private static final String VIEWMODE_DASHBOARD = "dashboard"; 1586 private static final String PAGE_NAME_BROWSE = "browse"; 1587 1588 1589 private static final String MSG_ERROR_DELETE_FILE = "error_delete_file"; 1590 private static final String MSG_ERROR_DELETE_SPACE = "error_delete_space"; 1591 private static final String MSG_DELETE_COMPANYROOT = "delete_companyroot_confirm"; 1592 private static final String MSG_SEARCH_MINIMUM = "search_minimum"; 1593 1594 private static Logger logger = Logger.getLogger(BrowseBean.class); 1595 1596 1597 protected NodeService nodeService; 1598 1599 1600 protected SearchService searchService; 1601 1602 1603 protected LockService lockService; 1604 1605 1606 protected NavigationBean navigator; 1607 1608 1609 protected DictionaryService dictionaryService; 1610 1611 1612 protected FileFolderService fileFolderService; 1613 1614 1615 protected ViewsConfigElement viewsConfig = null; 1616 1617 1618 private Set <NodeEventListener> nodeEventListeners = null; 1619 1620 1621 protected UIRichList spacesRichList; 1622 protected UIRichList contentRichList; 1623 private UIStatusMessage statusMessage; 1624 1625 1626 private List <Node> containerNodes = null; 1627 private List <Node> contentNodes = null; 1628 1629 1630 private Node actionSpace; 1631 1632 1633 private Node document; 1634 1635 1636 private String deleteMessage; 1637 1638 1639 private String browseViewMode; 1640 1641 1642 private int browsePageSize; 1643 1644 1645 private boolean dashboardView; 1646 1647 private boolean externalForceRefresh = false; 1648} 1649 | Popular Tags |