1 9 package org.jboss.portal.bridge; 10 11 import org.apache.portals.bridges.common.ServletContextProvider; 12 import org.jboss.portal.server.PortalRequest; 13 import org.jboss.portal.server.PortalResponse; 14 15 import javax.servlet.ServletContext ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 import javax.portlet.GenericPortlet; 19 import javax.portlet.PortletRequest; 20 import javax.portlet.PortletResponse; 21 22 30 public class JBossServletContextProvider implements ServletContextProvider 31 { 32 33 private static final ThreadLocal local = new ThreadLocal (); 34 35 public static void set(BridgeInfo info) 36 { 37 local.set(info); 38 } 39 40 public static BridgeInfo get() 41 { 42 return (BridgeInfo)local.get(); 43 } 44 45 48 public ServletContext getServletContext(GenericPortlet genericPortlet) throws IllegalStateException 49 { 50 BridgeInfo info = ((BridgeInfo)local.get()); 51 if (info == null) 52 { 53 throw new IllegalStateException ("No bridge set"); 54 } 55 return info.ctx; 56 } 57 58 61 public HttpServletRequest getHttpServletRequest(GenericPortlet genericPortlet, PortletRequest portletRequest) throws IllegalStateException 62 { 63 BridgeInfo info = (BridgeInfo)JBossServletContextProvider.local.get(); 64 if (info == null) 65 { 66 throw new IllegalStateException ("No bridge set"); 67 } 68 if (info.breq == null) 69 { 70 init(info); 71 } 72 return info.breq; 73 } 74 75 78 public HttpServletResponse getHttpServletResponse(GenericPortlet genericPortlet, PortletResponse portletResponse) throws IllegalStateException 79 { 80 BridgeInfo info = (BridgeInfo)JBossServletContextProvider.local.get(); 81 if (info == null) 82 { 83 throw new IllegalStateException ("No bridge set"); 84 } 85 if (info.breq == null) 86 { 87 init(info); 88 } 89 return info.bresp; 90 } 91 92 95 private void init(BridgeInfo bridgeInfo) 96 { 97 PortletRequest rreq = (PortletRequest)bridgeInfo.hreq.getAttribute("javax.portlet.request"); 98 PortletResponse rresp = (PortletResponse)bridgeInfo.hreq.getAttribute("javax.portlet.response"); 99 bridgeInfo.breq = new BridgeRequest(bridgeInfo.preq, rreq, bridgeInfo.hreq); 100 bridgeInfo.bresp = new BridgeResponse(bridgeInfo.preq, bridgeInfo.presp, rresp, bridgeInfo.hresp); 101 } 102 103 public static class BridgeInfo 104 { 105 106 private final ServletContext ctx; 107 108 109 private final PortalRequest preq; 110 111 112 private final PortalResponse presp; 113 114 115 private final HttpServletRequest hreq; 116 117 118 private final HttpServletResponse hresp; 119 120 121 private BridgeRequest breq; 122 123 124 private BridgeResponse bresp; 125 126 public BridgeInfo(ServletContext ctx, PortalRequest preq, PortalResponse presp, HttpServletRequest hreq, HttpServletResponse hresp) 127 { 128 this.ctx = ctx; 129 this.preq = preq; 130 this.presp = presp; 131 this.hreq = hreq; 132 this.hresp = hresp; 133 this.breq = null; 134 this.bresp = null; 135 } 136 } 137 } 138 | Popular Tags |