1 17 package org.alfresco.web.bean; 18 19 import java.io.Serializable ; 20 import java.text.MessageFormat ; 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import java.util.Map ; 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.error.AlfrescoRuntimeException; 33 import org.alfresco.model.ContentModel; 34 import org.alfresco.repo.content.MimetypeMap; 35 import org.alfresco.service.cmr.lock.LockService; 36 import org.alfresco.service.cmr.repository.ContentData; 37 import org.alfresco.service.cmr.repository.CopyService; 38 import org.alfresco.service.cmr.repository.NodeRef; 39 import org.alfresco.service.cmr.repository.NodeService; 40 import org.alfresco.service.cmr.repository.TemplateImageResolver; 41 import org.alfresco.service.cmr.repository.TemplateNode; 42 import org.alfresco.service.cmr.security.OwnableService; 43 import org.alfresco.service.cmr.version.Version; 44 import org.alfresco.service.cmr.version.VersionHistory; 45 import org.alfresco.service.cmr.version.VersionService; 46 import org.alfresco.service.namespace.NamespaceService; 47 import org.alfresco.service.namespace.QName; 48 import org.alfresco.web.app.Application; 49 import org.alfresco.web.app.context.UIContextService; 50 import org.alfresco.web.app.servlet.DownloadContentServlet; 51 import org.alfresco.web.bean.repository.MapNode; 52 import org.alfresco.web.bean.repository.Node; 53 import org.alfresco.web.bean.repository.Repository; 54 import org.alfresco.web.bean.wizard.NewRuleWizard; 55 import org.alfresco.web.ui.common.Utils; 56 import org.alfresco.web.ui.common.Utils.URLMode; 57 import org.alfresco.web.ui.common.component.UIActionLink; 58 import org.alfresco.web.ui.common.component.UIPanel.ExpandedEvent; 59 import org.apache.log4j.Logger; 60 61 66 public class DocumentDetailsBean 67 { 68 private static final String MSG_SUCCESS_OWNERSHIP = "success_ownership"; 69 private static final String MSG_HAS_FOLLOWING_CATEGORIES = "has_following_categories"; 70 private static final String MSG_NO_CATEGORIES_APPLIED = "no_categories_applied"; 71 private static final String MSG_ERROR_ASPECT_INLINEEDITABLE = "error_aspect_inlineeditable"; 72 private static final String MSG_ERROR_ASPECT_VERSIONING = "error_aspect_versioning"; 73 private static final String MSG_ERROR_ASPECT_CLASSIFY = "error_aspect_classify"; 74 private static final String MSG_ERROR_WORKFLOW_REJECT = "error_workflow_reject"; 75 private static final String MSG_ERROR_WORKFLOW_APPROVE = "error_workflow_approve"; 76 private static final String MSG_ERROR_UPDATE_SIMPLEWORKFLOW = "error_update_simpleworkflow"; 77 private static final String MSG_ERROR_UPDATE_CATEGORY = "error_update_category"; 78 79 private static Logger logger = Logger.getLogger(DocumentDetailsBean.class); 80 81 protected BrowseBean browseBean; 82 protected NodeService nodeService; 83 protected LockService lockService; 84 protected CopyService copyService; 85 protected VersionService versionService; 86 protected OwnableService ownableService; 87 protected NavigationBean navigator; 88 89 private Map <String , Boolean > panels = new HashMap <String , Boolean >(5, 1.0f); 90 91 private Map <String , Serializable > workflowProperties; 92 private NodeRef addedCategory; 93 private List categories; 94 95 96 99 public DocumentDetailsBean() 100 { 101 panels.put("workflow-panel", false); 103 panels.put("category-panel", false); 104 panels.put("version-history-panel", false); 105 } 106 107 110 public void reset() 111 { 112 this.workflowProperties = null; 114 115 this.categories = null; 117 this.addedCategory = null; 118 } 119 120 125 public String getId() 126 { 127 return getDocument().getId(); 128 } 129 130 135 public String getName() 136 { 137 return getDocument().getName(); 138 } 139 140 145 public String getUrl() 146 { 147 return (String )getDocument().getProperties().get("url"); 148 } 149 150 155 public String getBrowserUrl() 156 { 157 return Utils.generateURL(FacesContext.getCurrentInstance(), getDocument(), URLMode.HTTP_INLINE); 158 } 159 160 165 public String getDownloadUrl() 166 { 167 return Utils.generateURL(FacesContext.getCurrentInstance(), getDocument(), URLMode.HTTP_DOWNLOAD); 168 } 169 170 175 public String getWebdavUrl() 176 { 177 return Utils.generateURL(FacesContext.getCurrentInstance(), getDocument(), URLMode.WEBDAV); 178 } 179 180 185 public String getBookmarkUrl() 186 { 187 return Utils.generateURL(FacesContext.getCurrentInstance(), getDocument(), URLMode.SHOW_DETAILS); 188 } 189 190 195 public String getCifsPath() 196 { 197 return Utils.generateURL(FacesContext.getCurrentInstance(), getDocument(), URLMode.CIFS); 198 } 199 200 205 public String getNodeRefUrl() 206 { 207 return getDocument().getNodeRef().toString(); 208 } 209 210 215 public boolean isVersionable() 216 { 217 return getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE); 218 } 219 220 223 public boolean isInlineEditable() 224 { 225 return getDocument().hasAspect(ContentModel.ASPECT_INLINEEDITABLE); 226 } 227 228 234 public List getVersionHistory() 235 { 236 List <MapNode> versions = new ArrayList <MapNode>(); 237 238 if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE)) 239 { 240 VersionHistory history = this.versionService.getVersionHistory(getDocument().getNodeRef()); 241 242 if (history != null) 243 { 244 for (Version version : history.getAllVersions()) 245 { 246 MapNode clientVersion = new MapNode(version.getFrozenStateNodeRef()); 248 clientVersion.put("versionLabel", version.getVersionLabel()); 249 clientVersion.put("notes", version.getDescription()); 250 clientVersion.put("author", version.getCreator()); 251 clientVersion.put("versionDate", version.getCreatedDate()); 252 clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(), 253 clientVersion.getName())); 254 255 versions.add(clientVersion); 257 } 258 } 259 } 260 261 return versions; 262 } 263 264 269 public boolean isCategorised() 270 { 271 return getDocument().hasAspect(ContentModel.ASPECT_GEN_CLASSIFIABLE); 272 } 273 274 280 public String getCategoriesOverviewHTML() 281 { 282 String html = null; 283 284 if (isCategorised()) 285 { 286 Collection categories = (Collection )this.nodeService.getProperty(this.browseBean.getDocument().getNodeRef(), 289 ContentModel.PROP_CATEGORIES); 290 291 if (categories == null || categories.size() == 0) 292 { 293 html = Application.getMessage(FacesContext.getCurrentInstance(), MSG_NO_CATEGORIES_APPLIED); 294 } 295 else 296 { 297 StringBuilder builder = new StringBuilder (Application.getMessage(FacesContext.getCurrentInstance(), 298 MSG_HAS_FOLLOWING_CATEGORIES)); 299 300 builder.append("<ul>"); 301 for (Object obj : categories) 302 { 303 if (obj instanceof NodeRef) 304 { 305 if (this.nodeService.exists((NodeRef)obj)) 306 { 307 builder.append("<li>"); 308 builder.append(Repository.getNameForNode(this.nodeService, (NodeRef)obj)); 309 builder.append("</li>"); 310 } 311 } 312 } 313 builder.append("</ul>"); 314 315 html = builder.toString(); 316 } 317 } 318 319 return html; 320 } 321 322 327 public void setupCategoriesForEdit(ActionEvent event) 328 { 329 this.categories = (List )this.nodeService.getProperty(this.browseBean.getDocument().getNodeRef(), 330 ContentModel.PROP_CATEGORIES); 331 } 332 333 338 public List getCategories() 339 { 340 return this.categories; 341 } 342 343 348 public void setCategories(List categories) 349 { 350 this.categories = categories; 351 } 352 353 358 public NodeRef getAddedCategory() 359 { 360 return this.addedCategory; 361 } 362 363 368 public void setAddedCategory(NodeRef addedCategory) 369 { 370 this.addedCategory = addedCategory; 371 } 372 373 378 public String saveCategories() 379 { 380 String outcome = "cancel"; 381 382 UserTransaction tx = null; 383 384 try 385 { 386 FacesContext context = FacesContext.getCurrentInstance(); 387 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 388 tx.begin(); 389 390 Map <QName, Serializable > updateProps = this.nodeService.getProperties( 392 getDocument().getNodeRef()); 393 394 updateProps.put(ContentModel.PROP_CATEGORIES, (Serializable )this.categories); 396 397 this.nodeService.setProperties(getDocument().getNodeRef(), updateProps); 399 400 tx.commit(); 402 403 getDocument().reset(); 405 406 outcome = "finish"; 407 } 408 catch (Throwable e) 409 { 410 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 411 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 412 FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE_CATEGORY), e.getMessage()), e); 413 } 414 415 return outcome; 416 } 417 418 424 public String getWorkflowOverviewHTML() 425 { 426 String html = null; 427 428 if (getDocument().hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW)) 429 { 430 Map <String , Object > props = getDocument().getProperties(); 432 433 String approveStepName = (String )props.get( 434 ContentModel.PROP_APPROVE_STEP.toString()); 435 String rejectStepName = (String )props.get( 436 ContentModel.PROP_REJECT_STEP.toString()); 437 438 Boolean approveMove = (Boolean )props.get( 439 ContentModel.PROP_APPROVE_MOVE.toString()); 440 Boolean rejectMove = (Boolean )props.get( 441 ContentModel.PROP_REJECT_MOVE.toString()); 442 443 NodeRef approveFolder = (NodeRef)props.get( 444 ContentModel.PROP_APPROVE_FOLDER.toString()); 445 NodeRef rejectFolder = (NodeRef)props.get( 446 ContentModel.PROP_REJECT_FOLDER.toString()); 447 448 String approveFolderName = null; 449 String rejectFolderName = null; 450 451 if (approveFolder != null) 453 { 454 Node node = new Node(approveFolder); 455 approveFolderName = node.getName(); 456 } 457 458 if (rejectFolder != null) 460 { 461 Node node = new Node(rejectFolder); 462 rejectFolderName = node.getName(); 463 } 464 465 StringBuilder builder = new StringBuilder (); 466 467 String action = null; 469 if (approveMove.booleanValue()) 470 { 471 action = Application.getMessage(FacesContext.getCurrentInstance(), "moved"); 472 } 473 else 474 { 475 action = Application.getMessage(FacesContext.getCurrentInstance(), "copied"); 476 } 477 478 String docActionPattern = Application.getMessage(FacesContext.getCurrentInstance(), "document_action"); 479 Object [] params = new Object [] {action, approveFolderName, approveStepName}; 480 builder.append(MessageFormat.format(docActionPattern, params)); 481 482 if (rejectStepName != null && rejectMove != null && rejectFolderName != null) 484 { 485 if (rejectMove.booleanValue()) 486 { 487 action = Application.getMessage(FacesContext.getCurrentInstance(), "moved"); 488 } 489 else 490 { 491 action = Application.getMessage(FacesContext.getCurrentInstance(), "copied"); 492 } 493 494 builder.append("<p>"); 495 params = new Object [] {action, rejectFolderName, rejectStepName}; 496 builder.append(MessageFormat.format(docActionPattern, params)); 497 builder.append("</p>"); 498 } 499 500 html = builder.toString(); 501 } 502 503 return html; 504 } 505 506 511 public Map <String , Serializable > getWorkflowProperties() 512 { 513 if (this.workflowProperties == null && 514 getDocument().hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW)) 515 { 516 Map <String , Object > props = getDocument().getProperties(); 518 519 String approveStepName = (String )props.get( 520 ContentModel.PROP_APPROVE_STEP.toString()); 521 String rejectStepName = (String )props.get( 522 ContentModel.PROP_REJECT_STEP.toString()); 523 524 Boolean approveMove = (Boolean )props.get( 525 ContentModel.PROP_APPROVE_MOVE.toString()); 526 Boolean rejectMove = (Boolean )props.get( 527 ContentModel.PROP_REJECT_MOVE.toString()); 528 529 NodeRef approveFolder = (NodeRef)props.get( 530 ContentModel.PROP_APPROVE_FOLDER.toString()); 531 NodeRef rejectFolder = (NodeRef)props.get( 532 ContentModel.PROP_REJECT_FOLDER.toString()); 533 534 this.workflowProperties = new HashMap <String , Serializable >(7); 536 this.workflowProperties.put(NewRuleWizard.PROP_APPROVE_STEP_NAME, 537 approveStepName); 538 this.workflowProperties.put(NewRuleWizard.PROP_APPROVE_ACTION, 539 approveMove ? "move" : "copy"); 540 this.workflowProperties.put(NewRuleWizard.PROP_APPROVE_FOLDER, approveFolder); 541 542 if (rejectStepName == null || rejectMove == null || rejectFolder == null) 543 { 544 this.workflowProperties.put(NewRuleWizard.PROP_REJECT_STEP_PRESENT, "no"); 545 } 546 else 547 { 548 this.workflowProperties.put(NewRuleWizard.PROP_REJECT_STEP_PRESENT, 549 "yes"); 550 this.workflowProperties.put(NewRuleWizard.PROP_REJECT_STEP_NAME, 551 rejectStepName); 552 this.workflowProperties.put(NewRuleWizard.PROP_REJECT_ACTION, 553 rejectMove ? "move" : "copy"); 554 this.workflowProperties.put(NewRuleWizard.PROP_REJECT_FOLDER, 555 rejectFolder); 556 } 557 } 558 559 return this.workflowProperties; 560 } 561 562 566 public String cancelWorkflowEdit() 567 { 568 this.workflowProperties.clear(); 571 this.workflowProperties = null; 572 return "cancel"; 573 } 574 575 581 public String saveWorkflow() 582 { 583 String outcome = "cancel"; 584 585 UserTransaction tx = null; 586 587 try 588 { 589 FacesContext context = FacesContext.getCurrentInstance(); 590 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 591 tx.begin(); 592 593 Map <QName, Serializable > updateProps = this.nodeService.getProperties( 595 getDocument().getNodeRef()); 596 597 599 updateProps.put(ContentModel.PROP_APPROVE_STEP, 601 this.workflowProperties.get(NewRuleWizard.PROP_APPROVE_STEP_NAME)); 602 603 boolean approveMove = true; 605 String approveAction = (String )this.workflowProperties.get(NewRuleWizard.PROP_APPROVE_ACTION); 606 if (approveAction != null && approveAction.equals("copy")) 607 { 608 approveMove = false; 609 } 610 updateProps.put(ContentModel.PROP_APPROVE_MOVE, Boolean.valueOf(approveMove)); 611 612 updateProps.put(ContentModel.PROP_APPROVE_FOLDER, 614 this.workflowProperties.get(NewRuleWizard.PROP_APPROVE_FOLDER)); 615 616 boolean requireReject = true; 618 String rejectStepPresent = (String )this.workflowProperties.get( 619 NewRuleWizard.PROP_REJECT_STEP_PRESENT); 620 if (rejectStepPresent != null && rejectStepPresent.equals("no")) 621 { 622 requireReject = false; 623 } 624 625 if (requireReject) 626 { 627 updateProps.put(ContentModel.PROP_REJECT_STEP, 629 this.workflowProperties.get(NewRuleWizard.PROP_REJECT_STEP_NAME)); 630 631 boolean rejectMove = true; 633 String rejectAction = (String )this.workflowProperties.get( 634 NewRuleWizard.PROP_REJECT_ACTION); 635 if (rejectAction != null && rejectAction.equals("copy")) 636 { 637 rejectMove = false; 638 } 639 updateProps.put(ContentModel.PROP_REJECT_MOVE, Boolean.valueOf(rejectMove)); 640 641 updateProps.put(ContentModel.PROP_REJECT_FOLDER, 643 this.workflowProperties.get(NewRuleWizard.PROP_REJECT_FOLDER)); 644 } 645 else 646 { 647 updateProps.put(ContentModel.PROP_REJECT_STEP, null); 650 updateProps.put(ContentModel.PROP_REJECT_MOVE, null); 651 updateProps.put(ContentModel.PROP_REJECT_FOLDER, null); 652 } 653 654 this.nodeService.setProperties(getDocument().getNodeRef(), updateProps); 656 657 tx.commit(); 659 660 getDocument().reset(); 662 663 outcome = "finish"; 664 } 665 catch (Throwable e) 666 { 667 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 668 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 669 FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE_SIMPLEWORKFLOW), e.getMessage()), e); 670 } 671 672 return outcome; 673 } 674 675 680 public String getApproveStepName() 681 { 682 String approveStepName = null; 683 684 if (getDocument().hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW)) 685 { 686 approveStepName = (String )getDocument().getProperties().get( 687 ContentModel.PROP_APPROVE_STEP.toString()); 688 } 689 690 return approveStepName; 691 } 692 693 698 public void approve(ActionEvent event) 699 { 700 UIActionLink link = (UIActionLink)event.getComponent(); 701 Map <String , String > params = link.getParameterMap(); 702 String id = params.get("id"); 703 if (id == null || id.length() == 0) 704 { 705 throw new AlfrescoRuntimeException("approve called without an id"); 706 } 707 708 NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id); 709 Node docNode = new Node(docNodeRef); 710 711 if (docNode.hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW) == false) 712 { 713 throw new AlfrescoRuntimeException("You can not approve a document that is not part of a workflow"); 714 } 715 716 Map <String , Object > props = docNode.getProperties(); 718 719 Boolean approveMove = (Boolean )props.get(ContentModel.PROP_APPROVE_MOVE.toString()); 720 NodeRef approveFolder = (NodeRef)props.get(ContentModel.PROP_APPROVE_FOLDER.toString()); 721 722 UserTransaction tx = null; 723 try 724 { 725 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 726 tx.begin(); 727 728 this.nodeService.removeAspect(docNodeRef, ContentModel.ASPECT_SIMPLE_WORKFLOW); 730 731 if (approveMove.booleanValue()) 732 { 733 String qname = QName.createValidLocalName(docNode.getName()); 735 this.nodeService.moveNode(docNodeRef, approveFolder, ContentModel.ASSOC_CONTAINS, 736 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname)); 737 } 738 else 739 { 740 String qname = QName.createValidLocalName(docNode.getName()); 742 this.copyService.copy(docNodeRef, approveFolder, ContentModel.ASSOC_CONTAINS, 743 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname)); 744 } 745 746 tx.commit(); 748 749 if (getDocument() != null) 751 { 752 getDocument().reset(); 753 } 754 755 UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans(); 757 758 if (logger.isDebugEnabled()) 759 { 760 String movedCopied = approveMove ? "moved" : "copied"; 761 logger.debug("Document has been approved and " + movedCopied + " to folder with id of " + 762 approveFolder.getId()); 763 } 764 } 765 catch (Throwable e) 766 { 767 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 769 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 770 FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_APPROVE), e.getMessage()), e); 771 } 772 } 773 774 779 public String getRejectStepName() 780 { 781 String approveStepName = null; 782 783 if (getDocument().hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW)) 784 { 785 approveStepName = (String )getDocument().getProperties().get( 786 ContentModel.PROP_REJECT_STEP.toString()); 787 } 788 789 return approveStepName; 790 } 791 792 797 public void reject(ActionEvent event) 798 { 799 UIActionLink link = (UIActionLink)event.getComponent(); 800 Map <String , String > params = link.getParameterMap(); 801 String id = params.get("id"); 802 if (id == null || id.length() == 0) 803 { 804 throw new AlfrescoRuntimeException("reject called without an id"); 805 } 806 807 NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id); 808 Node docNode = new Node(docNodeRef); 809 810 if (docNode.hasAspect(ContentModel.ASPECT_SIMPLE_WORKFLOW) == false) 811 { 812 throw new AlfrescoRuntimeException("You can not reject a document that is not part of a workflow"); 813 } 814 815 Map <String , Object > props = docNode.getProperties(); 817 818 String rejectStep = (String )props.get(ContentModel.PROP_REJECT_STEP.toString()); 819 Boolean rejectMove = (Boolean )props.get(ContentModel.PROP_REJECT_MOVE.toString()); 820 NodeRef rejectFolder = (NodeRef)props.get(ContentModel.PROP_REJECT_FOLDER.toString()); 821 822 if (rejectStep == null && rejectMove == null && rejectFolder == null) 823 { 824 throw new AlfrescoRuntimeException("The workflow does not have a reject step defined"); 825 } 826 827 UserTransaction tx = null; 828 try 829 { 830 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 831 tx.begin(); 832 833 this.nodeService.removeAspect(docNodeRef, ContentModel.ASPECT_SIMPLE_WORKFLOW); 835 836 if (rejectMove.booleanValue()) 837 { 838 String qname = QName.createValidLocalName(docNode.getName()); 840 this.nodeService.moveNode(docNodeRef, rejectFolder, ContentModel.ASSOC_CONTAINS, 841 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname)); 842 } 843 else 844 { 845 String qname = QName.createValidLocalName(docNode.getName()); 847 this.copyService.copy(docNodeRef, rejectFolder, ContentModel.ASSOC_CONTAINS, 848 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname)); 849 } 850 851 tx.commit(); 853 854 if (getDocument() != null) 856 { 857 getDocument().reset(); 858 } 859 860 UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans(); 862 863 if (logger.isDebugEnabled()) 864 { 865 String movedCopied = rejectMove ? "moved" : "copied"; 866 logger.debug("Document has been rejected and " + movedCopied + " to folder with id of " + 867 rejectFolder.getId()); 868 } 869 } 870 catch (Throwable e) 871 { 872 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 874 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 875 FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_REJECT), e.getMessage()), e); 876 } 877 } 878 879 882 public void applyClassifiable() 883 { 884 UserTransaction tx = null; 885 886 try 887 { 888 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 889 tx.begin(); 890 891 this.nodeService.addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, null); 893 894 tx.commit(); 896 897 getDocument().reset(); 899 } 900 catch (Throwable e) 901 { 902 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 904 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 905 FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_CLASSIFY), e.getMessage()), e); 906 } 907 } 908 909 912 public void applyVersionable() 913 { 914 UserTransaction tx = null; 915 916 try 917 { 918 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 919 tx.begin(); 920 921 this.nodeService.addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null); 923 924 tx.commit(); 926 927 getDocument().reset(); 929 } 930 catch (Throwable e) 931 { 932 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 934 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 935 FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_VERSIONING), e.getMessage()), e); 936 } 937 } 938 939 942 public String applyInlineEditable() 943 { 944 UserTransaction tx = null; 945 946 try 947 { 948 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 949 tx.begin(); 950 951 Map <QName, Serializable > props = new HashMap <QName, Serializable >(1, 1.0f); 953 String contentType = null; 954 ContentData contentData = (ContentData)getDocument().getProperties().get(ContentModel.PROP_CONTENT); 955 if (contentData != null) 956 { 957 contentType = contentData.getMimetype(); 958 } 959 if (contentType != null) 960 { 961 if (MimetypeMap.MIMETYPE_HTML.equals(contentType) || 963 MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(contentType) || 964 MimetypeMap.MIMETYPE_XML.equals(contentType) || 965 MimetypeMap.MIMETYPE_TEXT_CSS.equals(contentType)) 966 { 967 props.put(ContentModel.PROP_EDITINLINE, true); 968 } 969 } 970 this.nodeService.addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_INLINEEDITABLE, props); 971 972 tx.commit(); 974 975 getDocument().reset(); 977 } 978 catch (Throwable e) 979 { 980 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 982 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 983 FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_INLINEEDITABLE), e.getMessage()), e); 984 } 985 986 return "showDocDetails"; 988 } 989 990 993 public void nextItem(ActionEvent event) 994 { 995 UIActionLink link = (UIActionLink)event.getComponent(); 996 Map <String , String > params = link.getParameterMap(); 997 String id = params.get("id"); 998 if (id != null && id.length() != 0) 999 { 1000 List <Node> nodes = this.browseBean.getContent(); 1001 if (nodes.size() > 1) 1002 { 1003 for (int i=0; i<nodes.size(); i++) 1008 { 1009 if (id.equals(nodes.get(i).getId()) == true) 1010 { 1011 Node next; 1012 if (i != nodes.size() - 1) 1014 { 1015 next = nodes.get(i + 1); 1016 } 1017 else 1018 { 1019 next = nodes.get(0); 1021 } 1022 1023 this.browseBean.setupContentAction(next.getId(), false); 1025 break; 1026 } 1027 } 1028 } 1029 } 1030 } 1031 1032 1035 public void previousItem(ActionEvent event) 1036 { 1037 UIActionLink link = (UIActionLink)event.getComponent(); 1038 Map <String , String > params = link.getParameterMap(); 1039 String id = params.get("id"); 1040 if (id != null && id.length() != 0) 1041 { 1042 List <Node> nodes = this.browseBean.getContent(); 1043 if (nodes.size() > 1) 1044 { 1045 for (int i=0; i<nodes.size(); i++) 1047 { 1048 if (id.equals(nodes.get(i).getId()) == true) 1049 { 1050 Node previous; 1051 if (i != 0) 1053 { 1054 previous = nodes.get(i - 1); 1055 } 1056 else 1057 { 1058 previous = nodes.get(nodes.size() - 1); 1060 } 1061 1062 this.browseBean.setupContentAction(previous.getId(), false); 1064 break; 1065 } 1066 } 1067 } 1068 } 1069 } 1070 1071 1074 public void takeOwnership(ActionEvent event) 1075 { 1076 UserTransaction tx = null; 1077 1078 try 1079 { 1080 tx = Repository.getUserTransaction(FacesContext.getCurrentInstance()); 1081 tx.begin(); 1082 1083 this.ownableService.takeOwnership(getDocument().getNodeRef()); 1084 1085 FacesContext context = FacesContext.getCurrentInstance(); 1086 String msg = Application.getMessage(context, MSG_SUCCESS_OWNERSHIP); 1087 FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg); 1088 context.addMessage(event.getComponent().getClientId(context), facesMsg); 1089 1090 tx.commit(); 1092 } 1093 catch (Throwable e) 1094 { 1095 try { if (tx != null) {tx.rollback();} } catch (Exception ex) {} 1097 Utils.addErrorMessage(MessageFormat.format(Application.getMessage( 1098 FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e); 1099 } 1100 } 1101 1102 1105 public void expandPanel(ActionEvent event) 1106 { 1107 if (event instanceof ExpandedEvent) 1108 { 1109 String id = event.getComponent().getId(); 1110 if (id.startsWith("no-") == true) 1112 { 1113 id = id.substring(3); 1114 } 1115 this.panels.put(id, ((ExpandedEvent)event).State); 1116 } 1117 } 1118 1119 1124 public Map getTemplateModel() 1125 { 1126 HashMap model = new HashMap (3, 1.0f); 1127 1128 FacesContext fc = FacesContext.getCurrentInstance(); 1129 TemplateNode documentNode = new TemplateNode(getDocument().getNodeRef(), 1130 Repository.getServiceRegistry(fc), imageResolver); 1131 model.put("document", documentNode); 1132 TemplateNode spaceNode = new TemplateNode(this.navigator.getCurrentNode().getNodeRef(), 1133 Repository.getServiceRegistry(fc), imageResolver); 1134 model.put("space", spaceNode); 1135 1136 return model; 1137 } 1138 1139 1140 private TemplateImageResolver imageResolver = new TemplateImageResolver() 1141 { 1142 public String resolveImagePathForName(String filename, boolean small) 1143 { 1144 return Utils.getFileTypeImage(filename, small); 1145 } 1146 }; 1147 1148 1153 public boolean isLocked() 1154 { 1155 return Repository.isNodeLocked(getDocument(), this.lockService); 1156 } 1157 1158 1163 public boolean isWorkingCopy() 1164 { 1165 return getDocument().hasAspect(ContentModel.ASPECT_WORKING_COPY); 1166 } 1167 1168 1173 public boolean isOwner() 1174 { 1175 return Repository.isNodeOwner(getDocument(), this.lockService); 1176 } 1177 1178 1183 public Node getDocument() 1184 { 1185 return this.browseBean.getDocument(); 1186 } 1187 1188 1191 public Map <String , Boolean > getPanels() 1192 { 1193 return this.panels; 1194 } 1195 1196 1199 public void setPanels(Map <String , Boolean > panels) 1200 { 1201 this.panels = panels; 1202 } 1203 1204 1209 public void setBrowseBean(BrowseBean browseBean) 1210 { 1211 this.browseBean = browseBean; 1212 } 1213 1214 1219 public void setNodeService(NodeService nodeService) 1220 { 1221 this.nodeService = nodeService; 1222 } 1223 1224 1229 public void setLockService(LockService lockService) 1230 { 1231 this.lockService = lockService; 1232 } 1233 1234 1239 public void setVersionService(VersionService versionService) 1240 { 1241 this.versionService = versionService; 1242 } 1243 1244 1249 public void setCopyService(CopyService copyService) 1250 { 1251 this.copyService = copyService; 1252 } 1253 1254 1259 public void setOwnableService(OwnableService ownableService) 1260 { 1261 this.ownableService = ownableService; 1262 } 1263 1264 1267 public void setNavigator(NavigationBean navigator) 1268 { 1269 this.navigator = navigator; 1270 } 1271} 1272 | Popular Tags |