Class DefaultRequestToViewNameTranslator
java.lang.Object
org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator
- All Implemented Interfaces:
- RequestToViewNameTranslator
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
- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptiongetViewName(HttpServletRequest request) Translates the request URI of the incomingHttpServletRequestinto the view name based on the configured parameters.voidSet the prefix to prepend to generated view names.voidsetSeparator(String separator) Set the value that will replace '/' as the separator in the view name.voidsetStripExtension(boolean stripExtension) Set whether file extensions should be stripped from the URI when generating the view name.voidsetStripLeadingSlash(boolean stripLeadingSlash) Set whether leading slashes should be stripped from the URI when generating the view name.voidsetStripTrailingSlash(boolean stripTrailingSlash) Set whether trailing slashes should be stripped from the URI when generating the view name.voidSet the suffix to append to generated view names.protected StringtransformPath(String lookupPath) Transform the request URI (in the context of the webapp) stripping slashes and extensions, and replacing the separator as required.
- 
Constructor Details- 
DefaultRequestToViewNameTranslatorpublic DefaultRequestToViewNameTranslator()
 
- 
- 
Method Details- 
setPrefixSet the prefix to prepend to generated view names.- Parameters:
- prefix- the prefix to prepend to generated view names
 
- 
setSuffixSet the suffix to append to generated view names.- Parameters:
- suffix- the suffix to append to generated view names
 
- 
setSeparatorSet the value that will replace '/' as the separator in the view name. The default behavior simply leaves '/' as the separator.
- 
setStripLeadingSlashpublic void setStripLeadingSlash(boolean stripLeadingSlash) Set whether leading slashes should be stripped from the URI when generating the view name. Default is "true".
- 
setStripTrailingSlashpublic void setStripTrailingSlash(boolean stripTrailingSlash) Set whether trailing slashes should be stripped from the URI when generating the view name. Default is "true".
- 
setStripExtensionpublic void setStripExtension(boolean stripExtension) Set whether file extensions should be stripped from the URI when generating the view name. Default is "true".
- 
getViewNameTranslates the request URI of the incomingHttpServletRequestinto the view name based on the configured parameters.- Specified by:
- getViewNamein interface- RequestToViewNameTranslator
- Parameters:
- request- the incoming- HttpServletRequestproviding the context from which a view name is to be resolved
- Returns:
- the view name, or nullif no default found
- Throws:
- IllegalArgumentException- if neither a parsed RequestPath, nor a String lookupPath have been resolved and cached as a request attribute.
- See Also:
 
- 
transformPathTransform the request URI (in the context of the webapp) stripping slashes and extensions, and replacing the separator as required.- Parameters:
- lookupPath- the lookup path for the current request, as determined by the UrlPathHelper
- Returns:
- the transformed path, with slashes and extensions stripped if desired
 
 
-