01: package com.opensymphony.sitemesh.webapp.decorator;
02:
03: import com.opensymphony.sitemesh.Content;
04: import com.opensymphony.sitemesh.Decorator;
05: import com.opensymphony.sitemesh.SiteMeshContext;
06: import com.opensymphony.sitemesh.webapp.SiteMeshWebAppContext;
07:
08: import javax.servlet.ServletContext;
09: import javax.servlet.ServletException;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12: import java.io.IOException;
13:
14: /**
15: * Convenient base class for all Java web-app based decorators that make use of the Servlet API.
16: *
17: * @author Joe Walnes
18: * @since SiteMesh 3.0
19: */
20: public abstract class BaseWebAppDecorator implements Decorator {
21:
22: /**
23: * More convenient version of {@link #render(com.opensymphony.sitemesh.Content, com.opensymphony.sitemesh.SiteMeshContext)}
24: * suited for Servlet API calls.
25: */
26: protected abstract void render(Content content,
27: HttpServletRequest request, HttpServletResponse response,
28: ServletContext servletContext,
29: SiteMeshWebAppContext webAppContext) throws IOException,
30: ServletException;
31:
32: public void render(Content content, SiteMeshContext context) {
33: SiteMeshWebAppContext webAppContext = (SiteMeshWebAppContext) context;
34: // TODO: content.setRequest(request);
35: try {
36: render(content, webAppContext.getRequest(), webAppContext
37: .getResponse(), webAppContext.getServletContext(),
38: webAppContext);
39: } catch (IOException e) {
40: // TODO: Decent exception handling
41: throw new RuntimeException(e.toString());
42: } catch (ServletException e) {
43: // TODO: Decent exception handling
44: throw new RuntimeException(e.toString());
45: }
46: }
47: }
|