1 17 package org.alfresco.web.bean.wizard; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import javax.faces.context.FacesContext; 26 import javax.faces.model.SelectItem; 27 28 import org.alfresco.config.Config; 29 import org.alfresco.config.ConfigElement; 30 import org.alfresco.config.ConfigService; 31 import org.alfresco.model.ContentModel; 32 import org.alfresco.repo.action.executer.AddFeaturesActionExecuter; 33 import org.alfresco.repo.action.executer.CheckInActionExecuter; 34 import org.alfresco.repo.action.executer.CheckOutActionExecuter; 35 import org.alfresco.repo.action.executer.CopyActionExecuter; 36 import org.alfresco.repo.action.executer.ImageTransformActionExecuter; 37 import org.alfresco.repo.action.executer.ImporterActionExecuter; 38 import org.alfresco.repo.action.executer.LinkCategoryActionExecuter; 39 import org.alfresco.repo.action.executer.MailActionExecuter; 40 import org.alfresco.repo.action.executer.MoveActionExecuter; 41 import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; 42 import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; 43 import org.alfresco.repo.action.executer.TransformActionExecuter; 44 import org.alfresco.service.cmr.action.ActionDefinition; 45 import org.alfresco.service.cmr.action.ActionService; 46 import org.alfresco.service.cmr.dictionary.AspectDefinition; 47 import org.alfresco.service.cmr.dictionary.DictionaryService; 48 import org.alfresco.service.cmr.dictionary.TypeDefinition; 49 import org.alfresco.service.cmr.repository.MimetypeService; 50 import org.alfresco.service.cmr.repository.NodeRef; 51 import org.alfresco.service.namespace.NamespaceService; 52 import org.alfresco.service.namespace.QName; 53 import org.alfresco.web.app.Application; 54 import org.alfresco.web.bean.repository.Node; 55 import org.alfresco.web.bean.repository.Repository; 56 import org.alfresco.web.data.IDataContainer; 57 import org.alfresco.web.data.QuickSort; 58 import org.apache.commons.logging.Log; 59 import org.apache.commons.logging.LogFactory; 60 61 66 public abstract class BaseActionWizard extends AbstractWizardBean 67 { 68 public static final String PROP_CATEGORY = "category"; 70 public static final String PROP_ASPECT = "aspect"; 71 public static final String PROP_DESTINATION = "destinationLocation"; 72 public static final String PROP_APPROVE_STEP_NAME = "approveStepName"; 73 public static final String PROP_APPROVE_ACTION = "approveAction"; 74 public static final String PROP_APPROVE_FOLDER = "approveFolder"; 75 public static final String PROP_REJECT_STEP_PRESENT = "rejectStepPresent"; 76 public static final String PROP_REJECT_STEP_NAME = "rejectStepName"; 77 public static final String PROP_REJECT_ACTION = "rejectAction"; 78 public static final String PROP_REJECT_FOLDER = "rejectFolder"; 79 public static final String PROP_CHECKIN_DESC = "checkinDescription"; 80 public static final String PROP_CHECKIN_MINOR = "checkinMinorChange"; 81 public static final String PROP_TRANSFORMER = "transformer"; 82 public static final String PROP_IMAGE_TRANSFORMER = "imageTransformer"; 83 public static final String PROP_TRANSFORM_OPTIONS = "transformOptions"; 84 public static final String PROP_ENCODING = "encoding"; 85 public static final String PROP_MESSAGE = "message"; 86 public static final String PROP_SUBJECT = "subject"; 87 public static final String PROP_TO = "to"; 88 public static final String PROP_OBJECT_TYPE = "objecttype"; 89 90 private static final Log logger = LogFactory.getLog(BaseActionWizard.class); 91 private static final String IMPORT_ENCODING = "UTF-8"; 92 93 protected boolean multiActionMode = false; 95 protected String action; 96 protected ActionService actionService; 97 protected DictionaryService dictionaryService; 98 protected MimetypeService mimetypeService; 99 protected List <SelectItem> actions; 100 protected List <SelectItem> transformers; 101 protected List <SelectItem> imageTransformers; 102 protected List <SelectItem> aspects; 103 protected List <SelectItem> users; 104 protected List <SelectItem> encodings; 105 protected Map <String , String > actionDescriptions; 106 protected Map <String , Serializable > currentActionProperties; 107 protected List <SelectItem> objectTypes; 108 109 112 public void init() 113 { 114 super.init(); 115 116 this.action = "add-features"; 117 this.users = null; 118 this.actions = null; 119 this.actionDescriptions = null; 120 121 this.currentActionProperties = new HashMap <String , Serializable >(3); 122 123 this.currentActionProperties.put(PROP_APPROVE_ACTION, "move"); 125 this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes"); 126 this.currentActionProperties.put(PROP_REJECT_ACTION, "move"); 127 128 this.currentActionProperties.put(PROP_CHECKIN_MINOR, new Boolean (true)); 130 } 131 132 137 protected Map <String , Serializable > buildActionParams() 138 { 139 Map <String , Serializable > actionParams = new HashMap <String , Serializable >(); 141 142 if (this.action.equals(AddFeaturesActionExecuter.NAME)) 143 { 144 QName aspect = Repository.resolveToQName((String )this.currentActionProperties.get(PROP_ASPECT)); 145 actionParams.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, aspect); 146 } 147 else if (this.action.equals(CopyActionExecuter.NAME)) 148 { 149 NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 151 actionParams.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); 152 153 actionParams.put(CopyActionExecuter.PARAM_ASSOC_TYPE_QNAME, 156 ContentModel.ASSOC_CONTAINS); 157 actionParams.put(CopyActionExecuter.PARAM_ASSOC_QNAME, 158 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); 159 } 160 else if (this.action.equals(MoveActionExecuter.NAME)) 161 { 162 NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 164 actionParams.put(MoveActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); 165 166 actionParams.put(MoveActionExecuter.PARAM_ASSOC_TYPE_QNAME, 169 ContentModel.ASSOC_CONTAINS); 170 actionParams.put(MoveActionExecuter.PARAM_ASSOC_QNAME, 171 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "move")); 172 } 173 else if (this.action.equals(SimpleWorkflowActionExecuter.NAME)) 174 { 175 actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP, 177 (String )this.currentActionProperties.get(PROP_APPROVE_STEP_NAME)); 178 179 boolean approveMove = true; 181 String approveAction = (String )this.currentActionProperties.get(PROP_APPROVE_ACTION); 182 if (approveAction != null && approveAction.equals("copy")) 183 { 184 approveMove = false; 185 } 186 187 actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE, Boolean.valueOf(approveMove)); 188 189 NodeRef approveDestNodeRef = null; 191 Object approveDestNode = this.currentActionProperties.get(PROP_APPROVE_FOLDER); 192 if (approveDestNode instanceof NodeRef) 193 { 194 approveDestNodeRef = (NodeRef)approveDestNode; 195 } 196 else if (approveDestNode instanceof String ) 197 { 198 approveDestNodeRef = new NodeRef((String )approveDestNode); 199 } 200 actionParams.put(SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER, approveDestNodeRef); 201 202 boolean requireReject = true; 204 String rejectStepPresent = (String )this.currentActionProperties.get(PROP_REJECT_STEP_PRESENT); 205 if (rejectStepPresent != null && rejectStepPresent.equals("no")) 206 { 207 requireReject = false; 208 } 209 210 if (requireReject) 211 { 212 actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP, 214 (String )this.currentActionProperties.get(PROP_REJECT_STEP_NAME)); 215 216 boolean rejectMove = true; 218 String rejectAction = (String )this.currentActionProperties.get(PROP_REJECT_ACTION); 219 if (rejectAction != null && rejectAction.equals("copy")) 220 { 221 rejectMove = false; 222 } 223 224 actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE, Boolean.valueOf(rejectMove)); 225 226 NodeRef rejectDestNodeRef = null; 228 Object rejectDestNode = this.currentActionProperties.get(PROP_REJECT_FOLDER); 229 if (rejectDestNode instanceof NodeRef) 230 { 231 rejectDestNodeRef = (NodeRef)rejectDestNode; 232 } 233 else if (rejectDestNode instanceof String ) 234 { 235 rejectDestNodeRef = new NodeRef((String )rejectDestNode); 236 } 237 actionParams.put(SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER, rejectDestNodeRef); 238 } 239 } 240 else if (this.action.equals(LinkCategoryActionExecuter.NAME)) 241 { 242 actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_ASPECT, 244 ContentModel.ASPECT_GEN_CLASSIFIABLE); 245 246 NodeRef catNodeRef = (NodeRef)this.currentActionProperties.get(PROP_CATEGORY); 248 actionParams.put(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE, 249 catNodeRef); 250 } 251 else if (this.action.equals(CheckOutActionExecuter.NAME)) 252 { 253 NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 256 actionParams.put(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); 257 258 actionParams.put(CheckOutActionExecuter.PARAM_ASSOC_TYPE_QNAME, 261 ContentModel.ASSOC_CONTAINS); 262 actionParams.put(CheckOutActionExecuter.PARAM_ASSOC_QNAME, 263 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "checkout")); 264 } 265 else if (this.action.equals(CheckInActionExecuter.NAME)) 266 { 267 actionParams.put(CheckInActionExecuter.PARAM_DESCRIPTION, 269 this.currentActionProperties.get(PROP_CHECKIN_DESC)); 270 271 actionParams.put(CheckInActionExecuter.PARAM_MINOR_CHANGE, 273 this.currentActionProperties.get(PROP_CHECKIN_MINOR)); 274 } 275 else if (this.action.equals(TransformActionExecuter.NAME)) 276 { 277 actionParams.put(TransformActionExecuter.PARAM_MIME_TYPE, 279 this.currentActionProperties.get(PROP_TRANSFORMER)); 280 281 NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 283 actionParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); 284 285 actionParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, 288 ContentModel.ASSOC_CONTAINS); 289 actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME, 290 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); 291 } 292 else if (this.action.equals(ImageTransformActionExecuter.NAME)) 293 { 294 actionParams.put(ImageTransformActionExecuter.PARAM_MIME_TYPE, 296 this.currentActionProperties.get(PROP_IMAGE_TRANSFORMER)); 297 298 actionParams.put(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND, 300 this.currentActionProperties.get(PROP_TRANSFORM_OPTIONS)); 301 302 NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 304 actionParams.put(TransformActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); 305 306 actionParams.put(TransformActionExecuter.PARAM_ASSOC_TYPE_QNAME, 309 ContentModel.ASSOC_CONTAINS); 310 actionParams.put(TransformActionExecuter.PARAM_ASSOC_QNAME, 311 QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "copy")); 312 } 313 else if (this.action.equals(MailActionExecuter.NAME)) 314 { 315 actionParams.put(MailActionExecuter.PARAM_TEXT, 317 this.currentActionProperties.get(PROP_MESSAGE)); 318 319 actionParams.put(MailActionExecuter.PARAM_TO, 321 this.currentActionProperties.get(PROP_TO)); 322 323 actionParams.put(MailActionExecuter.PARAM_SUBJECT, 325 this.currentActionProperties.get(PROP_SUBJECT)); 326 } 327 else if (this.action.equals(ImporterActionExecuter.NAME)) 328 { 329 actionParams.put(ImporterActionExecuter.PARAM_ENCODING, IMPORT_ENCODING); 331 332 NodeRef destNodeRef = (NodeRef)this.currentActionProperties.get(PROP_DESTINATION); 334 actionParams.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); 335 } 336 else if (this.action.equals(SpecialiseTypeActionExecuter.NAME) == true) 337 { 338 String objectType = (String )this.currentActionProperties.get(PROP_OBJECT_TYPE); 340 actionParams.put(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, QName.createQName(objectType)); 341 } 342 343 return actionParams; 344 } 345 346 352 protected void populateActionFromProperties(Map <String , Serializable > actionProps) 353 { 354 if (this.action.equals(AddFeaturesActionExecuter.NAME)) 355 { 356 QName aspect = (QName)actionProps.get(AddFeaturesActionExecuter.PARAM_ASPECT_NAME); 357 this.currentActionProperties.put(PROP_ASPECT, aspect.toString()); 358 } 359 else if (this.action.equals(CopyActionExecuter.NAME)) 360 { 361 NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER); 362 this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); 363 } 364 else if (this.action.equals(MoveActionExecuter.NAME)) 365 { 366 NodeRef destNodeRef = (NodeRef)actionProps.get(MoveActionExecuter.PARAM_DESTINATION_FOLDER); 367 this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); 368 } 369 else if (this.action.equals(SimpleWorkflowActionExecuter.NAME)) 370 { 371 String approveStep = (String )actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP); 372 Boolean approveMove = (Boolean )actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE); 373 NodeRef approveFolderNode = (NodeRef)actionProps.get( 374 SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER); 375 376 String rejectStep = (String )actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP); 377 Boolean rejectMove = (Boolean )actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE); 378 NodeRef rejectFolderNode = (NodeRef)actionProps.get( 379 SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER); 380 381 this.currentActionProperties.put(PROP_APPROVE_STEP_NAME, approveStep); 382 this.currentActionProperties.put(PROP_APPROVE_ACTION, approveMove ? "move" : "copy"); 383 this.currentActionProperties.put(PROP_APPROVE_FOLDER, approveFolderNode); 384 385 if (rejectStep == null && rejectMove == null && rejectFolderNode == null) 386 { 387 this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "no"); 388 } 389 else 390 { 391 this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes"); 392 this.currentActionProperties.put(PROP_REJECT_STEP_NAME, rejectStep); 393 this.currentActionProperties.put(PROP_REJECT_ACTION, rejectMove ? "move" : "copy"); 394 this.currentActionProperties.put(PROP_REJECT_FOLDER, rejectFolderNode); 395 } 396 } 397 else if (this.action.equals(LinkCategoryActionExecuter.NAME)) 398 { 399 NodeRef catNodeRef = (NodeRef)actionProps.get(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE); 400 this.currentActionProperties.put(PROP_CATEGORY, catNodeRef); 401 } 402 else if (this.action.equals(CheckOutActionExecuter.NAME)) 403 { 404 NodeRef destNodeRef = (NodeRef)actionProps.get(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER); 405 this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); 406 } 407 else if (this.action.equals(CheckInActionExecuter.NAME)) 408 { 409 String checkDesc = (String )actionProps.get(CheckInActionExecuter.PARAM_DESCRIPTION); 410 this.currentActionProperties.put(PROP_CHECKIN_DESC, checkDesc); 411 412 Boolean minorChange = (Boolean )actionProps.get(CheckInActionExecuter.PARAM_MINOR_CHANGE); 413 this.currentActionProperties.put(PROP_CHECKIN_MINOR, minorChange); 414 } 415 else if (this.action.equals(TransformActionExecuter.NAME)) 416 { 417 String transformer = (String )actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE); 418 this.currentActionProperties.put(PROP_TRANSFORMER, transformer); 419 420 NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER); 421 this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); 422 } 423 else if (this.action.equals(ImageTransformActionExecuter.NAME)) 424 { 425 String transformer = (String )actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE); 426 this.currentActionProperties.put(PROP_IMAGE_TRANSFORMER, transformer); 427 428 String options = (String )actionProps.get(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND); 429 this.currentActionProperties.put(PROP_TRANSFORM_OPTIONS, options != null ? options : ""); 430 431 NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER); 432 this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); 433 } 434 else if (this.action.equals(MailActionExecuter.NAME)) 435 { 436 String subject = (String )actionProps.get(MailActionExecuter.PARAM_SUBJECT); 437 this.currentActionProperties.put(PROP_SUBJECT, subject); 438 439 String message = (String )actionProps.get(MailActionExecuter.PARAM_TEXT); 440 this.currentActionProperties.put(PROP_MESSAGE, message); 441 442 String to = (String )actionProps.get(MailActionExecuter.PARAM_TO); 443 this.currentActionProperties.put(PROP_TO, to); 444 } 445 else if (this.action.equals(ImporterActionExecuter.NAME)) 446 { 447 NodeRef destNodeRef = (NodeRef)actionProps.get(ImporterActionExecuter.PARAM_DESTINATION_FOLDER); 448 this.currentActionProperties.put(PROP_DESTINATION, destNodeRef); 449 } 450 else if (this.action.equals(SpecialiseTypeActionExecuter.NAME) == true) 451 { 452 QName specialiseType = (QName)actionProps.get(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME); 453 this.currentActionProperties.put(PROP_OBJECT_TYPE, specialiseType.toString()); 454 } 455 } 456 457 460 public String getAction() 461 { 462 return this.action; 463 } 464 465 468 public void setAction(String action) 469 { 470 this.action = action; 471 } 472 473 478 public void setActionService(ActionService actionService) 479 { 480 this.actionService = actionService; 481 } 482 483 488 public void setDictionaryService(DictionaryService dictionaryService) 489 { 490 this.dictionaryService = dictionaryService; 491 } 492 493 498 public void setMimetypeService(MimetypeService mimetypeService) 499 { 500 this.mimetypeService = mimetypeService; 501 } 502 503 506 public List <SelectItem> getActions() 507 { 508 if (this.actions == null) 509 { 510 List <ActionDefinition> ruleActions = this.actionService.getActionDefinitions(); 511 this.actions = new ArrayList <SelectItem>(); 512 for (ActionDefinition ruleActionDef : ruleActions) 513 { 514 this.actions.add(new SelectItem(ruleActionDef.getName(), ruleActionDef.getTitle())); 515 } 516 517 QuickSort sorter = new QuickSort(this.actions, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 519 sorter.sort(); 520 } 521 522 return this.actions; 523 } 524 525 528 public Map <String , String > getActionDescriptions() 529 { 530 if (this.actionDescriptions == null) 531 { 532 List <ActionDefinition> ruleActions = this.actionService.getActionDefinitions(); 533 this.actionDescriptions = new HashMap <String , String >(); 534 for (ActionDefinition ruleActionDef : ruleActions) 535 { 536 this.actionDescriptions.put(ruleActionDef.getName(), ruleActionDef.getDescription()); 537 } 538 } 539 540 return this.actionDescriptions; 541 } 542 543 546 public Map <String , Serializable > getActionProperties() 547 { 548 return this.currentActionProperties; 549 } 550 551 556 public List <SelectItem> getEncodings() 557 { 558 if (this.encodings == null) 559 { 560 ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance()); 561 Config wizardCfg = svc.getConfig("Action Wizards"); 562 if (wizardCfg != null) 563 { 564 ConfigElement encodingsCfg = wizardCfg.getConfigElement("encodings"); 565 if (encodingsCfg != null) 566 { 567 FacesContext context = FacesContext.getCurrentInstance(); 568 this.encodings = new ArrayList <SelectItem>(); 569 for (ConfigElement child : encodingsCfg.getChildren()) 570 { 571 String id = child.getAttribute("name"); 572 573 String label = null; 575 String msgId = child.getAttribute("displayLabelId"); 576 if (msgId != null) 577 { 578 label = Application.getMessage(context, msgId); 579 } 580 581 if (label == null) 583 { 584 label = child.getAttribute("displayLabel"); 585 } 586 587 this.encodings.add(new SelectItem(id, label)); 588 } 589 590 QuickSort sorter = new QuickSort(this.encodings, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 592 sorter.sort(); 593 } 594 else 595 { 596 logger.warn("Could not find encodings configuration element"); 597 } 598 } 599 else 600 { 601 logger.warn("Could not find Action Wizards configuration section"); 602 } 603 } 604 605 return this.encodings; 606 } 607 608 613 public List <SelectItem> getTransformers() 614 { 615 if (this.transformers == null) 616 { 617 ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance()); 618 Config wizardCfg = svc.getConfig("Action Wizards"); 619 if (wizardCfg != null) 620 { 621 ConfigElement transformersCfg = wizardCfg.getConfigElement("transformers"); 622 if (transformersCfg != null) 623 { 624 FacesContext context = FacesContext.getCurrentInstance(); 625 Map <String , String > mimeTypes = this.mimetypeService.getDisplaysByMimetype(); 626 this.transformers = new ArrayList <SelectItem>(); 627 for (ConfigElement child : transformersCfg.getChildren()) 628 { 629 String id = child.getAttribute("name"); 630 631 String label = null; 633 String msgId = child.getAttribute("displayLabelId"); 634 if (msgId != null) 635 { 636 label = Application.getMessage(context, msgId); 637 } 638 639 if (label == null) 641 { 642 label = child.getAttribute("displayLabel"); 643 } 644 645 if (label == null) 647 { 648 label = mimeTypes.get(id); 649 } 650 651 this.transformers.add(new SelectItem(id, label)); 652 } 653 654 QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 656 sorter.sort(); 657 } 658 else 659 { 660 logger.warn("Could not find transformers configuration element"); 661 } 662 } 663 else 664 { 665 logger.warn("Could not find Action Wizards configuration section"); 666 } 667 } 668 669 return this.transformers; 670 } 671 672 677 public List <SelectItem> getImageTransformers() 678 { 679 if (this.imageTransformers == null) 680 { 681 ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance()); 682 Config wizardCfg = svc.getConfig("Action Wizards"); 683 if (wizardCfg != null) 684 { 685 ConfigElement transformersCfg = wizardCfg.getConfigElement("image-transformers"); 686 if (transformersCfg != null) 687 { 688 FacesContext context = FacesContext.getCurrentInstance(); 689 Map <String , String > mimeTypes = this.mimetypeService.getDisplaysByMimetype(); 690 this.imageTransformers = new ArrayList <SelectItem>(); 691 for (ConfigElement child : transformersCfg.getChildren()) 692 { 693 String id = child.getAttribute("name"); 694 695 String label = null; 697 String msgId = child.getAttribute("displayLabelId"); 698 if (msgId != null) 699 { 700 label = Application.getMessage(context, msgId); 701 } 702 703 if (label == null) 705 { 706 label = child.getAttribute("displayLabel"); 707 } 708 709 if (label == null) 711 { 712 label = mimeTypes.get(id); 713 } 714 715 this.imageTransformers.add(new SelectItem(id, label)); 716 } 717 718 QuickSort sorter = new QuickSort(this.imageTransformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 720 sorter.sort(); 721 } 722 else 723 { 724 logger.warn("Could not find image-transformers configuration element"); 725 } 726 } 727 else 728 { 729 logger.warn("Could not find Action Wizards configuration section"); 730 } 731 } 732 733 return this.imageTransformers; 734 } 735 736 741 public List <SelectItem> getAspects() 742 { 743 if (this.aspects == null) 744 { 745 ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance()); 746 Config wizardCfg = svc.getConfig("Action Wizards"); 747 if (wizardCfg != null) 748 { 749 ConfigElement aspectsCfg = wizardCfg.getConfigElement("aspects"); 750 if (aspectsCfg != null) 751 { 752 FacesContext context = FacesContext.getCurrentInstance(); 753 this.aspects = new ArrayList <SelectItem>(); 754 for (ConfigElement child : aspectsCfg.getChildren()) 755 { 756 QName idQName = Repository.resolveToQName(child.getAttribute("name")); 757 758 String label = null; 760 String msgId = child.getAttribute("displayLabelId"); 761 if (msgId != null) 762 { 763 label = Application.getMessage(context, msgId); 764 } 765 766 if (label == null) 768 { 769 label = child.getAttribute("displayLabel"); 770 } 771 772 if (label == null) 774 { 775 AspectDefinition aspectDef = this.dictionaryService.getAspect(idQName); 776 if (aspectDef != null) 777 { 778 label = aspectDef.getTitle(); 779 } 780 else 781 { 782 label = idQName.getLocalName(); 783 } 784 } 785 786 this.aspects.add(new SelectItem(idQName.toString(), label)); 787 } 788 789 QuickSort sorter = new QuickSort(this.aspects, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 791 sorter.sort(); 792 } 793 else 794 { 795 logger.warn("Could not find aspects configuration element"); 796 } 797 } 798 else 799 { 800 logger.warn("Could not find Action Wizards configuration section"); 801 } 802 } 803 804 return this.aspects; 805 } 806 807 810 public List <SelectItem> getObjectTypes() 811 { 812 if (this.objectTypes == null) 813 { 814 FacesContext context = FacesContext.getCurrentInstance(); 815 816 this.objectTypes = new ArrayList <SelectItem>(5); 818 this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), 819 Application.getMessage(context, "content"))); 820 821 ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance()); 823 Config wizardCfg = svc.getConfig("Custom Content Types"); 824 if (wizardCfg != null) 825 { 826 ConfigElement typesCfg = wizardCfg.getConfigElement("content-types"); 827 if (typesCfg != null) 828 { 829 for (ConfigElement child : typesCfg.getChildren()) 830 { 831 QName idQName = Repository.resolveToQName(child.getAttribute("name")); 832 TypeDefinition typeDef = this.dictionaryService.getType(idQName); 833 834 if (typeDef != null && 835 this.dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_CONTENT)) 836 { 837 String label = null; 839 String msgId = child.getAttribute("displayLabelId"); 840 if (msgId != null) 841 { 842 label = Application.getMessage(context, msgId); 843 } 844 845 if (label == null) 847 { 848 label = child.getAttribute("displayLabel"); 849 } 850 851 if (label == null) 853 { 854 label = typeDef.getTitle(); 855 } 856 857 if (label == null) 859 { 860 label = idQName.getLocalName(); 861 } 862 863 this.objectTypes.add(new SelectItem(idQName.toString(), label)); 864 } 865 } 866 867 QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 869 sorter.sort(); 870 } 871 else 872 { 873 logger.warn("Could not find 'content-types' configuration element"); 874 } 875 } 876 else 877 { 878 logger.warn("Could not find 'Custom Content Types' configuration section"); 879 } 880 881 } 882 883 return this.objectTypes; 884 } 885 886 889 public List <SelectItem> getUsers() 890 { 891 if (this.users == null) 892 { 893 List <Node> userNodes = Repository.getUsers( 894 FacesContext.getCurrentInstance(), 895 this.nodeService, 896 this.searchService); 897 this.users = new ArrayList <SelectItem>(); 898 for (Node user : userNodes) 899 { 900 String email = (String )user.getProperties().get("email"); 901 if (email != null && email.length() > 0) 902 { 903 this.users.add(new SelectItem(email, (String )user.getProperties().get("fullName"))); 904 } 905 } 906 907 QuickSort sorter = new QuickSort(this.users, "label", true, IDataContainer.SORT_CASEINSENSITIVE); 909 sorter.sort(); 910 } 911 912 return this.users; 913 } 914 } 915 | Popular Tags |