1 9 package org.jboss.portal.bridge; 10 11 import java.io.IOException ; 12 import java.io.OutputStream ; 13 import java.io.PrintWriter ; 14 import java.util.Locale ; 15 16 import javax.portlet.RenderResponse; 17 import javax.portlet.PortletResponse; 18 import javax.servlet.ServletOutputStream ; 19 import javax.servlet.http.Cookie ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.jboss.portal.server.PortalResponse; 23 import org.jboss.portal.server.PortalRequest; 24 25 29 public class BridgeResponse implements HttpServletResponse 30 { 31 32 protected final PortalRequest preq; 33 protected final PortalResponse presp; 34 protected final PortletResponse resp; 35 protected final HttpServletResponse hresp; 36 37 protected ServletOutputStream sos; 38 39 public BridgeResponse(PortalRequest preq, PortalResponse presp, PortletResponse resp, HttpServletResponse hresp) 40 { 41 this.preq = preq; 42 this.presp = presp; 43 this.resp = resp; 44 this.hresp = hresp; 45 this.sos = null; 46 } 47 48 public String encodeRedirectURL(String s) 49 { 50 return null; 51 } 52 53 public String encodeRedirectUrl(String s) 54 { 55 return null; 56 } 57 58 public String getCharacterEncoding() 59 { 60 return "UTF-8"; 61 } 62 63 public void setBufferSize(int i) 64 { 65 if (resp instanceof RenderResponse) 66 { 67 ((RenderResponse)resp).setBufferSize(i); 68 } 69 else 70 { 71 throw new IllegalStateException ("setBufferSize called on non render response"); 72 } 73 } 74 75 public void flushBuffer() throws IOException 76 { 77 if (resp instanceof RenderResponse) 78 { 79 ((RenderResponse)resp).flushBuffer(); 80 } 81 else 82 { 83 throw new IllegalStateException ("flushBuffer called on non render response"); 84 } 85 } 86 87 public void resetBuffer() 88 { 89 if (resp instanceof RenderResponse) 90 { 91 ((RenderResponse)resp).resetBuffer(); 92 } 93 else 94 { 95 throw new IllegalStateException ("resetBuffer called on non render response"); 96 } 97 } 98 99 public void reset() 100 { 101 if (resp instanceof RenderResponse) 102 { 103 ((RenderResponse)resp).reset(); 104 } 105 else 106 { 107 throw new IllegalStateException ("reset called on non render response"); 108 } 109 } 110 111 public int getBufferSize() 112 { 113 if (resp instanceof RenderResponse) 114 { 115 return ((RenderResponse)resp).getBufferSize(); 116 } 117 throw new IllegalStateException ("getBufferSize called on non render response"); 118 } 119 120 public boolean isCommitted() 121 { 122 if (resp instanceof RenderResponse) 123 { 124 return ((RenderResponse)resp).isCommitted(); 125 } 126 throw new IllegalStateException ("isCommited called on non render response"); 127 } 128 129 public ServletOutputStream getOutputStream() throws IOException 130 { 131 if (sos == null) 132 { 133 if (resp instanceof RenderResponse) 134 { 135 sos = new ServletOutputStream () 136 { 137 private OutputStream out = ((RenderResponse)resp).getPortletOutputStream(); 138 public void write(byte b[], int off, int len) throws IOException 139 { 140 out.write(b, off, len); 141 } 142 public void write(byte b[]) throws IOException 143 { 144 out.write(b); 145 } 146 public void write(int b) throws IOException 147 { 148 out.write(b); 149 } 150 }; 151 } 152 else 153 { 154 throw new IllegalStateException ("getOutputStream called on non render response"); 155 } 156 } 157 return sos; 158 } 159 160 public PrintWriter getWriter() throws IOException 161 { 162 if (resp instanceof RenderResponse) 163 { 164 RenderResponse rresp = (RenderResponse)resp; 165 if (rresp.getContentType() == null) 166 { 167 rresp.setContentType("text/html"); 169 } 170 return rresp.getWriter(); 171 } 172 throw new IllegalStateException ("getWriter called on non render response"); 173 } 174 175 public String encodeURL(String s) 176 { 177 return hresp.encodeURL(s); 180 } 181 182 public String encodeUrl(String s) 183 { 184 return hresp.encodeURL(s); 185 } 186 187 189 public void setContentType(String mimeType) 190 { 191 if (resp instanceof RenderResponse) 192 { 193 ((RenderResponse)resp).setContentType(mimeType); 194 } 195 else 196 { 197 throw new IllegalStateException ("setContentType called on non render response"); 198 } 199 } 200 201 public void setContentLength(int i) 202 { 203 } 204 205 public void setLocale(Locale locale) 206 { 207 } 208 209 public void addCookie(Cookie cookie) 210 { 211 } 212 213 public void sendError(int i) throws IOException 214 { 215 } 216 217 public void sendError(int i, String s) throws IOException 218 { 219 } 220 221 public void sendRedirect(String s) throws IOException 222 { 223 } 224 225 public void setDateHeader(String s, long l) 226 { 227 } 228 229 public void addDateHeader(String s, long l) 230 { 231 } 232 233 public void setHeader(String s, String s1) 234 { 235 } 236 237 public void addHeader(String s, String s1) 238 { 239 } 240 241 public void setIntHeader(String s, int i) 242 { 243 } 244 245 public void addIntHeader(String s, int i) 246 { 247 } 248 249 public void setStatus(int i) 250 { 251 } 252 253 public void setStatus(int i, String s) 254 { 255 } 256 257 public boolean containsHeader(String s) 258 { 259 return false; 260 } 261 262 public Locale getLocale() 263 { 264 return preq.getLocale(); 265 } 266 267 public String getContentType() 268 { 269 throw new UnsupportedOperationException (); 270 } 271 272 public void setCharacterEncoding(String s) 273 { 274 throw new UnsupportedOperationException (); 275 } 276 } 277 278 | Popular Tags |