public class

UrlFilenameViewController

extends AbstractUrlViewController
java.lang.Object
   ↳ org.springframework.context.support.ApplicationObjectSupport
     ↳ org.springframework.web.context.support.WebApplicationObjectSupport
       ↳ org.springframework.web.servlet.support.WebContentGenerator
         ↳ org.springframework.web.servlet.mvc.AbstractController
           ↳ org.springframework.web.servlet.mvc.AbstractUrlViewController
             ↳ org.springframework.web.servlet.mvc.UrlFilenameViewController

Class Overview

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!

Summary

[Expand]
Inherited Constants
From class org.springframework.web.servlet.support.WebContentGenerator
[Expand]
Inherited Fields
From class org.springframework.context.support.ApplicationObjectSupport
Public Constructors
UrlFilenameViewController()
Public Methods
void setPrefix(String prefix)
Set the prefix to prepend to the request URL filename to build a view name.
void setSuffix(String suffix)
Set the suffix to append to the request URL filename to build a view name.
Protected Methods
String extractOperableUrl(HttpServletRequest request)
Extract a URL path from the given request, suitable for view name extraction.
String extractViewNameFromUrlPath(String uri)
Extract the URL filename from the given request URI.
String getPrefix()
Return the prefix to prepend to the request URL filename.
String getSuffix()
Return the suffix to append to the request URL filename.
String getViewNameForRequest(HttpServletRequest request)
Returns view name based on the URL filename, with prefix/suffix applied when appropriate.
String getViewNameForUrlPath(String uri)
Returns view name based on the URL filename, with prefix/suffix applied when appropriate.
String postProcessViewName(String viewName)
Build the full view name based on the given view name as indicated by the URL path.
[Expand]
Inherited Methods
From class org.springframework.web.servlet.mvc.AbstractUrlViewController
From class org.springframework.web.servlet.mvc.AbstractController
From class org.springframework.web.servlet.support.WebContentGenerator
From class org.springframework.web.context.support.WebApplicationObjectSupport
From class org.springframework.context.support.ApplicationObjectSupport
From class java.lang.Object
From interface org.springframework.context.ApplicationContextAware
From interface org.springframework.web.context.ServletContextAware
From interface org.springframework.web.servlet.mvc.Controller

Public Constructors

public UrlFilenameViewController ()

Public Methods

public void setPrefix (String prefix)

Set the prefix to prepend to the request URL filename to build a view name.

public void setSuffix (String suffix)

Set the suffix to append to the request URL filename to build a view name.

Protected Methods

protected String extractOperableUrl (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

protected String extractViewNameFromUrlPath (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"

protected String getPrefix ()

Return the prefix to prepend to the request URL filename.

protected String getSuffix ()

Return the suffix to append to the request URL filename.

protected String getViewNameForRequest (HttpServletRequest request)

Returns view name based on the URL filename, with prefix/suffix applied when appropriate.

Parameters
request current HTTP request
Returns
  • a view name for this request (never null)

protected String getViewNameForUrlPath (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"

protected String postProcessViewName (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