Spring Framework

org.springframework.web.servlet.mvc
Class UrlFilenameViewController

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.support.WebContentGenerator
              extended by org.springframework.web.servlet.mvc.AbstractController
                  extended by org.springframework.web.servlet.mvc.AbstractUrlViewController
                      extended by org.springframework.web.servlet.mvc.UrlFilenameViewController
All Implemented Interfaces:
Aware, ApplicationContextAware, ServletContextAware, Controller

public class UrlFilenameViewController
extends AbstractUrlViewController

Simple Controller implementation that transforms the virtual path of a URL into a view name and returns that view.

Can optionally prepend a prefix and/or append a suffix to build the viewname from the URL filename.

Find below some examples:

  1. "/index" -> "index"
  2. "/index.html" -> "index"
  3. "/index.html" + prefix "pre_" and suffix "_suf" -> "pre_index_suf"
  4. "/products/view.html" -> "products/view"

Thanks to David Barri for suggesting prefix/suffix support!

Author:
Alef Arendsen, Juergen Hoeller, Rob Harrop
See Also:
setPrefix(java.lang.String), setSuffix(java.lang.String)

Field Summary
 
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator
METHOD_GET, METHOD_HEAD, METHOD_POST
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
UrlFilenameViewController()
           
 
Method Summary
protected  java.lang.String extractOperableUrl(javax.servlet.http.HttpServletRequest request)
          Extract a URL path from the given request, suitable for view name extraction.
protected  java.lang.String extractViewNameFromUrlPath(java.lang.String uri)
          Extract the URL filename from the given request URI.
protected  java.lang.String getPrefix()
          Return the prefix to prepend to the request URL filename.
protected  java.lang.String getSuffix()
          Return the suffix to append to the request URL filename.
protected  java.lang.String getViewNameForRequest(javax.servlet.http.HttpServletRequest request)
          Returns view name based on the URL filename, with prefix/suffix applied when appropriate.
protected  java.lang.String getViewNameForUrlPath(java.lang.String uri)
          Returns view name based on the URL filename, with prefix/suffix applied when appropriate.
protected  java.lang.String postProcessViewName(java.lang.String viewName)
          Build the full view name based on the given view name as indicated by the URL path.
 void setPrefix(java.lang.String prefix)
          Set the prefix to prepend to the request URL filename to build a view name.
 void setSuffix(java.lang.String suffix)
          Set the suffix to append to the request URL filename to build a view name.
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractUrlViewController
getUrlPathHelper, handleRequestInternal, setAlwaysUseFullPath, setUrlDecode, setUrlPathHelper
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
 
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader
 
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, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UrlFilenameViewController

public UrlFilenameViewController()
Method Detail

setPrefix

public void setPrefix(java.lang.String prefix)
Set the prefix to prepend to the request URL filename to build a view name.


getPrefix

protected java.lang.String getPrefix()
Return the prefix to prepend to the request URL filename.


setSuffix

public void setSuffix(java.lang.String suffix)
Set the suffix to append to the request URL filename to build a view name.


getSuffix

protected java.lang.String getSuffix()
Return the suffix to append to the request URL filename.


getViewNameForRequest

protected java.lang.String getViewNameForRequest(javax.servlet.http.HttpServletRequest request)
Returns view name based on the URL filename, with prefix/suffix applied when appropriate.

Specified by:
getViewNameForRequest in class AbstractUrlViewController
Parameters:
request - current HTTP request
Returns:
a view name for this request (never null)
See Also:
extractViewNameFromUrlPath(java.lang.String), setPrefix(java.lang.String), setSuffix(java.lang.String)

extractOperableUrl

protected java.lang.String extractOperableUrl(javax.servlet.http.HttpServletRequest request)
Extract a URL path from the given request, suitable for view name extraction.

Parameters:
request - current HTTP request
Returns:
the URL to use for view name extraction

getViewNameForUrlPath

protected java.lang.String getViewNameForUrlPath(java.lang.String uri)
Returns view name based on the URL filename, with prefix/suffix applied when appropriate.

Parameters:
uri - the request URI; for example "/index.html"
Returns:
the extracted URI filename; for example "index"
See Also:
extractViewNameFromUrlPath(java.lang.String), postProcessViewName(java.lang.String)

extractViewNameFromUrlPath

protected java.lang.String extractViewNameFromUrlPath(java.lang.String uri)
Extract the URL filename from the given request URI.

Parameters:
uri - the request URI; for example "/index.html"
Returns:
the extracted URI filename; for example "index"

postProcessViewName

protected java.lang.String postProcessViewName(java.lang.String viewName)
Build the full view name based on the given view name as indicated by the URL path.

The default implementation simply applies prefix and suffix. This can be overridden, for example, to manipulate upper case / lower case, etc.

Parameters:
viewName - the original view name, as indicated by the URL path
Returns:
the full view name to use
See Also:
getPrefix(), getSuffix()

Spring Framework