Package org.shredzone.commons.view
Interface ViewService
-
- All Known Implementing Classes:
ViewServiceImpl
@ParametersAreNonnullByDefault public interface ViewService
Service for rendering views, creating links to views, and handling servlet requests.Note: A servlet delegates a request to
handleRequest(HttpServletRequest, HttpServletResponse). The other methods are request scoped and must only be invoked from the same thread that invokedhandleRequest().- Author:
- Richard "Shred" Körber
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description StringbuildPath(PathContext context, String view, PathType type)Builds an URL path to a view that is able to render the provided data.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.
-
-
-
Method Detail
-
handleRequest
void handleRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws ViewException
Handles a HTTP request. This method is usually invoked from a servlet.- Parameters:
req-HttpServletRequestresp-HttpServletResponse- Throws:
ViewException- if the request could not be handled
-
getViewContext
ViewContext getViewContext()
Gets theViewContextof the current request.- Returns:
ViewContext
-
buildPath
String buildPath(PathContext context, String view, PathType type)
Builds an URL path to a view that is able to render the provided data.- Parameters:
context-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
-
invokeView
String invokeView(String path) throws ViewException
Analyzes the given path, and invokes a view handler for processing the request.- 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
-
getTemplatePath
@Nonnull String getTemplatePath(String template)
Gets the path to a template resource with the given name. It is not checked if the template actually exists.- Parameters:
template- Template name- Returns:
- Template path
-
-