/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Header:$
*/
package org.apache.beehive.netui.compiler.model;
import org.apache.beehive.netui.compiler.model.schema.struts11.*;
import org.apache.beehive.netui.compiler.model.validation.ValidationModel;
import org.apache.beehive.netui.compiler.JpfLanguageConstants;
import org.apache.beehive.netui.compiler.FatalCompileTimeException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlDocumentProperties;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlOptions;
import java.io.File;
import java.io.PrintStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
public class StrutsApp
extends AbstractForwardContainer
implements ForwardContainer, ExceptionContainer, JpfLanguageConstants
{
//protected boolean _isRootApp = false;
private HashMap _actionMappings = new HashMap();
private ArrayList _exceptionCatches = new ArrayList();
private ArrayList _messageResources = new ArrayList();
private HashMap _formBeans = new HashMap();
private ValidationModel _validationModel;
private List _additionalValidatorConfigs;
private boolean _returnToPageDisabled = true;
private boolean _returnToActionDisabled = true;
private boolean _isNestedPageFlow = false;
private boolean _isLongLivedPageFlow = false;
private boolean _isSharedFlow = false;
/** Map of name to typename */
private Map _sharedFlows = null;
private String _controllerClassName = null;
private String _multipartHandlerClassName = null;
private List _tilesDefinitionsConfigs = null;
protected static final String DUPLICATE_ACTION_COMMENT = "Note that there is more than one action with path \"{0}\"."
+ " Use a form-qualified action path if this is not the "
+ "one you want.";
protected static final String PAGEFLOW_REQUESTPROCESSOR_CLASSNAME
= PAGEFLOW_PACKAGE + ".PageFlowRequestProcessor";
protected static final String PAGEFLOW_CONTROLLER_CONFIG_CLASSNAME
= PAGEFLOW_PACKAGE + ".config.PageFlowControllerConfig";
protected static final String STRUTS_CONFIG_PREFIX = "jpf-struts-config";
protected static final String STRUTS_CONFIG_EXTENSION = ".xml";
protected static final char STRUTS_CONFIG_SEPARATOR = '-';
protected static final String WEBINF_DIR_NAME = "WEB-INF";
protected static final String STRUTSCONFIG_OUTPUT_DIR = '/' + WEBINF_DIR_NAME + "/.pageflow-struts-generated";
protected static final String VALIDATOR_PLUG_IN_CLASSNAME = STRUTS_PACKAGE + ".validator.ValidatorPlugIn";
protected static final String VALIDATOR_PATHNAMES_PROPERTY = "pathnames";
protected static final String TILES_PLUG_IN_CLASSNAME = STRUTS_PACKAGE + ".tiles.TilesPlugin";
protected static final String TILES_DEFINITIONS_CONFIG_PROPERTY = "definitions-config";
protected static final String TILES_MODULE_AWARE_PROPERTY = "moduleAware";
protected static final String NETUI_VALIDATOR_RULES_URI = '/' + WEBINF_DIR_NAME + "/beehive-netui-validator-rules.xml";
protected static final String STRUTS_VALIDATOR_RULES_URI = '/' + WEBINF_DIR_NAME + "/validator-rules.xml";
public StrutsApp( String controllerClassName )
{
super( null );
setParentApp( this );
_controllerClassName = controllerClassName;
//
// Add a reference for the default validation message resources (in beehive-netui-pageflow.jar).
//
MessageResourcesModel mrm = new MessageResourcesModel( this );
mrm.setParameter( DEFAULT_VALIDATION_MESSAGE_BUNDLE );
mrm.setKey( DEFAULT_VALIDATION_MESSAGE_BUNDLE_NAME );
mrm.setReturnNull( true );
addMessageResources( mrm );
}
public void addMessageResources( MessageResourcesModel mr )
{
_messageResources.add( mr );
}
private void addDisambiguatedActionMapping( ActionModel mapping )
{
if ( mapping.getFormBeanName() != null )
{
String qualifiedPath = getFormQualifiedActionPath( mapping );
ActionModel qualifiedMapping = new ActionModel( mapping, qualifiedPath );
qualifiedMapping.setUnqualifiedActionPath( mapping.getPath() );
_actionMappings.put( qualifiedPath, qualifiedMapping );
}
}
/**
* Adds a new ActionMapping to this StrutsApp.
*/
public void addActionMapping( ActionModel mapping )
{
String mappingPath = mapping.getPath();
ActionModel conflictingActionMapping = ( ActionModel ) _actionMappings.get( mappingPath );
if ( conflictingActionMapping != null )
{
ActionModel defaultMappingForThisPath = conflictingActionMapping;
//
// If the new action mapping takes no form, then it has the highest precedence, and replaces the existing
// "natural" mapping for the given path. Otherwise, replace the existing one if the existing one has a
// form bean and if the new mapping's form bean type comes alphabetically before the existing one's.
//
if ( mapping.getFormBeanName() == null
|| ( conflictingActionMapping.getFormBeanName() != null
&& getBeanType( mapping ).compareTo( getBeanType( conflictingActionMapping ) ) < 0 ) )
{
_actionMappings.put( mappingPath, mapping );
defaultMappingForThisPath = mapping;
conflictingActionMapping.setOverloaded( false );
}
addDisambiguatedActionMapping( mapping );
addDisambiguatedActionMapping( conflictingActionMapping );
defaultMappingForThisPath.setOverloaded( true );
defaultMappingForThisPath.setComment( DUPLICATE_ACTION_COMMENT.replaceAll( "\\{0\\}", mappingPath ) ); // @TODO I18N
}
else
{
_actionMappings.put( mappingPath, mapping );
}
}
//
// Returns either the "form class" (specified for non-ActionForm-derived bean types), or the type of the
// associated FormBeanModel.
//
public String getBeanType( ActionModel actionMapping )
{
String beanType = actionMapping.getFormClass(); // will be non-null for non-ActionForm-derived types
if ( beanType == null )
{
FormBeanModel bean = getFormBean( actionMapping.getFormBeanName() );
assert bean != null;
beanType = bean.getType();
}
return beanType;
}
protected String getFormQualifiedActionPath( ActionModel action )
{
assert action.getFormBeanName() != null : "action " + action.getPath() + " has no form bean";
String beanType = getBeanType( action );
return action.getPath() + '_' + makeFullyQualifiedBeanName( beanType );
}
/**
* Implemented for {@link ExceptionContainer}.
*/
public void addException( ExceptionModel c )
{
_exceptionCatches.add( c );
}
/**
* Returns all of the form beans that are defined for this
* StrutsApp.
*/
public FormBeanModel[] getFormBeans()
{
return ( FormBeanModel[] ) getFormBeansAsList().toArray( new FormBeanModel[0] );
}
/**
* Returns a list of all the form beans that are defined for this StrutsApp.
*/
public List getFormBeansAsList()
{
ArrayList retList = new ArrayList();
for ( Iterator i = _formBeans.values().iterator(); i.hasNext(); )
{
FormBeanModel fb = ( FormBeanModel ) i.next();
if ( fb != null ) retList.add( fb );
}
return retList;
}
public FormBeanModel getFormBean( String formBeanName )
{
return ( FormBeanModel ) _formBeans.get( formBeanName );
}
/**
* Returns a list of {@link FormBeanModel}.
*/
public List getFormBeansByActualType( String actualTypeName, Boolean usesPageFlowScopedBean )
{
ArrayList beans = null;
for ( Iterator i = _formBeans.values().iterator(); i.hasNext(); )
{
FormBeanModel formBean = ( FormBeanModel ) i.next();
if ( formBean != null && formBean.getActualType().equals( actualTypeName )
&& ( usesPageFlowScopedBean == null || usesPageFlowScopedBean.booleanValue() == formBean.isPageFlowScoped() ) )
{
if ( beans == null ) beans = new ArrayList();
beans.add( formBean );
}
}
return beans;
}
/**
* Adds a new form bean to this StrutsApp.
*/
public void addFormBean( FormBeanModel newFormBean )
{
_formBeans.put( newFormBean.getName(), newFormBean );
}
/**
* Delete the given form-bean.
*/
public void deleteFormBean( FormBeanModel formBean )
{
_formBeans.remove( formBean.getName() );
}
public String getFormNameForType( String formType, boolean isPageFlowScoped )
{
//
// First try and create a form-bean name that is a camelcased version of the classname without all of its
// package/outer-class qualifiers. If one with that name already exists, munge the fully-qualified classname.
//
int lastQualifier = formType.lastIndexOf( '$' );
if ( lastQualifier == -1 ) lastQualifier = formType.lastIndexOf( '.' );
String formBeanName = formType.substring( lastQualifier + 1 );
formBeanName = Character.toLowerCase( formBeanName.charAt( 0 ) ) + formBeanName.substring( 1 );
//
// If there's a name conflict, we need to disambiguate.
//
if ( _formBeans.containsKey( formBeanName ) )
{
String conflictingName = formBeanName;
FormBeanModel conflictingBean = ( FormBeanModel ) _formBeans.get( conflictingName );
//
// If the conflicting form bean has a different value for isPageFlowScoped(), we can simply add a suffix
// to this bean name.
//
if ( conflictingBean != null && isPageFlowScoped != conflictingBean.isPageFlowScoped() )
{
formBeanName += isPageFlowScoped ? "_flowScoped" : "_nonFlowScoped";
assert ! _formBeans.containsKey( formBeanName ); // we generate this name -- shouldn't conflict
return formBeanName;
}
formBeanName = makeFullyQualifiedBeanName( formType );
//
// Now look for the one we're conflicting with
//
if ( conflictingBean != null )
{
String nonConflictingName = makeFullyQualifiedBeanName( conflictingBean.getType() );
conflictingBean.setName( nonConflictingName );
_formBeans.put( nonConflictingName, conflictingBean );
//
// Now look for any action mappings that are using the conflicting name...
//
for ( Iterator i = _actionMappings.values().iterator(); i.hasNext(); )
{
ActionModel mapping = ( ActionModel ) i.next();
if ( mapping.getFormBeanName() != null && mapping.getFormBeanName().equals( conflictingName ) )
{
mapping.setFormBeanName( nonConflictingName );
}
}
}
_formBeans.put( conflictingName, null );
}
return formBeanName;
}
protected static String makeFullyQualifiedBeanName( String formType )
{
return formType.replace( '.', '_' ).replace( '$', '_' );
}
protected static class ActionMappingComparator implements Comparator
{
public int compare( Object o1, Object o2 )
{
assert o1 instanceof ActionModel && o2 instanceof ActionModel;
ActionModel am1 = ( ActionModel ) o1;
ActionModel am2 = ( ActionModel ) o2;
assert ! am1.getPath().equals( am2.getPath() ); // there should be no duplicate paths
return am1.getPath().compareTo( am2.getPath() );
}
}
protected ForwardDocument.Forward addNewForward( XmlObject xmlObject )
{
return ( ( GlobalForwardsDocument.GlobalForwards ) xmlObject ).addNewForward();
}
protected Map getFormBeansMap()
{
return _formBeans;
}
protected List getExceptionCatchesList()
{
return _exceptionCatches;
}
protected List getSortedActionMappings()
{
ArrayList sortedActionMappings = new ArrayList();
sortedActionMappings.addAll( _actionMappings.values() );
Collections.sort( sortedActionMappings, new ActionMappingComparator() );
return sortedActionMappings;
}
protected List getMessageResourcesList()
{
return _messageResources;
}
/**
* Get the MessageResourcesModel for which no "key" is set (the default one used at runtime).
*/
public MessageResourcesModel getDefaultMessageResources()
{
for ( java.util.Iterator ii = _messageResources.iterator(); ii.hasNext(); )
{
MessageResourcesModel i = ( MessageResourcesModel ) ii.next();
if ( i.getKey() == null ) return i;
}
return null;
}
public boolean isReturnToPageDisabled()
{
return _returnToPageDisabled;
}
public boolean isReturnToActionDisabled()
{
return _returnToActionDisabled;
}
public void setReturnToPageDisabled( boolean disabled )
{
_returnToPageDisabled = disabled;
}
public void setReturnToActionDisabled( boolean disabled )
{
_returnToActionDisabled = disabled;
}
public void setAdditionalValidatorConfigs( List additionalValidatorConfigs )
{
if ( additionalValidatorConfigs != null && ! additionalValidatorConfigs.isEmpty() )
{
_additionalValidatorConfigs = additionalValidatorConfigs;
}
}
public void setValidationModel( ValidationModel validationModel )
{
if ( ! validationModel.isEmpty() ) // if there's nothing in the validation model, we don't care about it.
{
_validationModel = validationModel;
}
}
public void writeXml( PrintStream outputStream, File mergeFile, String webappBuildRoot )
throws IOException, XmlException, FatalCompileTimeException
{
StrutsConfigDocument doc;
if ( mergeFile != null && mergeFile.canRead() )
{
doc = StrutsConfigDocument.Factory.parse( mergeFile );
}
else
{
doc = StrutsConfigDocument.Factory.newInstance();
}
//
// Write the DOCTYPE and all that good stuff.
//
XmlDocumentProperties docProps = doc.documentProperties();
if ( docProps.getDoctypeName() == null )
{
docProps.setDoctypeName( "struts-config" ); // NOI18N
}
if ( docProps.getDoctypePublicId() == null )
{
docProps.setDoctypePublicId( "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" ); // NOI18N
}
if ( docProps.getDoctypeSystemId() == null )
{
docProps.setDoctypeSystemId( "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" ); // NOI18N
}
//
// struts-config
//
StrutsConfigDocument.StrutsConfig scElement = doc.getStrutsConfig();
if ( scElement == null )
{
scElement = doc.addNewStrutsConfig();
}
//
// Write the "generated by" comment.
//
XmlCursor curs = scElement.newCursor();
String headerComment = getHeaderComment( mergeFile );
if ( headerComment != null ) curs.insertComment( headerComment );
//
// form-beans
//
writeFormBeans( scElement );
//
// global-exceptions
//
writeExceptions( scElement );
//
// global-forwards
//
GlobalForwardsDocument.GlobalForwards globalForwards = scElement.getGlobalForwards();
if ( globalForwards == null )
{
globalForwards = scElement.addNewGlobalForwards();
}
writeForwards( globalForwards.getForwardArray(), globalForwards );
//
// action-mappings
//
writeActionMappings( scElement );
//
// message-resources
//
writeMessageResources( scElement );
//
// request-processor
//
writeControllerElement( scElement );
//
// ValidatorPlugIn
//
writeValidatorInit( scElement );
//
// TilesPlugin
//
writeTilesInit( scElement );
//
// Write the file.
//
XmlOptions options = new XmlOptions();
options.setSavePrettyPrint();
doc.save( outputStream, options );
}
private void writeMessageResources( StrutsConfigDocument.StrutsConfig scElement )
{
MessageResourcesDocument.MessageResources[] existingMessageResources = scElement.getMessageResourcesArray();
for ( Iterator i = getMessageResourcesList().iterator(); i.hasNext(); )
{
MessageResourcesModel mr = ( MessageResourcesModel ) i.next();
if ( mr != null )
{
MessageResourcesDocument.MessageResources mrToEdit = null;
for ( int j = 0; j < existingMessageResources.length; ++j )
{
String existingKey = existingMessageResources[j].getKey();
if ( ( existingKey == null && mr.getKey() == null )
|| ( existingKey != null && mr.getKey() != null && existingKey.equals( mr.getKey() ) ) )
{
mrToEdit = existingMessageResources[j];
break;
}
}
if ( mrToEdit == null )
{
mrToEdit = scElement.addNewMessageResources();
}
mr.writeToXMLBean( mrToEdit );
}
}
}
private void writeActionMappings( StrutsConfigDocument.StrutsConfig scElement )
{
ActionMappingsDocument.ActionMappings actionMappings = scElement.getActionMappings();
if ( actionMappings == null )
{
actionMappings = scElement.addNewActionMappings();
}
ActionDocument.Action[] existingActions = actionMappings.getActionArray();
List actionMappingsList = getSortedActionMappings();
for ( int i = 0; i < actionMappingsList.size(); ++i )
{
ActionModel am = ( ActionModel ) actionMappingsList.get( i );
ActionDocument.Action actionMappingToEdit = null;
for ( int j = 0; j < existingActions.length; ++j )
{
if ( am.getPath().equals( existingActions[j].getPath() ) )
{
actionMappingToEdit = existingActions[j];
break;
}
}
if ( actionMappingToEdit == null )
{
actionMappingToEdit = actionMappings.addNewAction();
}
am.writeToXMLBean( actionMappingToEdit );
}
}
private void writeExceptions( StrutsConfigDocument.StrutsConfig scElement )
{
GlobalExceptionsDocument.GlobalExceptions globalExceptions = scElement.getGlobalExceptions();
if ( globalExceptions == null )
{
globalExceptions = scElement.addNewGlobalExceptions();
}
List exceptionCatches = getExceptionCatchesList();
if ( exceptionCatches != null && ! exceptionCatches.isEmpty() )
{
ExceptionDocument.Exception[] existingExceptions = globalExceptions.getExceptionArray();
for ( int i = 0; i < exceptionCatches.size(); ++i )
{
ExceptionModel ec = ( ExceptionModel ) exceptionCatches.get( i );
ExceptionDocument.Exception exceptionToEdit = null;
for ( int j = 0; j < existingExceptions.length; ++j )
{
if ( ec.getType().equals( existingExceptions[j].getType() ) )
{
exceptionToEdit = existingExceptions[j];
break;
}
}
if ( exceptionToEdit == null )
{
exceptionToEdit = globalExceptions.addNewException();
}
ec.writeToXMLBean( exceptionToEdit );
}
}
}
private void writeFormBeans( StrutsConfigDocument.StrutsConfig scElement )
{
FormBeansDocument.FormBeans formBeans = scElement.getFormBeans();
if ( formBeans == null )
{
formBeans = scElement.addNewFormBeans();
}
FormBeanDocument.FormBean[] existingBeans = formBeans.getFormBeanArray();
for ( Iterator i = getFormBeansMap().values().iterator(); i.hasNext(); )
{
FormBeanModel fb = ( FormBeanModel ) i.next();
if ( fb != null )
{
FormBeanDocument.FormBean formBeanToEdit = null;
for ( int j = 0; j < existingBeans.length; ++j )
{
if ( existingBeans[j].getName().equals( fb.getName() ) )
{
formBeanToEdit = existingBeans[j];
break;
}
}
if ( formBeanToEdit == null )
{
formBeanToEdit = formBeans.addNewFormBean();
}
fb.writeToXMLBean( formBeanToEdit );
}
}
}
protected void writeControllerElement( StrutsConfigDocument.StrutsConfig scElement )
{
ControllerDocument.Controller controller = scElement.getController();
if ( controller == null ) controller = scElement.addNewController();
if ( controller.getProcessorClass() == null )
{
controller.setProcessorClass( PAGEFLOW_REQUESTPROCESSOR_CLASSNAME );
}
if ( controller.getInputForward() == null )
{
controller.setInputForward( ControllerDocument.Controller.InputForward.TRUE );
}
if ( _multipartHandlerClassName != null && controller.getMultipartClass() == null )
{
controller.setMultipartClass( _multipartHandlerClassName );
}
if ( _isNestedPageFlow ) addSetProperty( controller, "isNestedPageFlow", "true" );
if ( _isLongLivedPageFlow ) addSetProperty( controller, "isLongLivedPageFlow", "true" );
if ( _isSharedFlow ) addSetProperty( controller, "isSharedFlow", "true" );
if ( isReturnToPageDisabled() ) addSetProperty( controller, "isReturnToPageDisabled", "true" );
if ( isReturnToActionDisabled() ) addSetProperty( controller, "isReturnToActionDisabled", "true" );
if ( _sharedFlows != null )
{
StringBuffer str = new StringBuffer();
boolean first = true;
for ( java.util.Iterator ii = _sharedFlows.entrySet().iterator(); ii.hasNext(); )
{
Map.Entry entry = ( Map.Entry ) ii.next();
if ( ! first ) str.append( ',' );
first = false;
String name = ( String ) entry.getKey();
String type = ( String ) entry.getValue();
str.append( name ).append( '=' ).append( type );
}
addSetProperty( controller, "sharedFlows", str.toString() );
}
addSetProperty( controller, "controllerClass", _controllerClassName );
//
// If there is not a default MessageResources element in the generated XML, add a special set-property
// to communicate this to the runtime.
//
MessageResourcesDocument.MessageResources[] mrArray = scElement.getMessageResourcesArray();
for ( int i = 0; i < mrArray.length; i++ )
{
MessageResourcesDocument.MessageResources messageResources = mrArray[i];
if ( messageResources.getKey() == null ) return;
}
addSetProperty( controller, "isMissingDefaultMessages", "true" );
}
protected static void addSetProperty( ControllerDocument.Controller controller, String propName, String propValue )
{
if ( controller.getClassName() == null ) controller.setClassName( PAGEFLOW_CONTROLLER_CONFIG_CLASSNAME );
SetPropertyDocument.SetProperty prop = controller.addNewSetProperty();
prop.setProperty( propName );
prop.setValue( propValue );
}
protected void writeValidatorInit( StrutsConfigDocument.StrutsConfig scElement )
{
if ( ( _validationModel != null && ! _validationModel.isEmpty() ) || _additionalValidatorConfigs != null )
{
PlugInDocument.PlugIn plugInElementToEdit = null;
PlugInDocument.PlugIn[] existingPlugIns = scElement.getPlugInArray();
for ( int i = 0; i < existingPlugIns.length; i++ )
{
PlugInDocument.PlugIn existingPlugIn = existingPlugIns[i];
if ( VALIDATOR_PLUG_IN_CLASSNAME.equals( existingPlugIn.getClassName() ) )
{
plugInElementToEdit = existingPlugIn;
break;
}
}
if ( plugInElementToEdit == null )
{
plugInElementToEdit = scElement.addNewPlugIn();
plugInElementToEdit.setClassName( VALIDATOR_PLUG_IN_CLASSNAME );
}
SetPropertyDocument.SetProperty[] existingSetProperties = plugInElementToEdit.getSetPropertyArray();
for ( int i = 0; i < existingSetProperties.length; i++ )
{
if ( VALIDATOR_PATHNAMES_PROPERTY.equals( existingSetProperties[i].getProperty() ) )
{
//
// This means that in the user's struts-merge file, there's already a "pathnames" set-property
// element. We don't want to overwrite it.
//
return;
}
}
SetPropertyDocument.SetProperty pathnamesProperty = plugInElementToEdit.addNewSetProperty();
pathnamesProperty.setProperty( VALIDATOR_PATHNAMES_PROPERTY );
StringBuffer pathNames = new StringBuffer();
pathNames.append( NETUI_VALIDATOR_RULES_URI );
pathNames.append( ',' ).append( STRUTS_VALIDATOR_RULES_URI );
if ( _validationModel != null && ! _validationModel.isEmpty() )
{
pathNames.append( ',' ).append( _validationModel.getOutputFileURI() );
}
if ( _additionalValidatorConfigs != null )
{
for ( java.util.Iterator ii = _additionalValidatorConfigs.iterator(); ii.hasNext(); )
{
String configFile = ( String ) ii.next();
pathNames.append( ',' ).append( configFile );
}
}
pathnamesProperty.setValue( pathNames.toString() );
}
}
protected void writeTilesInit( StrutsConfigDocument.StrutsConfig scElement )
{
if ( _tilesDefinitionsConfigs == null || _tilesDefinitionsConfigs.isEmpty() )
{
return;
}
PlugInDocument.PlugIn plugInElementToEdit = null;
PlugInDocument.PlugIn[] existingPlugIns = scElement.getPlugInArray();
for ( int i = 0; i < existingPlugIns.length; i++ )
{
PlugInDocument.PlugIn existingPlugIn = existingPlugIns[i];
if ( TILES_PLUG_IN_CLASSNAME.equals( existingPlugIn.getClassName() ) )
{
plugInElementToEdit = existingPlugIn;
break;
}
}
if ( plugInElementToEdit == null )
{
plugInElementToEdit = scElement.addNewPlugIn();
plugInElementToEdit.setClassName( TILES_PLUG_IN_CLASSNAME );
}
boolean definitionsConfigIsSet = false;
boolean moduleAwarePropertyIsSet = false;
SetPropertyDocument.SetProperty[] existingSetProperties = plugInElementToEdit.getSetPropertyArray();
for ( int i = 0; i < existingSetProperties.length; i++ )
{
String name = existingSetProperties[i].getProperty();
if ( TILES_DEFINITIONS_CONFIG_PROPERTY.equals( name ) )
{
//
// This means that in the user's struts-merge file, there's already a
// "definitions-config" set-property element. We don't want to overwrite it.
//
definitionsConfigIsSet = true;
}
if ( TILES_MODULE_AWARE_PROPERTY.equals( name ) )
{
// Make sure "moduleAware" is true
moduleAwarePropertyIsSet = true;
}
}
if ( !definitionsConfigIsSet )
{
SetPropertyDocument.SetProperty pathnamesProperty = plugInElementToEdit.addNewSetProperty();
pathnamesProperty.setProperty( TILES_DEFINITIONS_CONFIG_PROPERTY );
StringBuffer pathNames = new StringBuffer();
boolean firstOne = true;
for ( java.util.Iterator ii = _tilesDefinitionsConfigs.iterator(); ii.hasNext(); )
{
String definitionsConfig = ( String ) ii.next();
if ( ! firstOne ) pathNames.append( ',' );
firstOne = false;
pathNames.append( definitionsConfig );
}
pathnamesProperty.setValue( pathNames.toString() );
}
if ( !moduleAwarePropertyIsSet )
{
SetPropertyDocument.SetProperty pathnamesProperty = plugInElementToEdit.addNewSetProperty();
pathnamesProperty.setProperty( TILES_MODULE_AWARE_PROPERTY );
pathnamesProperty.setValue( "true" );
}
}
protected String getHeaderComment( File mergeFile )
throws FatalCompileTimeException
{
return null;
}
public void setNestedPageFlow( boolean nestedPageFlow )
{
_isNestedPageFlow = nestedPageFlow;
}
public void setLongLivedPageFlow( boolean longLivedPageFlow )
{
_isLongLivedPageFlow = longLivedPageFlow;
}
protected static String getStrutsConfigURI( String containingPackage, boolean isSharedFlow )
{
return getOutputFileURI( STRUTS_CONFIG_PREFIX, containingPackage, isSharedFlow );
}
public static String getOutputFileURI( String filePrefix, String containingPackage, boolean isSharedFlow )
{
StringBuffer fileName = new StringBuffer( STRUTSCONFIG_OUTPUT_DIR );
fileName.append( '/' ).append( filePrefix );
if ( containingPackage != null && containingPackage.length() > 0 ) fileName.append( STRUTS_CONFIG_SEPARATOR );
if ( isSharedFlow ) fileName.append( STRUTS_CONFIG_SEPARATOR );
if ( containingPackage != null ) fileName.append( containingPackage.replace( '.', STRUTS_CONFIG_SEPARATOR ) );
fileName.append( STRUTS_CONFIG_EXTENSION );
return fileName.toString();
}
protected void setSharedFlow( boolean sharedFlow )
{
_isSharedFlow = sharedFlow;
}
protected void setSharedFlows( Map sharedFlows )
{
_sharedFlows = sharedFlows;
}
public String getMultipartHandlerClassName()
{
return _multipartHandlerClassName;
}
protected void setMultipartHandlerClassName( String multipartHandlerClassName )
{
_multipartHandlerClassName = multipartHandlerClassName;
}
public void setTilesDefinitionsConfigs( List tilesDefinitionsConfigs )
{
_tilesDefinitionsConfigs = tilesDefinitionsConfigs;
}
protected boolean isSharedFlow()
{
return _isSharedFlow;
}
}