net.sourceforge.xconf.toolbox.spring.mvc
Class URITemplateHandlerMapping

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 net.sourceforge.xconf.toolbox.spring.mvc.URITemplateHandlerMapping
All Implemented Interfaces:
ApplicationContextAware, Ordered, ServletContextAware, HandlerMapping

public class URITemplateHandlerMapping
extends AbstractHandlerMapping

HandlerMapping implementation to match URITemplate patterns.

See Also:
URITemplate

Field Summary
static String PARAMETERS_ATTRIBUTE
          Request attribute key used to retrieve parameter map parsed from the current request's path.
static String TEMPLATE_ATTRIBUTE
          Request attribute key used to retrieve the URITemplate that matched the current request.
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
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
URITemplateHandlerMapping()
           
 
Method Summary
protected  void exposeTemplateAndParameters(String lookupPath, URITemplate template, HttpServletRequest request)
          Expose the path within the current mapping, the template used to match the path, and the parameters parsed from the path as request attributes.
protected  Object getHandlerInternal(HttpServletRequest request)
          Look up a handler for the URL path of the given request.
 void setAlwaysUseFullPath(boolean alwaysUseFullPath)
          Set if URL lookup should always use the full path within the current servlet context.
 void setMappings(Map<String,String> mappings)
          Map URL paths to handler bean names.
 void setMappings(Properties mappings)
          Map URL paths to handler bean names.
 void setUrlDecode(boolean urlDecode)
          Set if context path and request URI should be URL-decoded.
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
adaptInterceptor, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, initApplicationContext, initInterceptors, setDefaultHandler, setInterceptors, setOrder
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, 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
 

Field Detail

TEMPLATE_ATTRIBUTE

public static final String TEMPLATE_ATTRIBUTE
Request attribute key used to retrieve the URITemplate that matched the current request.

See Also:
URITemplate.matches(String), exposeTemplateAndParameters(String, net.sourceforge.xconf.toolbox.web.URITemplate, javax.servlet.http.HttpServletRequest)

PARAMETERS_ATTRIBUTE

public static final String PARAMETERS_ATTRIBUTE
Request attribute key used to retrieve parameter map parsed from the current request's path.

See Also:
URITemplate.parse(String), exposeTemplateAndParameters(String, net.sourceforge.xconf.toolbox.web.URITemplate, javax.servlet.http.HttpServletRequest)
Constructor Detail

URITemplateHandlerMapping

public URITemplateHandlerMapping()
Method Detail

setAlwaysUseFullPath

public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Set if URL lookup should always use the full path within the current servlet context. Else, the path within the current servlet mapping is used if applicable (that is, in the case of a ".../*" servlet mapping in web.xml).

Default is "false".

See Also:
UrlPathHelper.setAlwaysUseFullPath(boolean)

setUrlDecode

public void setUrlDecode(boolean urlDecode)
Set if context path and request URI should be URL-decoded. Both are returned undecoded by the Servlet API, in contrast to the servlet path.

Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).

Note: Setting this to "true" requires JDK 1.4 if the encoding differs from the VM's platform default encoding, as JDK 1.3's URLDecoder class does not offer a way to specify the encoding.

See Also:
UrlPathHelper.setUrlDecode(boolean)

setMappings

public void setMappings(Properties mappings)
Map URL paths to handler bean names. This is the typical way of configuring this HandlerMapping.

Parameters:
mappings - properties with URLs as keys and bean names as values

setMappings

public void setMappings(Map<String,String> mappings)
Map URL paths to handler bean names. This is the typical way of configuring this HandlerMapping.

Parameters:
mappings - map with URLs as keys and bean names as values

getHandlerInternal

protected Object getHandlerInternal(HttpServletRequest request)
                             throws Exception
Look up a handler for the URL path of the given request.

Specified by:
getHandlerInternal in class AbstractHandlerMapping
Parameters:
request - current HTTP request
Returns:
the handler instance, or null if none found
Throws:
Exception

exposeTemplateAndParameters

protected void exposeTemplateAndParameters(String lookupPath,
                                           URITemplate template,
                                           HttpServletRequest request)
Expose the path within the current mapping, the template used to match the path, and the parameters parsed from the path as request attributes.

Parameters:
lookupPath - the path used to lookup a handler mapping
template - the template that matched the lookup path
request - the request to expose the path, template and parameters to
See Also:
HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PARAMETERS_ATTRIBUTE, TEMPLATE_ATTRIBUTE, URITemplate.parse(String)


Copyright © 2007 Thomas Czarniecki. All Rights Reserved.