1 18 package org.apache.beehive.netui.compiler.model; 19 20 import org.apache.beehive.netui.compiler.model.schema.struts11.*; 21 import org.apache.beehive.netui.compiler.model.validation.ValidationModel; 22 import org.apache.beehive.netui.compiler.JpfLanguageConstants; 23 import org.apache.beehive.netui.compiler.FatalCompileTimeException; 24 import org.apache.xmlbeans.XmlObject; 25 import org.apache.xmlbeans.XmlException; 26 import org.apache.xmlbeans.XmlDocumentProperties; 27 import org.apache.xmlbeans.XmlCursor; 28 import org.apache.xmlbeans.XmlOptions; 29 30 import java.io.File ; 31 import java.io.PrintStream ; 32 import java.io.IOException ; 33 import java.util.ArrayList ; 34 import java.util.Map ; 35 import java.util.HashMap ; 36 import java.util.List ; 37 import java.util.Iterator ; 38 import java.util.Collections ; 39 import java.util.Comparator ; 40 41 42 public class StrutsApp 43 extends AbstractForwardContainer 44 implements ForwardContainer, ExceptionContainer, JpfLanguageConstants 45 { 46 private HashMap _actionMappings = new HashMap (); 48 private ArrayList _exceptionCatches = new ArrayList (); 49 private ArrayList _messageResources = new ArrayList (); 50 private HashMap _formBeans = new HashMap (); 51 private ValidationModel _validationModel; 52 private List _additionalValidatorConfigs; 53 54 private boolean _returnToPageDisabled = true; 55 private boolean _returnToActionDisabled = true; 56 private boolean _isNestedPageFlow = false; 57 private boolean _isLongLivedPageFlow = false; 58 private boolean _isSharedFlow = false; 59 60 private Map _sharedFlows = null; 61 private String _controllerClassName = null; 62 private String _multipartHandlerClassName = null; 63 private List _tilesDefinitionsConfigs = null; 64 65 66 protected static final String DUPLICATE_ACTION_COMMENT = "Note that there is more than one action with path \"{0}\"." 67 + " Use a form-qualified action path if this is not the " 68 + "one you want."; 69 70 protected static final String PAGEFLOW_REQUESTPROCESSOR_CLASSNAME 71 = PAGEFLOW_PACKAGE + ".PageFlowRequestProcessor"; 72 73 protected static final String PAGEFLOW_CONTROLLER_CONFIG_CLASSNAME 74 = PAGEFLOW_PACKAGE + ".config.PageFlowControllerConfig"; 75 76 protected static final String STRUTS_CONFIG_PREFIX = "jpf-struts-config"; 77 protected static final String STRUTS_CONFIG_EXTENSION = ".xml"; 78 protected static final char STRUTS_CONFIG_SEPARATOR = '-'; 79 protected static final String WEBINF_DIR_NAME = "WEB-INF"; 80 protected static final String STRUTSCONFIG_OUTPUT_DIR = '/' + WEBINF_DIR_NAME + "/.pageflow-struts-generated"; 81 protected static final String VALIDATOR_PLUG_IN_CLASSNAME = STRUTS_PACKAGE + ".validator.ValidatorPlugIn"; 82 protected static final String VALIDATOR_PATHNAMES_PROPERTY = "pathnames"; 83 protected static final String TILES_PLUG_IN_CLASSNAME = STRUTS_PACKAGE + ".tiles.TilesPlugin"; 84 protected static final String TILES_DEFINITIONS_CONFIG_PROPERTY = "definitions-config"; 85 protected static final String TILES_MODULE_AWARE_PROPERTY = "moduleAware"; 86 protected static final String NETUI_VALIDATOR_RULES_URI = '/' + WEBINF_DIR_NAME + "/beehive-netui-validator-rules.xml"; 87 protected static final String STRUTS_VALIDATOR_RULES_URI = '/' + WEBINF_DIR_NAME + "/validator-rules.xml"; 88 89 90 public StrutsApp( String controllerClassName ) 91 { 92 super( null ); 93 setParentApp( this ); 94 _controllerClassName = controllerClassName; 95 96 MessageResourcesModel mrm = new MessageResourcesModel( this ); 100 mrm.setParameter( DEFAULT_VALIDATION_MESSAGE_BUNDLE ); 101 mrm.setKey( DEFAULT_VALIDATION_MESSAGE_BUNDLE_NAME ); 102 mrm.setReturnNull( true ); 103 addMessageResources( mrm ); 104 } 105 106 public void addMessageResources( MessageResourcesModel mr ) 107 { 108 _messageResources.add( mr ); 109 } 110 111 private void addDisambiguatedActionMapping( ActionModel mapping ) 112 { 113 if ( mapping.getFormBeanName() != null ) 114 { 115 String qualifiedPath = getFormQualifiedActionPath( mapping ); 116 ActionModel qualifiedMapping = new ActionModel( mapping, qualifiedPath ); 117 qualifiedMapping.setUnqualifiedActionPath( mapping.getPath() ); 118 _actionMappings.put( qualifiedPath, qualifiedMapping ); 119 } 120 } 121 122 125 public void addActionMapping( ActionModel mapping ) 126 { 127 String mappingPath = mapping.getPath(); 128 ActionModel conflictingActionMapping = ( ActionModel ) _actionMappings.get( mappingPath ); 129 130 if ( conflictingActionMapping != null ) 131 { 132 ActionModel defaultMappingForThisPath = conflictingActionMapping; 133 134 if ( mapping.getFormBeanName() == null 140 || ( conflictingActionMapping.getFormBeanName() != null 141 && getBeanType( mapping ).compareTo( getBeanType( conflictingActionMapping ) ) < 0 ) ) 142 { 143 _actionMappings.put( mappingPath, mapping ); 144 defaultMappingForThisPath = mapping; 145 conflictingActionMapping.setOverloaded( false ); 146 } 147 148 addDisambiguatedActionMapping( mapping ); 149 addDisambiguatedActionMapping( conflictingActionMapping ); 150 defaultMappingForThisPath.setOverloaded( true ); 151 defaultMappingForThisPath.setComment( DUPLICATE_ACTION_COMMENT.replaceAll( "\\{0\\}", mappingPath ) ); } 153 else 154 { 155 _actionMappings.put( mappingPath, mapping ); 156 } 157 } 158 159 160 public String getBeanType( ActionModel actionMapping ) 165 { 166 String beanType = actionMapping.getFormClass(); 168 if ( beanType == null ) 169 { 170 FormBeanModel bean = getFormBean( actionMapping.getFormBeanName() ); 171 assert bean != null; 172 beanType = bean.getType(); 173 } 174 175 return beanType; 176 } 177 178 protected String getFormQualifiedActionPath( ActionModel action ) 179 { 180 assert action.getFormBeanName() != null : "action " + action.getPath() + " has no form bean"; 181 String beanType = getBeanType( action ); 182 return action.getPath() + '_' + makeFullyQualifiedBeanName( beanType ); 183 } 184 185 188 public void addException( ExceptionModel c ) 189 { 190 _exceptionCatches.add( c ); 191 } 192 193 197 public FormBeanModel[] getFormBeans() 198 { 199 return ( FormBeanModel[] ) getFormBeansAsList().toArray( new FormBeanModel[0] ); 200 } 201 202 205 public List getFormBeansAsList() 206 { 207 ArrayList retList = new ArrayList (); 208 209 for ( Iterator i = _formBeans.values().iterator(); i.hasNext(); ) 210 { 211 FormBeanModel fb = ( FormBeanModel ) i.next(); 212 if ( fb != null ) retList.add( fb ); 213 } 214 215 return retList; 216 } 217 218 public FormBeanModel getFormBean( String formBeanName ) 219 { 220 return ( FormBeanModel ) _formBeans.get( formBeanName ); 221 } 222 223 226 public List getFormBeansByActualType( String actualTypeName, Boolean usesPageFlowScopedBean ) 227 { 228 ArrayList beans = null; 229 230 for ( Iterator i = _formBeans.values().iterator(); i.hasNext(); ) 231 { 232 FormBeanModel formBean = ( FormBeanModel ) i.next(); 233 234 if ( formBean != null && formBean.getActualType().equals( actualTypeName ) 235 && ( usesPageFlowScopedBean == null || usesPageFlowScopedBean.booleanValue() == formBean.isPageFlowScoped() ) ) 236 { 237 if ( beans == null ) beans = new ArrayList (); 238 beans.add( formBean ); 239 } 240 } 241 242 return beans; 243 } 244 245 248 public void addFormBean( FormBeanModel newFormBean ) 249 { 250 _formBeans.put( newFormBean.getName(), newFormBean ); 251 } 252 253 256 public void deleteFormBean( FormBeanModel formBean ) 257 { 258 _formBeans.remove( formBean.getName() ); 259 } 260 261 public String getFormNameForType( String formType, boolean isPageFlowScoped ) 262 { 263 int lastQualifier = formType.lastIndexOf( '$' ); 268 if ( lastQualifier == -1 ) lastQualifier = formType.lastIndexOf( '.' ); 269 270 String formBeanName = formType.substring( lastQualifier + 1 ); 271 formBeanName = Character.toLowerCase( formBeanName.charAt( 0 ) ) + formBeanName.substring( 1 ); 272 273 if ( _formBeans.containsKey( formBeanName ) ) 277 { 278 String conflictingName = formBeanName; 279 FormBeanModel conflictingBean = ( FormBeanModel ) _formBeans.get( conflictingName ); 280 281 if ( conflictingBean != null && isPageFlowScoped != conflictingBean.isPageFlowScoped() ) 286 { 287 formBeanName += isPageFlowScoped ? "_flowScoped" : "_nonFlowScoped"; 288 assert ! _formBeans.containsKey( formBeanName ); return formBeanName; 290 } 291 292 formBeanName = makeFullyQualifiedBeanName( formType ); 293 294 if ( conflictingBean != null ) 298 { 299 String nonConflictingName = makeFullyQualifiedBeanName( conflictingBean.getType() ); 300 conflictingBean.setName( nonConflictingName ); 301 _formBeans.put( nonConflictingName, conflictingBean ); 302 303 for ( Iterator i = _actionMappings.values().iterator(); i.hasNext(); ) 307 { 308 ActionModel mapping = ( ActionModel ) i.next(); 309 310 if ( mapping.getFormBeanName() != null && mapping.getFormBeanName().equals( conflictingName ) ) 311 { 312 mapping.setFormBeanName( nonConflictingName ); 313 } 314 } 315 } 316 317 _formBeans.put( conflictingName, null ); 318 } 319 320 return formBeanName; 321 } 322 323 protected static String makeFullyQualifiedBeanName( String formType ) 324 { 325 return formType.replace( '.', '_' ).replace( '$', '_' ); 326 } 327 328 protected static class ActionMappingComparator implements Comparator 329 { 330 public int compare( Object o1, Object o2 ) 331 { 332 assert o1 instanceof ActionModel && o2 instanceof ActionModel; 333 334 ActionModel am1 = ( ActionModel ) o1; 335 ActionModel am2 = ( ActionModel ) o2; 336 337 assert ! am1.getPath().equals( am2.getPath() ); return am1.getPath().compareTo( am2.getPath() ); 339 } 340 } 341 342 protected ForwardDocument.Forward addNewForward( XmlObject xmlObject ) 343 { 344 return ( ( GlobalForwardsDocument.GlobalForwards ) xmlObject ).addNewForward(); 345 } 346 347 protected Map getFormBeansMap() 348 { 349 return _formBeans; 350 } 351 352 protected List getExceptionCatchesList() 353 { 354 return _exceptionCatches; 355 } 356 357 protected List getSortedActionMappings() 358 { 359 ArrayList sortedActionMappings = new ArrayList (); 360 sortedActionMappings.addAll( _actionMappings.values() ); 361 Collections.sort( sortedActionMappings, new ActionMappingComparator() ); 362 return sortedActionMappings; 363 } 364 365 protected List getMessageResourcesList() 366 { 367 return _messageResources; 368 } 369 370 373 public MessageResourcesModel getDefaultMessageResources() 374 { 375 for ( java.util.Iterator ii = _messageResources.iterator(); ii.hasNext(); ) 376 { 377 MessageResourcesModel i = ( MessageResourcesModel ) ii.next(); 378 if ( i.getKey() == null ) return i; 379 } 380 381 return null; 382 } 383 384 public boolean isReturnToPageDisabled() 385 { 386 return _returnToPageDisabled; 387 } 388 389 public boolean isReturnToActionDisabled() 390 { 391 return _returnToActionDisabled; 392 } 393 394 public void setReturnToPageDisabled( boolean disabled ) 395 { 396 _returnToPageDisabled = disabled; 397 } 398 399 public void setReturnToActionDisabled( boolean disabled ) 400 { 401 _returnToActionDisabled = disabled; 402 } 403 404 public void setAdditionalValidatorConfigs( List additionalValidatorConfigs ) 405 { 406 if ( additionalValidatorConfigs != null && ! additionalValidatorConfigs.isEmpty() ) 407 { 408 _additionalValidatorConfigs = additionalValidatorConfigs; 409 } 410 } 411 412 public void setValidationModel( ValidationModel validationModel ) 413 { 414 if ( ! validationModel.isEmpty() ) { 416 _validationModel = validationModel; 417 } 418 } 419 420 public void writeXml( PrintStream outputStream, File mergeFile, String webappBuildRoot ) 421 throws IOException , XmlException, FatalCompileTimeException 422 { 423 StrutsConfigDocument doc; 424 425 if ( mergeFile != null && mergeFile.canRead() ) 426 { 427 doc = StrutsConfigDocument.Factory.parse( mergeFile ); 428 } 429 else 430 { 431 doc = StrutsConfigDocument.Factory.newInstance(); 432 } 433 434 435 XmlDocumentProperties docProps = doc.documentProperties(); 439 440 if ( docProps.getDoctypeName() == null ) 441 { 442 docProps.setDoctypeName( "struts-config" ); } 444 445 if ( docProps.getDoctypePublicId() == null ) 446 { 447 docProps.setDoctypePublicId( "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" ); } 449 450 if ( docProps.getDoctypeSystemId() == null ) 451 { 452 docProps.setDoctypeSystemId( "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" ); } 454 455 456 StrutsConfigDocument.StrutsConfig scElement = doc.getStrutsConfig(); 460 461 if ( scElement == null ) 462 { 463 scElement = doc.addNewStrutsConfig(); 464 } 465 466 XmlCursor curs = scElement.newCursor(); 470 String headerComment = getHeaderComment( mergeFile ); 471 if ( headerComment != null ) curs.insertComment( headerComment ); 472 473 writeFormBeans( scElement ); 477 478 479 writeExceptions( scElement ); 483 484 485 GlobalForwardsDocument.GlobalForwards globalForwards = scElement.getGlobalForwards(); 489 490 if ( globalForwards == null ) 491 { 492 globalForwards = scElement.addNewGlobalForwards(); 493 } 494 writeForwards( globalForwards.getForwardArray(), globalForwards ); 495 496 497 writeActionMappings( scElement ); 501 502 503 writeMessageResources( scElement ); 507 508 509 writeControllerElement( scElement ); 513 514 515 writeValidatorInit( scElement ); 519 520 521 writeTilesInit( scElement ); 525 526 527 XmlOptions options = new XmlOptions(); 531 options.setSavePrettyPrint(); 532 doc.save( outputStream, options ); 533 } 534 535 private void writeMessageResources( StrutsConfigDocument.StrutsConfig scElement ) 536 { 537 MessageResourcesDocument.MessageResources[] existingMessageResources = scElement.getMessageResourcesArray(); 538 539 for ( Iterator i = getMessageResourcesList().iterator(); i.hasNext(); ) 540 { 541 MessageResourcesModel mr = ( MessageResourcesModel ) i.next(); 542 543 if ( mr != null ) 544 { 545 MessageResourcesDocument.MessageResources mrToEdit = null; 546 547 for ( int j = 0; j < existingMessageResources.length; ++j ) 548 { 549 String existingKey = existingMessageResources[j].getKey(); 550 551 if ( ( existingKey == null && mr.getKey() == null ) 552 || ( existingKey != null && mr.getKey() != null && existingKey.equals( mr.getKey() ) ) ) 553 { 554 mrToEdit = existingMessageResources[j]; 555 break; 556 } 557 558 } 559 560 if ( mrToEdit == null ) 561 { 562 mrToEdit = scElement.addNewMessageResources(); 563 } 564 565 mr.writeToXMLBean( mrToEdit ); 566 } 567 } 568 } 569 570 private void writeActionMappings( StrutsConfigDocument.StrutsConfig scElement ) 571 { 572 ActionMappingsDocument.ActionMappings actionMappings = scElement.getActionMappings(); 573 574 if ( actionMappings == null ) 575 { 576 actionMappings = scElement.addNewActionMappings(); 577 } 578 579 ActionDocument.Action[] existingActions = actionMappings.getActionArray(); 580 List actionMappingsList = getSortedActionMappings(); 581 582 for ( int i = 0; i < actionMappingsList.size(); ++i ) 583 { 584 ActionModel am = ( ActionModel ) actionMappingsList.get( i ); 585 ActionDocument.Action actionMappingToEdit = null; 586 587 for ( int j = 0; j < existingActions.length; ++j ) 588 { 589 if ( am.getPath().equals( existingActions[j].getPath() ) ) 590 { 591 actionMappingToEdit = existingActions[j]; 592 break; 593 } 594 } 595 596 if ( actionMappingToEdit == null ) 597 { 598 actionMappingToEdit = actionMappings.addNewAction(); 599 } 600 601 am.writeToXMLBean( actionMappingToEdit ); 602 } 603 } 604 605 private void writeExceptions( StrutsConfigDocument.StrutsConfig scElement ) 606 { 607 GlobalExceptionsDocument.GlobalExceptions globalExceptions = scElement.getGlobalExceptions(); 608 609 if ( globalExceptions == null ) 610 { 611 globalExceptions = scElement.addNewGlobalExceptions(); 612 } 613 614 List exceptionCatches = getExceptionCatchesList(); 615 if ( exceptionCatches != null && ! exceptionCatches.isEmpty() ) 616 { 617 ExceptionDocument.Exception[] existingExceptions = globalExceptions.getExceptionArray(); 618 619 for ( int i = 0; i < exceptionCatches.size(); ++i ) 620 { 621 ExceptionModel ec = ( ExceptionModel ) exceptionCatches.get( i ); 622 ExceptionDocument.Exception exceptionToEdit = null; 623 624 for ( int j = 0; j < existingExceptions.length; ++j ) 625 { 626 if ( ec.getType().equals( existingExceptions[j].getType() ) ) 627 { 628 exceptionToEdit = existingExceptions[j]; 629 break; 630 } 631 } 632 633 if ( exceptionToEdit == null ) 634 { 635 exceptionToEdit = globalExceptions.addNewException(); 636 } 637 638 ec.writeToXMLBean( exceptionToEdit ); 639 } 640 } 641 } 642 643 private void writeFormBeans( StrutsConfigDocument.StrutsConfig scElement ) 644 { 645 FormBeansDocument.FormBeans formBeans = scElement.getFormBeans(); 646 647 if ( formBeans == null ) 648 { 649 formBeans = scElement.addNewFormBeans(); 650 } 651 652 FormBeanDocument.FormBean[] existingBeans = formBeans.getFormBeanArray(); 653 654 for ( Iterator i = getFormBeansMap().values().iterator(); i.hasNext(); ) 655 { 656 FormBeanModel fb = ( FormBeanModel ) i.next(); 657 658 if ( fb != null ) 659 { 660 FormBeanDocument.FormBean formBeanToEdit = null; 661 662 for ( int j = 0; j < existingBeans.length; ++j ) 663 { 664 if ( existingBeans[j].getName().equals( fb.getName() ) ) 665 { 666 formBeanToEdit = existingBeans[j]; 667 break; 668 } 669 670 } 671 672 if ( formBeanToEdit == null ) 673 { 674 formBeanToEdit = formBeans.addNewFormBean(); 675 } 676 677 fb.writeToXMLBean( formBeanToEdit ); 678 } 679 } 680 } 681 682 protected void writeControllerElement( StrutsConfigDocument.StrutsConfig scElement ) 683 { 684 ControllerDocument.Controller controller = scElement.getController(); 685 if ( controller == null ) controller = scElement.addNewController(); 686 687 if ( controller.getProcessorClass() == null ) 688 { 689 controller.setProcessorClass( PAGEFLOW_REQUESTPROCESSOR_CLASSNAME ); 690 } 691 692 if ( controller.getInputForward() == null ) 693 { 694 controller.setInputForward( ControllerDocument.Controller.InputForward.TRUE ); 695 } 696 697 if ( _multipartHandlerClassName != null && controller.getMultipartClass() == null ) 698 { 699 controller.setMultipartClass( _multipartHandlerClassName ); 700 } 701 702 if ( _isNestedPageFlow ) addSetProperty( controller, "isNestedPageFlow", "true" ); 703 if ( _isLongLivedPageFlow ) addSetProperty( controller, "isLongLivedPageFlow", "true" ); 704 if ( _isSharedFlow ) addSetProperty( controller, "isSharedFlow", "true" ); 705 if ( isReturnToPageDisabled() ) addSetProperty( controller, "isReturnToPageDisabled", "true" ); 706 if ( isReturnToActionDisabled() ) addSetProperty( controller, "isReturnToActionDisabled", "true" ); 707 708 if ( _sharedFlows != null ) 709 { 710 StringBuffer str = new StringBuffer (); 711 boolean first = true; 712 713 for ( java.util.Iterator ii = _sharedFlows.entrySet().iterator(); ii.hasNext(); ) 714 { 715 Map.Entry entry = ( Map.Entry ) ii.next(); 716 if ( ! first ) str.append( ',' ); 717 first = false; 718 String name = ( String ) entry.getKey(); 719 String type = ( String ) entry.getValue(); 720 str.append( name ).append( '=' ).append( type ); 721 } 722 723 addSetProperty( controller, "sharedFlows", str.toString() ); 724 } 725 726 addSetProperty( controller, "controllerClass", _controllerClassName ); 727 728 MessageResourcesDocument.MessageResources[] mrArray = scElement.getMessageResourcesArray(); 733 for ( int i = 0; i < mrArray.length; i++ ) 734 { 735 MessageResourcesDocument.MessageResources messageResources = mrArray[i]; 736 if ( messageResources.getKey() == null ) return; 737 } 738 addSetProperty( controller, "isMissingDefaultMessages", "true" ); 739 } 740 741 protected static void addSetProperty( ControllerDocument.Controller controller, String propName, String propValue ) 742 { 743 if ( controller.getClassName() == null ) controller.setClassName( PAGEFLOW_CONTROLLER_CONFIG_CLASSNAME ); 744 SetPropertyDocument.SetProperty prop = controller.addNewSetProperty(); 745 prop.setProperty( propName ); 746 prop.setValue( propValue ); 747 } 748 749 protected void writeValidatorInit( StrutsConfigDocument.StrutsConfig scElement ) 750 { 751 if ( ( _validationModel != null && ! _validationModel.isEmpty() ) || _additionalValidatorConfigs != null ) 752 { 753 PlugInDocument.PlugIn plugInElementToEdit = null; 754 PlugInDocument.PlugIn[] existingPlugIns = scElement.getPlugInArray(); 755 756 for ( int i = 0; i < existingPlugIns.length; i++ ) 757 { 758 PlugInDocument.PlugIn existingPlugIn = existingPlugIns[i]; 759 760 if ( VALIDATOR_PLUG_IN_CLASSNAME.equals( existingPlugIn.getClassName() ) ) 761 { 762 plugInElementToEdit = existingPlugIn; 763 break; 764 } 765 } 766 767 if ( plugInElementToEdit == null ) 768 { 769 plugInElementToEdit = scElement.addNewPlugIn(); 770 plugInElementToEdit.setClassName( VALIDATOR_PLUG_IN_CLASSNAME ); 771 } 772 773 SetPropertyDocument.SetProperty[] existingSetProperties = plugInElementToEdit.getSetPropertyArray(); 774 775 for ( int i = 0; i < existingSetProperties.length; i++ ) 776 { 777 if ( VALIDATOR_PATHNAMES_PROPERTY.equals( existingSetProperties[i].getProperty() ) ) 778 { 779 return; 784 } 785 } 786 787 SetPropertyDocument.SetProperty pathnamesProperty = plugInElementToEdit.addNewSetProperty(); 788 pathnamesProperty.setProperty( VALIDATOR_PATHNAMES_PROPERTY ); 789 StringBuffer pathNames = new StringBuffer (); 790 pathNames.append( NETUI_VALIDATOR_RULES_URI ); 791 pathNames.append( ',' ).append( STRUTS_VALIDATOR_RULES_URI ); 792 793 if ( _validationModel != null && ! _validationModel.isEmpty() ) 794 { 795 pathNames.append( ',' ).append( _validationModel.getOutputFileURI() ); 796 } 797 798 if ( _additionalValidatorConfigs != null ) 799 { 800 for ( java.util.Iterator ii = _additionalValidatorConfigs.iterator(); ii.hasNext(); ) 801 { 802 String configFile = ( String ) ii.next(); 803 pathNames.append( ',' ).append( configFile ); 804 } 805 } 806 807 pathnamesProperty.setValue( pathNames.toString() ); 808 } 809 } 810 811 protected void writeTilesInit( StrutsConfigDocument.StrutsConfig scElement ) 812 { 813 if ( _tilesDefinitionsConfigs == null || _tilesDefinitionsConfigs.isEmpty() ) 814 { 815 return; 816 } 817 818 PlugInDocument.PlugIn plugInElementToEdit = null; 819 PlugInDocument.PlugIn[] existingPlugIns = scElement.getPlugInArray(); 820 821 for ( int i = 0; i < existingPlugIns.length; i++ ) 822 { 823 PlugInDocument.PlugIn existingPlugIn = existingPlugIns[i]; 824 825 if ( TILES_PLUG_IN_CLASSNAME.equals( existingPlugIn.getClassName() ) ) 826 { 827 plugInElementToEdit = existingPlugIn; 828 break; 829 } 830 } 831 832 if ( plugInElementToEdit == null ) 833 { 834 plugInElementToEdit = scElement.addNewPlugIn(); 835 plugInElementToEdit.setClassName( TILES_PLUG_IN_CLASSNAME ); 836 } 837 838 boolean definitionsConfigIsSet = false; 839 boolean moduleAwarePropertyIsSet = false; 840 SetPropertyDocument.SetProperty[] existingSetProperties = plugInElementToEdit.getSetPropertyArray(); 841 842 for ( int i = 0; i < existingSetProperties.length; i++ ) 843 { 844 String name = existingSetProperties[i].getProperty(); 845 846 if ( TILES_DEFINITIONS_CONFIG_PROPERTY.equals( name ) ) 847 { 848 definitionsConfigIsSet = true; 853 } 854 855 if ( TILES_MODULE_AWARE_PROPERTY.equals( name ) ) 856 { 857 moduleAwarePropertyIsSet = true; 859 } 860 } 861 862 if ( !definitionsConfigIsSet ) 863 { 864 SetPropertyDocument.SetProperty pathnamesProperty = plugInElementToEdit.addNewSetProperty(); 865 pathnamesProperty.setProperty( TILES_DEFINITIONS_CONFIG_PROPERTY ); 866 StringBuffer pathNames = new StringBuffer (); 867 boolean firstOne = true; 868 869 for ( java.util.Iterator ii = _tilesDefinitionsConfigs.iterator(); ii.hasNext(); ) 870 { 871 String definitionsConfig = ( String ) ii.next(); 872 if ( ! firstOne ) pathNames.append( ',' ); 873 firstOne = false; 874 pathNames.append( definitionsConfig ); 875 } 876 pathnamesProperty.setValue( pathNames.toString() ); 877 } 878 879 if ( !moduleAwarePropertyIsSet ) 880 { 881 SetPropertyDocument.SetProperty pathnamesProperty = plugInElementToEdit.addNewSetProperty(); 882 pathnamesProperty.setProperty( TILES_MODULE_AWARE_PROPERTY ); 883 pathnamesProperty.setValue( "true" ); 884 } 885 } 886 887 protected String getHeaderComment( File mergeFile ) 888 throws FatalCompileTimeException 889 { 890 return null; 891 } 892 893 public void setNestedPageFlow( boolean nestedPageFlow ) 894 { 895 _isNestedPageFlow = nestedPageFlow; 896 } 897 898 public void setLongLivedPageFlow( boolean longLivedPageFlow ) 899 { 900 _isLongLivedPageFlow = longLivedPageFlow; 901 } 902 903 protected static String getStrutsConfigURI( String containingPackage, boolean isSharedFlow ) 904 { 905 return getOutputFileURI( STRUTS_CONFIG_PREFIX, containingPackage, isSharedFlow ); 906 } 907 908 public static String getOutputFileURI( String filePrefix, String containingPackage, boolean isSharedFlow ) 909 { 910 StringBuffer fileName = new StringBuffer ( STRUTSCONFIG_OUTPUT_DIR ); 911 fileName.append( '/' ).append( filePrefix ); 912 if ( containingPackage != null && containingPackage.length() > 0 ) fileName.append( STRUTS_CONFIG_SEPARATOR ); 913 if ( isSharedFlow ) fileName.append( STRUTS_CONFIG_SEPARATOR ); 914 if ( containingPackage != null ) fileName.append( containingPackage.replace( '.', STRUTS_CONFIG_SEPARATOR ) ); 915 fileName.append( STRUTS_CONFIG_EXTENSION ); 916 return fileName.toString(); 917 } 918 919 protected void setSharedFlow( boolean sharedFlow ) 920 { 921 _isSharedFlow = sharedFlow; 922 } 923 924 protected void setSharedFlows( Map sharedFlows ) 925 { 926 _sharedFlows = sharedFlows; 927 } 928 929 public String getMultipartHandlerClassName() 930 { 931 return _multipartHandlerClassName; 932 } 933 934 protected void setMultipartHandlerClassName( String multipartHandlerClassName ) 935 { 936 _multipartHandlerClassName = multipartHandlerClassName; 937 } 938 939 public void setTilesDefinitionsConfigs( List tilesDefinitionsConfigs ) 940 { 941 _tilesDefinitionsConfigs = tilesDefinitionsConfigs; 942 } 943 944 protected boolean isSharedFlow() 945 { 946 return _isSharedFlow; 947 } 948 } 949 | Popular Tags |