1 9 package org.jboss.portal.core.servlet.jsp; 10 11 import java.io.IOException ; 12 import java.util.LinkedList ; 13 14 import javax.portlet.PortletRequest; 15 import javax.servlet.ServletConfig ; 16 import javax.servlet.ServletException ; 17 import javax.servlet.ServletRequest ; 18 import javax.servlet.ServletResponse ; 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 import javax.servlet.jsp.HttpJspPage ; 22 23 import org.jboss.logging.Logger; 24 import org.jboss.portal.common.context.Context; 25 import org.jboss.portal.common.context.NamedContext; 26 27 34 public abstract class PortalJsp 35 implements HttpJspPage 36 { 37 38 41 public static final String CTX_REQUEST = "org.jboss.portal.core.context"; 42 43 47 public static final ThreadLocal request = new ThreadLocal (); 48 49 52 public static final ThreadLocal contextStack = new ThreadLocal (); 53 54 57 public static Logger log = Logger.getLogger(PortalJsp.class); 58 59 private ServletConfig config; 60 61 67 abstract public void _jspService(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException , 68 IOException ; 69 70 75 public void jspInit() 76 { 77 } 78 79 84 public void jspDestroy() 85 { 86 } 87 88 93 public void init(ServletConfig config) throws ServletException 94 { 95 this.config = config; 96 jspInit(); 97 } 98 99 104 public ServletConfig getServletConfig() 105 { 106 return config; 107 } 108 109 115 public void service(ServletRequest request, ServletResponse response) throws ServletException , IOException 116 { 117 HttpServletRequest httpRequest = (HttpServletRequest ) request; 119 HttpServletResponse httpResponse = (HttpServletResponse ) response; 120 121 Object formerRequest = PortalJsp.request.get(); 123 Object formerContextStack = PortalJsp.contextStack.get(); 124 125 PortletRequest req = (PortletRequest) request.getAttribute("javax.portlet.request"); 127 Object obj = req.getAttribute(CTX_REQUEST); 128 129 LinkedList stack = new LinkedList (); 130 if (obj != null) 131 { 132 Context ctx = (Context) obj; 133 NamedContext namedCtx = new NamedContext("", ctx); 134 stack.addLast(namedCtx); 135 } 136 try 137 { 138 PortalJsp.request.set(httpRequest); 139 PortalJsp.contextStack.set(stack); 140 _jspService(httpRequest, httpResponse); 141 } 142 finally 143 { 144 PortalJsp.request.set(formerRequest); 145 PortalJsp.contextStack.set(formerContextStack); 146 } 147 148 } 149 150 155 public String getServletInfo() 156 { 157 return "JBoss JSP superclass"; 158 } 159 160 165 public void destroy() 166 { 167 jspDestroy(); 168 } 169 } | Popular Tags |