01: package com.opensymphony.sitemesh.compatability;
02:
03: import com.opensymphony.sitemesh.Content;
04: import com.opensymphony.sitemesh.webapp.SiteMeshWebAppContext;
05: import com.opensymphony.sitemesh.webapp.decorator.BaseWebAppDecorator;
06: import com.opensymphony.module.sitemesh.RequestConstants;
07:
08: import javax.servlet.RequestDispatcher;
09: import javax.servlet.ServletContext;
10: import javax.servlet.ServletException;
11: import javax.servlet.http.HttpServletRequest;
12: import javax.servlet.http.HttpServletResponse;
13: import java.io.IOException;
14:
15: /**
16: * Adapts a SiteMesh 2 {@link com.opensymphony.module.sitemesh.Decorator} to a
17: * SiteMesh 3 {@link com.opensymphony.sitemesh.Decorator}.
18: *
19: * @author Joe Walnes
20: * @since SiteMesh 3
21: */
22: public class OldDecorator2NewDecorator extends BaseWebAppDecorator
23: implements RequestConstants {
24:
25: private final com.opensymphony.module.sitemesh.Decorator oldDecorator;
26:
27: public OldDecorator2NewDecorator(
28: com.opensymphony.module.sitemesh.Decorator oldDecorator) {
29: this .oldDecorator = oldDecorator;
30: }
31:
32: protected void render(Content content, HttpServletRequest request,
33: HttpServletResponse response,
34: ServletContext servletContext,
35: SiteMeshWebAppContext webAppContext) throws IOException,
36: ServletException {
37:
38: request.setAttribute(PAGE, new Content2HTMLPage(content));
39:
40: // see if the URI path (webapp) is set
41: if (oldDecorator.getURIPath() != null) {
42: // in a security conscious environment, the servlet container
43: // may return null for a given URL
44: if (servletContext.getContext(oldDecorator.getURIPath()) != null) {
45: servletContext = servletContext.getContext(oldDecorator
46: .getURIPath());
47: }
48: }
49: // get the dispatcher for the decorator
50: RequestDispatcher dispatcher = servletContext
51: .getRequestDispatcher(oldDecorator.getPage());
52: dispatcher.include(request, response);
53:
54: request.removeAttribute(PAGE);
55: }
56:
57: }
|