Package org.shredzone.commons.view.impl
Class ViewServiceImpl
- java.lang.Object
-
- org.shredzone.commons.view.impl.ViewServiceImpl
-
- All Implemented Interfaces:
ViewService
@Component @ParametersAreNonnullByDefault public class ViewServiceImpl extends Object implements ViewService
Default implementation ofViewService
.- Author:
- Richard "Shred" Körber
-
-
Constructor Summary
Constructors Constructor Description ViewServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
buildPath(PathContext data, String view, PathType type)
Builds an URL path to a view that is able to render the provided data.protected org.springframework.expression.EvaluationContext
createEvaluationContext(PathContext context)
Creates anEvaluationContext
to be used for evaluation in this view service.String
getTemplatePath(String template)
Gets the path to a template resource with the given name.ViewContext
getViewContext()
Gets theViewContext
of the current request.void
handleRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
Handles a HTTP request.String
invokeView(String path)
Analyzes the given path, and invokes a view handler for processing the request.protected void
setup()
-
-
-
Constructor Detail
-
ViewServiceImpl
public ViewServiceImpl()
-
-
Method Detail
-
setup
@PostConstruct protected void setup()
-
handleRequest
public void handleRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws ViewException
Description copied from interface:ViewService
Handles a HTTP request. This method is usually invoked from a servlet.- Specified by:
handleRequest
in interfaceViewService
- Parameters:
req
-HttpServletRequest
resp
-HttpServletResponse
- Throws:
ViewException
- if the request could not be handled
-
getViewContext
public ViewContext getViewContext()
Description copied from interface:ViewService
Gets theViewContext
of the current request.- Specified by:
getViewContext
in interfaceViewService
- Returns:
ViewContext
-
invokeView
public String invokeView(String path) throws ViewException
Description copied from interface:ViewService
Analyzes the given path, and invokes a view handler for processing the request.- Specified by:
invokeView
in interfaceViewService
- Parameters:
path
- the requested path- Returns:
- String returned by the view handler, usually the name of a JSP template to
forward the request to. May be
null
if the handler already took care for the response itself. - Throws:
PageNotFoundException
- if no view was matching the given pathViewException
- if the view handler could not be invoked or could not handle the request
-
buildPath
public String buildPath(PathContext data, String view, PathType type)
Description copied from interface:ViewService
Builds an URL path to a view that is able to render the provided data.- Specified by:
buildPath
in interfaceViewService
- Parameters:
data
-PathContext
containing all the data for the pathview
- name of the view to build a path totype
-PathType
to be built- Returns:
- the URL path that was built, or
null
if no view was found to be able to render the provided data
-
getTemplatePath
public String getTemplatePath(String template)
Description copied from interface:ViewService
Gets the path to a template resource with the given name. It is not checked if the template actually exists.- Specified by:
getTemplatePath
in interfaceViewService
- Parameters:
template
- Template name- Returns:
- Template path
-
createEvaluationContext
@Nonnull protected org.springframework.expression.EvaluationContext createEvaluationContext(PathContext context)
Creates anEvaluationContext
to be used for evaluation in this view service. The default implementation creates aViewPathEvaluationContext
.- Parameters:
context
-PathContext
to be used as root object- Returns:
EvaluationContext
to be used for evaluation
-
-