public class DefaultRequestToViewNameTranslator extends Object implements RequestToViewNameTranslator
RequestToViewNameTranslator
that simply transforms the URI of
the incoming request into a view name.
Can be explicitly defined as the viewNameTranslator
bean in a
DispatcherServlet
context.
Otherwise, a plain default instance will be used.
The default transformation simply strips leading and trailing slashes
as well as the file extension of the URI, and returns the result as the
view name with the configured prefix
and a
suffix
added as appropriate.
The stripping of the leading slash and file extension can be disabled
using the stripLeadingSlash
and
stripExtension
properties, respectively.
Find below some examples of request to view name translation.
http://localhost:8080/gamecast/display.html
» display
http://localhost:8080/gamecast/displayShoppingCart.html
» displayShoppingCart
http://localhost:8080/gamecast/admin/index.html
» admin/index
RequestToViewNameTranslator
,
ViewResolver
Constructor and Description |
---|
DefaultRequestToViewNameTranslator() |
Modifier and Type | Method and Description |
---|---|
String |
getViewName(HttpServletRequest request)
Translates the request URI of the incoming
HttpServletRequest
into the view name based on the configured parameters. |
void |
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Deprecated.
as of 5.3, the path is resolved externally and obtained with
ServletRequestPathUtils.getCachedPathValue(ServletRequest) |
void |
setPrefix(String prefix)
Set the prefix to prepend to generated view names.
|
void |
setRemoveSemicolonContent(boolean removeSemicolonContent)
Deprecated.
as of 5.3, the path is resolved externally and obtained with
ServletRequestPathUtils.getCachedPathValue(ServletRequest) |
void |
setSeparator(String separator)
Set the value that will replace '
/ ' as the separator
in the view name. |
void |
setStripExtension(boolean stripExtension)
Set whether or not file extensions should be stripped from the URI when
generating the view name.
|
void |
setStripLeadingSlash(boolean stripLeadingSlash)
Set whether or not leading slashes should be stripped from the URI when
generating the view name.
|
void |
setStripTrailingSlash(boolean stripTrailingSlash)
Set whether or not trailing slashes should be stripped from the URI when
generating the view name.
|
void |
setSuffix(String suffix)
Set the suffix to append to generated view names.
|
void |
setUrlDecode(boolean urlDecode)
Deprecated.
as of 5.3, the path is resolved externally and obtained with
ServletRequestPathUtils.getCachedPathValue(ServletRequest) |
void |
setUrlPathHelper(UrlPathHelper urlPathHelper)
Deprecated.
as of 5.3, the path is resolved externally and obtained with
ServletRequestPathUtils.getCachedPathValue(ServletRequest) |
protected String |
transformPath(String lookupPath)
Transform the request URI (in the context of the webapp) stripping
slashes and extensions, and replacing the separator as required.
|
public void setPrefix(@Nullable String prefix)
prefix
- the prefix to prepend to generated view namespublic void setSuffix(@Nullable String suffix)
suffix
- the suffix to append to generated view namespublic void setSeparator(String separator)
/
' as the separator
in the view name. The default behavior simply leaves '/
'
as the separator.public void setStripLeadingSlash(boolean stripLeadingSlash)
public void setStripTrailingSlash(boolean stripTrailingSlash)
public void setStripExtension(boolean stripExtension)
@Deprecated public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
ServletRequestPathUtils.getCachedPathValue(ServletRequest)
UrlPathHelper
.@Deprecated public void setUrlDecode(boolean urlDecode)
ServletRequestPathUtils.getCachedPathValue(ServletRequest)
UrlPathHelper
.UrlPathHelper.setUrlDecode(boolean)
@Deprecated public void setRemoveSemicolonContent(boolean removeSemicolonContent)
ServletRequestPathUtils.getCachedPathValue(ServletRequest)
@Deprecated public void setUrlPathHelper(UrlPathHelper urlPathHelper)
ServletRequestPathUtils.getCachedPathValue(ServletRequest)
UrlPathHelper
to use for
the resolution of lookup paths.
Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple web components.
public String getViewName(HttpServletRequest request)
HttpServletRequest
into the view name based on the configured parameters.getViewName
in interface RequestToViewNameTranslator
request
- the incoming HttpServletRequest
providing
the context from which a view name is to be resolvednull
if no default foundIllegalArgumentException
- if neither a parsed RequestPath, nor a
String lookupPath have been resolved and cached as a request attribute.ServletRequestPathUtils.getCachedPath(ServletRequest)
,
transformPath(java.lang.String)
@Nullable protected String transformPath(String lookupPath)
lookupPath
- the lookup path for the current request,
as determined by the UrlPathHelper