Package org.shredzone.commons.view.impl
Class ViewContextImpl
- java.lang.Object
-
- org.shredzone.commons.view.impl.ViewContextImpl
-
- All Implemented Interfaces:
ViewContext
@Component("viewContext") @Scope("request") @ParametersAreNonnullByDefault public class ViewContextImpl extends Object implements ViewContext
Default implementation ofViewContext
.This bean is request scoped.
- Author:
- Richard "Shred" Körber
-
-
Constructor Summary
Constructors Constructor Description ViewContextImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getParameter(String name)
Gets a parameter from the request URL's search part.Map<String,String>
getPathParts()
Gets a map of all path parts.String
getQualifier()
Gets a View qualifier.String
getRequestServerUrl()
Returns the server URL the request was sent to.String
getRequestServletName()
Returns the name of the servlet that processed the request.<T> T
getValueOfType(Class<T> type)
Gets a value that matches the requested type.<T> void
putTypedArgument(Class<T> type, T value)
Adds a typed argument to this context.void
setPathParts(Map<String,String> pathParts)
Sets the path parts from resolving the view URL.void
setQualifier(String qualifier)
Sets a View qualifier.protected void
setup()
Sets up this bean's contents.
-
-
-
Constructor Detail
-
ViewContextImpl
public ViewContextImpl()
-
-
Method Detail
-
setup
@PostConstruct protected void setup()
Sets up this bean's contents.
-
getRequestServerUrl
public String getRequestServerUrl()
Description copied from interface:ViewContext
Returns the server URL the request was sent to. The URL contains the protocol, the domain and (optionally) the port.- Specified by:
getRequestServerUrl
in interfaceViewContext
- Returns:
- the server URL (e.g. "http://www.shredzone.de")
-
getRequestServletName
public String getRequestServletName()
Description copied from interface:ViewContext
Returns the name of the servlet that processed the request.- Specified by:
getRequestServletName
in interfaceViewContext
- Returns:
- the servlet name (e.g. "/cilla")
-
getParameter
public String getParameter(String name)
Description copied from interface:ViewContext
Gets a parameter from the request URL's search part.- Specified by:
getParameter
in interfaceViewContext
- Parameters:
name
- the parameter name- Returns:
- parameter value, or
null
if there is no such parameter
-
putTypedArgument
public <T> void putTypedArgument(Class<T> type, T value)
Description copied from interface:ViewContext
Adds a typed argument to this context. Typed arguments are available to the view handler's parameter list.- Specified by:
putTypedArgument
in interfaceViewContext
- Parameters:
type
- Type this argument is to be registered with (may be the value's type or a supertype)value
- the value to register, may benull
-
getValueOfType
public <T> T getValueOfType(Class<T> type) throws ViewContextException
Description copied from interface:ViewContext
Gets a value that matches the requested type.- Specified by:
getValueOfType
in interfaceViewContext
- Type Parameters:
T
- the requested type- Parameters:
type
- type to get a value for- Returns:
- a value for that type, may be
null
if the type's value was set tonull
. - Throws:
ViewContextException
- if there was no data satisfying that type
-
setPathParts
public void setPathParts(Map<String,String> pathParts)
Description copied from interface:ViewContext
Sets the path parts from resolving the view URL. Should only be invoked from theViewService
.- Specified by:
setPathParts
in interfaceViewContext
- Parameters:
pathParts
- Map of path parts
-
getPathParts
public Map<String,String> getPathParts()
Description copied from interface:ViewContext
Gets a map of all path parts. This map is immutable.- Specified by:
getPathParts
in interfaceViewContext
- Returns:
- Map of path parts
-
setQualifier
public void setQualifier(String qualifier)
Description copied from interface:ViewContext
Sets a View qualifier.- Specified by:
setQualifier
in interfaceViewContext
- Parameters:
qualifier
- qualifier to be used, ornull
for the standard qualifier
-
getQualifier
public String getQualifier()
Description copied from interface:ViewContext
Gets a View qualifier.- Specified by:
getQualifier
in interfaceViewContext
- Returns:
- qualifier to be used, or
null
for the standard qualifier
-
-