📄 tilesplugin.java
字号:
{
throw new ServletException( "Can't set TilesUtil implementation to '"
+ getTilesUtilImplClassname()
+ "'. TilesUtil implementation should be a subclass of '"
+ TilesUtilStrutsImpl.class.getName()
+ "'" );
}
catch( Exception ex )
{
throw new ServletException( "Can't set TilesUtil implementation.", ex );
}
} // end if
} // end if
// Check if a factory already exist for this module
definitionFactory = ((TilesUtilStrutsImpl)TilesUtil.getTilesUtil()).getDefinitionsFactory(servlet.getServletContext(), moduleConfig);
if (definitionFactory != null)
{
if (log.isInfoEnabled())
log.info( "Factory already exists for module '"
+ moduleConfig.getPrefix()
+ "'. The factory found is from module '"
+ definitionFactory.getConfig().getFactoryName()
+ "'. No new creation.");
return;
} // end if
// Create configurable factory
try
{
definitionFactory = TilesUtil.createDefinitionsFactory(servlet.getServletContext(), factoryConfig);
}
catch (DefinitionsFactoryException ex)
{
log.error("Can't create Tiles definition factory for module '" + moduleConfig.getPrefix() + "'.");
throw new ServletException(ex);
}
log.info("Tiles definition factory loaded for module '" + moduleConfig.getPrefix() + "'.");
}
/**
* End plugin.
*/
public void destroy() {
definitionFactory.destroy();
definitionFactory = null;
}
/**
* Create FactoryConfig and initialize it from web.xml and struts-config.xml.
*
* @param servlet ActionServlet that is managing all the modules
* in this web application.
* @param config ModuleConfig for the module with which
* this plugin is associated.
* @exception ServletException if this <code>PlugIn</code> cannot
* be successfully initialized.
*/
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;
}
/**
* 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.
* @param servlet ActionServlet that is managing all the modules
* in this web application.
* @param config ModuleConfig for the module with which
* this plug in is associated.
*
* @exception ServletException if this <code>PlugIn</code> cannot
* be successfully initialized.
*/
protected Map findStrutsPlugInConfigProperties(ActionServlet servlet, ModuleConfig config)
throws ServletException
{
return currentPlugInConfigObject.getProperties();
}
/**
* Set RequestProcessor to appropriate Tiles {@link RequestProcessor}.
* First, check if a RequestProcessor is specified. If yes, check if it extends
* the appropriate {@link TilesRequestProcessor} class. If not, set processor class to
* TilesRequestProcessor.
*
* @param config ModuleConfig for the module with which
* this plugin is associated.
* @throws ServletException On errors.
*/
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(java.lang.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);
} // end if
}
/**
* Set Tiles util implemention classname.
* If this property is set, the flag <code>moduleAware</code> will not be used anymore.
* @param tilesUtilImplClassname Classname.
*/
public void setTilesUtilImplClassname(String tilesUtilImplClassname)
{
this.tilesUtilImplClassname = tilesUtilImplClassname;
}
/**
* Get Tiles util implemention classname.
* @return The classname or <code>null</code> if none is set.
*/
public String getTilesUtilImplClassname()
{
return tilesUtilImplClassname;
}
/**
* Method used by the ActionServlet initializing this plugin.
* Set the plugin config object read from module config.
* @param plugInConfigObject PlugInConfig.
*/
public void setCurrentPlugInConfigObject(PlugInConfig plugInConfigObject)
{
this.currentPlugInConfigObject = plugInConfigObject;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -