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.SportletProperties;
06: import org.gridsphere.portlet.impl.StoredPortletResponseImpl;
07: import org.gridsphere.provider.portletui.beans.ActionComponentBean;
08:
09: import javax.servlet.RequestDispatcher;
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.PageContext;
15:
16: /*
17: * @author <a href="mailto:russell@aei.mpg.de">Michael Russell</a>
18: * @version $Id: ActionComponentTag.java 6407 2008-01-16 15:20:21Z wehrens $
19: * <p>
20: * Includes jsp pages from any web application.
21: */
22:
23: public class ActionComponentTag extends IncludeTag {
24:
25: private Log log = LogFactory.getLog(ActionComponentTag.class);
26: private String activeCompId = "";
27:
28: protected String getActiveComponentId() {
29: return activeCompId;
30: }
31:
32: protected void setActionComponentId(String compId) {
33: this .activeCompId = compId;
34: }
35:
36: protected void includePage() {
37: //log.debug("includePage(" + page + ")");
38:
39: RequestDispatcher rd = servletContext
40: .getRequestDispatcher(page);
41: ServletRequest request = pageContext.getRequest();
42: ServletResponse response = pageContext.getResponse();
43:
44: String baseCompId = (String) pageContext
45: .findAttribute(SportletProperties.GP_COMPONENT_ID);
46:
47: if (includeBean != null) {
48: //log.debug("Using active component id ");
49: activeCompId = ((ActionComponentBean) includeBean)
50: .getActiveComponentId();
51: } else {
52: //log.debug("Using request component id ");
53: activeCompId = (String) pageContext
54: .findAttribute(SportletProperties.GP_COMPONENT_ID);
55: }
56:
57: //log.debug("Changing component id from " + baseCompId + " to " + activeCompId);
58: pageContext.setAttribute(SportletProperties.GP_COMPONENT_ID,
59: activeCompId, PageContext.REQUEST_SCOPE);
60:
61: // Include message box tag automagically
62: MessageBoxTag messageBoxTag = new MessageBoxTag();
63: messageBoxTag.setBeanId("messageBox");
64: messageBoxTag.setPageContext(pageContext);
65: try {
66: messageBoxTag.doEndTag();
67: } catch (Exception e) {
68: log.error("Unable to include message box bean ", e);
69: }
70:
71: try {
72:
73: // Very important here... must pass it the appropriate jsp writer!!!
74: // Or else this include won't be contained within the parent content
75: // but either before or after it.
76: //rd.include(request, new ServletResponseWrapperInclude(response, pageContext.getOut()));
77: rd.include(request, new StoredPortletResponseImpl(
78: (HttpServletRequest) request,
79: (HttpServletResponse) response, pageContext
80: .getOut()));
81: //rd.include(pageContext.getRequest(), pageContext.getResponse());
82: } catch (Exception e) {
83: log.error("Unable to include page ", e);
84: }
85: //log.debug("Resetting component id to " + baseCompId);
86: pageContext.setAttribute(SportletProperties.GP_COMPONENT_ID,
87: baseCompId, PageContext.REQUEST_SCOPE);
88: }
89: }
|