org.riotfamily.common.web.mapping
Class AdvancedBeanNameHandlerMapping

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.handler.AbstractHandlerMapping
              extended by org.riotfamily.common.web.mapping.AbstractReverseHandlerMapping
                  extended by org.riotfamily.common.web.mapping.AdvancedBeanNameHandlerMapping
All Implemented Interfaces:
ReverseHandlerMapping, ApplicationContextAware, Ordered, ServletContextAware, HandlerMapping
Direct Known Subclasses:
SiteBeanNameHandlerMapping

public class AdvancedBeanNameHandlerMapping
extends AbstractReverseHandlerMapping

HandlerMapping that works like Spring's BeanNameUrlHandlerMapping and can expose parts of the matched URL as request attributes.

The handler name /foo/bar/@{some}/@{value} would be equivalent to /foo/bar/*/*, the last two wildcards would be exposed as attributes "some" and "value".


Field Summary
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Fields inherited from interface org.riotfamily.common.web.mapping.ReverseHandlerMapping
TOP_LEVEL_HANDLER_NAME_ATTRIBUTE
 
Fields inherited from interface org.springframework.web.servlet.HandlerMapping
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
AdvancedBeanNameHandlerMapping()
           
 
Method Summary
protected  String addServletMappingIfNecessary(String path, HttpServletRequest request)
           
 Object getHandlerInternal(HttpServletRequest request)
          Look up a handler for the given request, falling back to the default handler if no specific one is found.
protected  String getLookupPath(HttpServletRequest request)
           
protected  List<AttributePattern> getPatternsForHandler(String beanName, UrlResolverContext context)
          Subclasses must implement this method and return all patterns for the handler with the specified name.
protected  Object getRootHandler()
          Return the root handler for this handler mapping (registered for "/"), or null if none.
 void initApplicationContext()
          Copied from BeanNameUrlHandlerMapping
protected  boolean isMapping(String beanName)
           
protected  boolean isStripServletMapping()
           
protected  Object lookupHandler(String urlPath, HttpServletRequest request)
          Look up a handler instance for the given URL path.
 void setLazyInitHandlers(boolean lazyInitHandlers)
          Set whether to lazily initialize handlers.
 void setRootHandler(Object rootHandler)
          Set the root handler for this handler mapping, that is, the handler to be registered for the root path ("/").
 void setStripServletMapping(boolean stripServletMapping)
           
 
Methods inherited from class org.riotfamily.common.web.mapping.AbstractReverseHandlerMapping
addServletMappingIfNecessary, exposeHandlerName, getDefaults, getPatternForHandler, getPatternForHandler, getPatternsForHandler, getUrlForHandler, getUrlForHandler, getWildcardAttributes
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, initInterceptors, setDefaultHandler, setInterceptors, setOrder
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdvancedBeanNameHandlerMapping

public AdvancedBeanNameHandlerMapping()
Method Detail

setStripServletMapping

public final void setStripServletMapping(boolean stripServletMapping)

isStripServletMapping

protected final boolean isStripServletMapping()

setRootHandler

public final void setRootHandler(Object rootHandler)
Set the root handler for this handler mapping, that is, the handler to be registered for the root path ("/").

Default is null, indicating no root handler.


getRootHandler

protected final Object getRootHandler()
Return the root handler for this handler mapping (registered for "/"), or null if none.


setLazyInitHandlers

public void setLazyInitHandlers(boolean lazyInitHandlers)
Set whether to lazily initialize handlers. Only applicable to singleton handlers, as prototypes are always lazily initialized. Default is "false", as eager initialization allows for more efficiency through referencing the controller objects directly.

If you want to allow your controllers to be lazily initialized, make them "lazy-init" and set this flag to true. Just making them "lazy-init" will not work, as they are initialized through the references from the handler mapping in this case.


initApplicationContext

public void initApplicationContext()
                            throws ApplicationContextException
Copied from BeanNameUrlHandlerMapping

Overrides:
initApplicationContext in class AbstractHandlerMapping
Throws:
ApplicationContextException

isMapping

protected boolean isMapping(String beanName)

getLookupPath

protected String getLookupPath(HttpServletRequest request)

getHandlerInternal

public Object getHandlerInternal(HttpServletRequest request)
                          throws Exception
Look up a handler for the given request, falling back to the default handler if no specific one is found.

Specified by:
getHandlerInternal in class AbstractHandlerMapping
Parameters:
request - current HTTP request
Returns:
the looked up handler instance, or the default handler
Throws:
Exception

lookupHandler

protected Object lookupHandler(String urlPath,
                               HttpServletRequest request)
Look up a handler instance for the given URL path.

Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.

Looks for the most exact pattern, where most exact is defined as the longest path pattern.

Copied from AbstractUrlHandlerMapping

Parameters:
urlPath - URL the bean is mapped to
Returns:
the associated handler instance, or null if not found
See Also:
AntPathMatcher

addServletMappingIfNecessary

protected String addServletMappingIfNecessary(String path,
                                              HttpServletRequest request)

getPatternsForHandler

protected List<AttributePattern> getPatternsForHandler(String beanName,
                                                       UrlResolverContext context)
Description copied from class: AbstractReverseHandlerMapping
Subclasses must implement this method and return all patterns for the handler with the specified name.

Specified by:
getPatternsForHandler in class AbstractReverseHandlerMapping