org.apache.struts.tiles
public class: TilesPlugin [javadoc |
source]
java.lang.Object
org.apache.struts.tiles.TilesPlugin
All Implemented Interfaces:
org.apache.struts.action.PlugIn
Direct Known Subclasses:
TilesPlugin
Tiles Plugin used to initialize Tiles.
This plugin is to be used with Struts 1.1 in association with
TilesRequestProcessor .
This plugin creates one definition factory for each Struts-module. The definition factory
configuration is read first from 'web.xml' (backward compatibility), then it is
overloaded with values found in the plugin property values.
The plugin changes the Struts configuration by specifying a
TilesRequestProcessor as
request processor. If you want to use your own RequestProcessor,
it should subclass TilesRequestProcessor.
This plugin can also be used to create one single factory for all modules.
This behavior is enabled by specifying
moduleAware=false
in each
plugin properties. In this case, the definition factory
configuration file is read by the first Tiles plugin to be initialized. The order is
determined by the order of modules declaration in web.xml. The first module
is always the default one if it exists.
The plugin should be declared in each struts-config.xml file in order to
properly initialize the request processor.
Field Summary |
---|
protected static Log | log | Commons Logging instance. |
protected boolean | moduleAware | Is the factory module aware? |
protected String | tilesUtilImplClassname | Tiles util implementation classname. This property can be set
by user in the plugin declaration. |
protected DefinitionsFactory | definitionFactory | Associated definition factory. |
protected PlugInConfig | currentPlugInConfigObject | The plugin config object provided by the ActionServlet initializing
this plugin. |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.struts.tiles.TilesPlugin Detail: |
public void destroy() {
definitionFactory.destroy();
definitionFactory = null;
}
|
protected Map findStrutsPlugInConfigProperties(ActionServlet servlet,
ModuleConfig config) throws ServletException {
return currentPlugInConfigObject.getProperties();
}
Find original properties set in the Struts PlugInConfig object.
First, we need to find the index of this plugin. Then we retrieve the array of configs
and then the object for this plugin. |
public String getTilesUtilImplClassname() {
return tilesUtilImplClassname;
}
Get Tiles util implemention classname. |
public void init(ActionServlet servlet,
ModuleConfig moduleConfig) throws ServletException {
// Create factory config object
DefinitionsFactoryConfig factoryConfig =
readFactoryConfig(servlet, moduleConfig);
// Set the module name in the config. This name will be used to compute
// the name under which the factory is stored.
factoryConfig.setFactoryName(moduleConfig.getPrefix());
// Set RequestProcessor class
this.initRequestProcessorClass(moduleConfig);
this.initTilesUtil();
this.initDefinitionsFactory(servlet.getServletContext(), moduleConfig, factoryConfig);
}
|
protected void initRequestProcessorClass(ModuleConfig config) throws ServletException {
String tilesProcessorClassname = TilesRequestProcessor.class.getName();
ControllerConfig ctrlConfig = config.getControllerConfig();
String configProcessorClassname = ctrlConfig.getProcessorClass();
// Check if specified classname exist
Class configProcessorClass;
try {
configProcessorClass =
RequestUtils.applicationClass(configProcessorClassname);
} catch (ClassNotFoundException ex) {
log.fatal(
"Can't set TilesRequestProcessor: bad class name '"
+ configProcessorClassname
+ "'.");
throw new ServletException(ex);
}
// Check if it is the default request processor or Tiles one.
// If true, replace by Tiles' one.
if (configProcessorClassname.equals(RequestProcessor.class.getName())
|| configProcessorClassname.endsWith(tilesProcessorClassname)) {
ctrlConfig.setProcessorClass(tilesProcessorClassname);
return;
}
// Check if specified request processor is compatible with Tiles.
Class tilesProcessorClass = TilesRequestProcessor.class;
if (!tilesProcessorClass.isAssignableFrom(configProcessorClass)) {
// Not compatible
String msg =
"TilesPlugin : Specified RequestProcessor not compatible with TilesRequestProcessor";
if (log.isFatalEnabled()) {
log.fatal(msg);
}
throw new ServletException(msg);
}
}
Set RequestProcessor to appropriate Tiles RequestProcessor .
First, check if a RequestProcessor is specified. If yes, check if it extends
the appropriate TilesRequestProcessor class. If not, set processor class to
TilesRequestProcessor. |
public boolean isModuleAware() {
return moduleAware;
}
Get the module aware flag. |
protected DefinitionsFactoryConfig readFactoryConfig(ActionServlet servlet,
ModuleConfig config) throws ServletException {
// Create tiles definitions config object
DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
// Get init parameters from web.xml files
try {
DefinitionsUtil.populateDefinitionsFactoryConfig(
factoryConfig,
servlet.getServletConfig());
} catch (Exception ex) {
if (log.isDebugEnabled()){
log.debug("", ex);
}
ex.printStackTrace();
throw new UnavailableException(
"Can't populate DefinitionsFactoryConfig class from 'web.xml': "
+ ex.getMessage());
}
// Get init parameters from struts-config.xml
try {
Map strutsProperties = findStrutsPlugInConfigProperties(servlet, config);
factoryConfig.populate(strutsProperties);
} catch (Exception ex) {
if (log.isDebugEnabled()) {
log.debug("", ex);
}
throw new UnavailableException(
"Can't populate DefinitionsFactoryConfig class from '"
+ config.getPrefix()
+ "/struts-config.xml':"
+ ex.getMessage());
}
return factoryConfig;
}
Create FactoryConfig and initialize it from web.xml and struts-config.xml. |
public void setCurrentPlugInConfigObject(PlugInConfig plugInConfigObject) {
this.currentPlugInConfigObject = plugInConfigObject;
}
Method used by the ActionServlet initializing this plugin.
Set the plugin config object read from module config. |
public void setModuleAware(boolean moduleAware) {
this.moduleAware = moduleAware;
}
Set the module aware flag.
This flag is only meaningful if the property tilesUtilImplClassname is not
set. |
public void setTilesUtilImplClassname(String tilesUtilImplClassname) {
this.tilesUtilImplClassname = tilesUtilImplClassname;
}
Set Tiles util implemention classname.
If this property is set, the flag moduleAware will not be used anymore. |