01: package com.sun.facelets;
02:
03: import java.io.IOException;
04:
05: import javax.faces.FacesException;
06: import javax.faces.application.ViewHandler;
07: import javax.faces.context.ExternalContext;
08: import javax.faces.context.FacesContext;
09: import javax.faces.context.ResponseWriter;
10: import javax.faces.render.RenderKit;
11: import javax.portlet.RenderRequest;
12: import javax.portlet.RenderResponse;
13:
14: /**
15: * ViewHandler implementation for Facelets used in Portlets
16: *
17: */
18: public class FaceletPortletViewHandler extends FaceletViewHandler {
19:
20: public FaceletPortletViewHandler(ViewHandler parent) {
21: super (parent);
22: }
23:
24: protected ResponseWriter createResponseWriter(FacesContext context)
25: throws IOException, FacesException {
26: ExternalContext extContext = context.getExternalContext();
27: RenderKit renderKit = context.getRenderKit();
28:
29: RenderRequest request = (RenderRequest) extContext.getRequest();
30: RenderResponse response = (RenderResponse) extContext
31: .getResponse();
32:
33: String contenttype = request.getResponseContentType();
34: if (contenttype == null) {
35: contenttype = "text/html";
36: }
37:
38: String encoding = response.getCharacterEncoding();
39: if (encoding == null) {
40: encoding = "ISO-8859-1";
41: }
42:
43: ResponseWriter writer = renderKit.createResponseWriter(
44: NullWriter.Instance, contenttype, encoding);
45:
46: contenttype = writer.getContentType();
47:
48: // apply them to the response
49: response.setContentType(contenttype);
50:
51: // Now, clone with the real writer
52: writer = writer.cloneWithWriter(response.getWriter());
53:
54: return writer;
55: }
56: }
|