org.springframework.web.servlet.view.tiles2
Class TilesConfigurer

java.lang.Object
  extended by org.springframework.web.servlet.view.tiles2.TilesConfigurer
All Implemented Interfaces:
DisposableBean, InitializingBean, ServletContextAware

public class TilesConfigurer
extends java.lang.Object
implements ServletContextAware, InitializingBean, DisposableBean

Helper class to configure Tiles 2.x for the Spring Framework. See http://tiles.apache.org for more information about Tiles, which basically is a templating mechanism for JSP-based web applications. Note: Spring 3.0 requires Tiles 2.1.2 or above, with explicit support for Tiles 2.2. Tiles 2.1's EL support will be activated by default when running on JSP 2.1 or above and when the Tiles EL module is present in the classpath.

The TilesConfigurer simply configures a TilesContainer using a set of files containing definitions, to be accessed by TilesView instances. This is a Spring-based alternative (for usage in Spring configuration) to the Tiles-provided org.apache.tiles.web.startup.TilesListener (for usage in web.xml).

TilesViews can be managed by any ViewResolver. For simple convention-based view resolution, consider using TilesViewResolver.

A typical TilesConfigurer bean definition looks as follows:

 <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
   <property name="definitions">
     <list>
       <value>/WEB-INF/defs/general.xml</value>
       <value>/WEB-INF/defs/widgets.xml</value>
       <value>/WEB-INF/defs/administrator.xml</value>
       <value>/WEB-INF/defs/customer.xml</value>
       <value>/WEB-INF/defs/templates.xml</value>
     </list>
   </property>
 </bean>
The values in the list are the actual Tiles XML files containing the definitions.

Since:
2.5
Author:
Juergen Hoeller
See Also:
TilesView, TilesViewResolver

Nested Class Summary
private  class TilesConfigurer.JspExpressionChecker
           
private  class TilesConfigurer.SpringTilesContainerFactory
           
private  class TilesConfigurer.SpringTilesInitializer
           
private  class TilesConfigurer.TilesElActivator
           
 
Field Summary
private  boolean checkRefresh
           
private  java.lang.String[] definitions
           
private  java.lang.Class<? extends DefinitionsFactory> definitionsFactoryClass
           
protected  Log logger
           
private  boolean overrideLocaleResolver
           
private  java.lang.Class<? extends PreparerFactory> preparerFactoryClass
           
private  ServletContext servletContext
           
private static boolean tiles22Present
           
private static boolean tilesElPresent
           
private  TilesInitializer tilesInitializer
           
private  java.util.Map<java.lang.String,java.lang.String> tilesPropertyMap
           
private  boolean useMutableTilesContainer
           
private  boolean validateDefinitions
           
 
Constructor Summary
TilesConfigurer()
           
 
Method Summary
private static void addClassNameIfPresent(java.lang.StringBuilder sb, java.lang.String className)
           
 void afterPropertiesSet()
          Creates and exposes a TilesContainer for this web application, delegating to the TilesInitializer.
protected  TilesInitializer createTilesInitializer()
          Creates a new instance of org.apache.tiles.startup.BasicTilesInitializer.
 void destroy()
          Removes the TilesContainer from this web application.
 void setCheckRefresh(boolean checkRefresh)
          Set whether to check Tiles definition files for a refresh at runtime.
 void setCompleteAutoload(boolean completeAutoload)
          Specify whether to apply Tiles 2.2's "complete-autoload" configuration.
 void setDefinitions(java.lang.String[] definitions)
          Set the Tiles definitions, i.e.
 void setDefinitionsFactoryClass(java.lang.Class<? extends DefinitionsFactory> definitionsFactoryClass)
          Set the org.apache.tiles.definition.DefinitionsFactory implementation to use.
 void setPreparerFactoryClass(java.lang.Class<? extends PreparerFactory> preparerFactoryClass)
          Set the org.apache.tiles.preparer.PreparerFactory implementation to use.
 void setServletContext(ServletContext servletContext)
          Set the ServletContext that this object runs in.
 void setTilesInitializer(TilesInitializer tilesInitializer)
          Configure Tiles using a custom TilesInitializer, typically specified as an inner bean.
 void setTilesProperties(java.util.Properties tilesProperties)
          Set Tiles properties (equivalent to the ServletContext init-params in the Tiles documentation), overriding the default settings.
 void setUseMutableTilesContainer(boolean useMutableTilesContainer)
          Set whether to use a MutableTilesContainer (typically the CachingTilesContainer implementation) for this application.
 void setValidateDefinitions(boolean validateDefinitions)
          Set whether to validate the Tiles XML definitions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tilesElPresent

private static final boolean tilesElPresent

tiles22Present

private static final boolean tiles22Present

logger

protected final Log logger

tilesInitializer

private TilesInitializer tilesInitializer

overrideLocaleResolver

private boolean overrideLocaleResolver

definitions

private java.lang.String[] definitions

checkRefresh

private boolean checkRefresh

validateDefinitions

private boolean validateDefinitions

definitionsFactoryClass

private java.lang.Class<? extends DefinitionsFactory> definitionsFactoryClass

preparerFactoryClass

private java.lang.Class<? extends PreparerFactory> preparerFactoryClass

useMutableTilesContainer

private boolean useMutableTilesContainer

tilesPropertyMap

private final java.util.Map<java.lang.String,java.lang.String> tilesPropertyMap

servletContext

private ServletContext servletContext
Constructor Detail

TilesConfigurer

public TilesConfigurer()
Method Detail

addClassNameIfPresent

private static void addClassNameIfPresent(java.lang.StringBuilder sb,
                                          java.lang.String className)

setTilesInitializer

public void setTilesInitializer(TilesInitializer tilesInitializer)
Configure Tiles using a custom TilesInitializer, typically specified as an inner bean.

Default is a variant of org.apache.tiles.startup.DefaultTilesInitializer, respecting the "definitions", "preparerFactoryClass" etc properties on this configurer.

NOTE: Specifying a custom TilesInitializer effectively disables all other bean properties on this configurer. The entire initialization procedure is then left to the TilesInitializer as specified.


setCompleteAutoload

public void setCompleteAutoload(boolean completeAutoload)
Specify whether to apply Tiles 2.2's "complete-autoload" configuration.

See org.apache.tiles.extras.complete.CompleteAutoloadTilesContainerFactory for details on the complete-autoload mode.

NOTE: Specifying the complete-autoload mode effectively disables all other bean properties on this configurer. The entire initialization procedure is then left to org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer.

See Also:
org.apache.tiles.extras.complete.CompleteAutoloadTilesContainerFactory, org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer

setDefinitions

public void setDefinitions(java.lang.String[] definitions)
Set the Tiles definitions, i.e. the list of files containing the definitions. Default is "/WEB-INF/tiles.xml".


setCheckRefresh

public void setCheckRefresh(boolean checkRefresh)
Set whether to check Tiles definition files for a refresh at runtime. Default is "false".


setValidateDefinitions

public void setValidateDefinitions(boolean validateDefinitions)
Set whether to validate the Tiles XML definitions. Default is "true".


setDefinitionsFactoryClass

public void setDefinitionsFactoryClass(java.lang.Class<? extends DefinitionsFactory> definitionsFactoryClass)
Set the org.apache.tiles.definition.DefinitionsFactory implementation to use. Default is org.apache.tiles.definition.UrlDefinitionsFactory, operating on definition resource URLs.

Specify a custom DefinitionsFactory, e.g. a UrlDefinitionsFactory subclass, to customize the creation of Tiles Definition objects. Note that such a DefinitionsFactory has to be able to handle URL source objects, unless you configure a different TilesContainerFactory.


setPreparerFactoryClass

public void setPreparerFactoryClass(java.lang.Class<? extends PreparerFactory> preparerFactoryClass)
Set the org.apache.tiles.preparer.PreparerFactory implementation to use. Default is org.apache.tiles.preparer.BasicPreparerFactory, creating shared instances for specified preparer classes.

Specify SimpleSpringPreparerFactory to autowire org.apache.tiles.preparer.ViewPreparer instances based on specified preparer classes, applying Spring's container callbacks as well as applying configured Spring BeanPostProcessors. If Spring's context-wide annotation-config has been activated, annotations in ViewPreparer classes will be automatically detected and applied.

Specify SpringBeanPreparerFactory to operate on specified preparer names instead of classes, obtaining the corresponding Spring bean from the DispatcherServlet's application context. The full bean creation process will be in the control of the Spring application context in this case, allowing for the use of scoped beans etc. Note that you need to define one Spring bean definition per preparer name (as used in your Tiles definitions).

See Also:
SimpleSpringPreparerFactory, SpringBeanPreparerFactory

setUseMutableTilesContainer

public void setUseMutableTilesContainer(boolean useMutableTilesContainer)
Set whether to use a MutableTilesContainer (typically the CachingTilesContainer implementation) for this application. Default is "false".

See Also:
org.apache.tiles.mgmt.MutableTilesContainer, org.apache.tiles.mgmt.CachingTilesContainer

setTilesProperties

public void setTilesProperties(java.util.Properties tilesProperties)
Set Tiles properties (equivalent to the ServletContext init-params in the Tiles documentation), overriding the default settings.

NOTE: This property is only effective with Tiles 2.1. Tiles 2.2 doesn't support property-based configuration anymore.


setServletContext

public void setServletContext(ServletContext servletContext)
Description copied from interface: ServletContextAware
Set the ServletContext that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.

Specified by:
setServletContext in interface ServletContextAware
Parameters:
servletContext - ServletContext object to be used by this object
See Also:
InitializingBean.afterPropertiesSet(), ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)

afterPropertiesSet

public void afterPropertiesSet()
                        throws TilesException
Creates and exposes a TilesContainer for this web application, delegating to the TilesInitializer.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
TilesException - in case of setup failure
See Also:
createTilesInitializer()

createTilesInitializer

protected TilesInitializer createTilesInitializer()
Creates a new instance of org.apache.tiles.startup.BasicTilesInitializer.

Override it to use a different initializer.

See Also:
org.apache.tiles.web.startup.TilesListener#createTilesInitializer()

destroy

public void destroy()
             throws TilesException
Removes the TilesContainer from this web application.

Specified by:
destroy in interface DisposableBean
Throws:
TilesException - in case of cleanup failure