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 StringbuildPath(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.EvaluationContextcreateEvaluationContext(PathContext context)Creates anEvaluationContextto be used for evaluation in this view service.StringgetTemplatePath(String template)Gets the path to a template resource with the given name.ViewContextgetViewContext()Gets theViewContextof the current request.voidhandleRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)Handles a HTTP request.StringinvokeView(String path)Analyzes the given path, and invokes a view handler for processing the request.protected voidsetup()
-
-
-
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:ViewServiceHandles a HTTP request. This method is usually invoked from a servlet.- Specified by:
handleRequestin interfaceViewService- Parameters:
req-HttpServletRequestresp-HttpServletResponse- Throws:
ViewException- if the request could not be handled
-
getViewContext
public ViewContext getViewContext()
Description copied from interface:ViewServiceGets theViewContextof the current request.- Specified by:
getViewContextin interfaceViewService- Returns:
ViewContext
-
invokeView
public String invokeView(String path) throws ViewException
Description copied from interface:ViewServiceAnalyzes the given path, and invokes a view handler for processing the request.- Specified by:
invokeViewin 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
nullif 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:ViewServiceBuilds an URL path to a view that is able to render the provided data.- Specified by:
buildPathin interfaceViewService- Parameters:
data-PathContextcontaining all the data for the pathview- name of the view to build a path totype-PathTypeto be built- Returns:
- the URL path that was built, or
nullif no view was found to be able to render the provided data
-
getTemplatePath
public String getTemplatePath(String template)
Description copied from interface:ViewServiceGets the path to a template resource with the given name. It is not checked if the template actually exists.- Specified by:
getTemplatePathin interfaceViewService- Parameters:
template- Template name- Returns:
- Template path
-
createEvaluationContext
@Nonnull protected org.springframework.expression.EvaluationContext createEvaluationContext(PathContext context)
Creates anEvaluationContextto be used for evaluation in this view service. The default implementation creates aViewPathEvaluationContext.- Parameters:
context-PathContextto be used as root object- Returns:
EvaluationContextto be used for evaluation
-
-