}
protected ResponseWriter createResponseWriter(FacesContext context) throws IOException, FacesException
{
ExternalContext extContext = context.getExternalContext();
RenderKit renderKit = context.getRenderKit();
// Avoid a cryptic NullPointerException when the renderkit ID
// is incorrectly set
if (renderKit == null)
{
String id = context.getViewRoot().getRenderKitId();
throw new IllegalStateException("No render kit was available for id \"" + id + "\"");
}
ServletResponse response = (ServletResponse) extContext.getResponse();
// set the buffer for content
if (this.bufferSize != -1)
{
response.setBufferSize(this.bufferSize);
}
// get our content type
String contentType = (String) extContext.getRequestMap().get("facelets.ContentType");
// get the encoding
String encoding = (String) extContext.getRequestMap().get("facelets.Encoding");
ResponseWriter writer;
// append */* to the contentType so createResponseWriter will succeed no matter
// the requested contentType.
if (contentType != null && !contentType.equals("*/*"))
{
contentType += ",*/*";
}
// Create a dummy ResponseWriter with a bogus writer,
// so we can figure out what content type the ReponseWriter
// is really going to ask for
try
{
writer = renderKit.createResponseWriter(NullWriter.INSTANCE, contentType, encoding);
}
catch (IllegalArgumentException e)
{
// Added because of an RI bug prior to 1.2_05-b3. Might as well leave it in case other
// impls have the same problem. https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=613
log.fine("The impl didn't correctly handled '*/*' in the content type list. Trying '*/*' directly.");
writer = renderKit.createResponseWriter(NullWriter.INSTANCE, "*/*", encoding);
}
// Override the JSF provided content type if necessary
contentType = getResponseContentType(context, writer.getContentType());
encoding = getResponseEncoding(context, writer.getCharacterEncoding());