01: package org.gridsphere.provider.portletui.tags;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05: import org.gridsphere.portlet.impl.StoredPortletResponseImpl;
06: import org.gridsphere.provider.portletui.beans.IncludeBean;
07:
08: import javax.servlet.RequestDispatcher;
09: import javax.servlet.ServletContext;
10: import javax.servlet.ServletRequest;
11: import javax.servlet.ServletResponse;
12: import javax.servlet.http.HttpServletRequest;
13: import javax.servlet.http.HttpServletResponse;
14: import javax.servlet.jsp.JspException;
15:
16: /*
17: * @author <a href="mailto:russell@aei.mpg.de">Michael Russell</a>
18: * @version $Id: IncludeTag.java 6407 2008-01-16 15:20:21Z wehrens $
19: * <p>
20: * Includes jsp pages from any web application.
21: */
22:
23: public class IncludeTag extends BaseBeanTag {
24:
25: private Log log = LogFactory.getLog(IncludeTag.class);
26: protected IncludeBean includeBean = null;
27: protected ServletContext servletContext = null;
28: protected String page = null;
29:
30: public ServletContext getServletContext() {
31: return servletContext;
32: }
33:
34: public void setServletContext(ServletContext servletContext) {
35: this .servletContext = servletContext;
36: }
37:
38: public String getPage() {
39: return page;
40: }
41:
42: public void setPage(String page) {
43: this .page = page;
44: }
45:
46: public int doStartTag() throws JspException {
47: if (beanId.equals("")) {
48: // If no bean id, create new bean
49: includeBean = new IncludeBean();
50: if (servletContext == null) {
51: // If no servlet context provided, then provide this context
52: servletContext = pageContext.getServletContext();
53: }
54: } else {
55: // Else get bean with bean id
56: includeBean = (IncludeBean) getTagBean();
57: if (includeBean == null) {
58: // If no bean with given id, exit early
59: return SKIP_BODY;
60: }
61: if (includeBean.getServletContext() == null) {
62: // If no servlet context provided, then provide this context
63: servletContext = pageContext.getServletContext();
64: } else {
65: log.debug("Using include bean context");
66: servletContext = includeBean.getServletContext();
67: }
68: page = includeBean.getPage();
69: }
70: // Set portlet request and response attributes
71: //includeBean.setJspWriter(pageContext.getOut());
72:
73: includePage();
74: return SKIP_BODY;
75: }
76:
77: protected void includePage() {
78: RequestDispatcher rd = servletContext
79: .getRequestDispatcher(page);
80: try {
81: ServletRequest request = pageContext.getRequest();
82: ServletResponse response = pageContext.getResponse();
83: // Very important here... must pass it the appropriate jsp writer!!!
84: // Or else this include won't be contained within the parent content
85: // but either before or after it.
86: //rd.include(request, new ServletResponseWrapperInclude(response, pageContext.getOut()));
87: rd.include(request, new StoredPortletResponseImpl(
88: (HttpServletRequest) request,
89: (HttpServletResponse) response, pageContext
90: .getOut()));
91: //rd.include(pageContext.getRequest(), pageContext.getResponse());
92: } catch (Exception e) {
93: log.error("Unable to include page ", e);
94: }
95: }
96: }
|