os.flush();
} else {
// xml resource
SAXSerializer sax = null;
final Serializer serializer = broker.getSerializer();
serializer.reset();
//setup the http context
final HttpContext httpContext = serializer.new HttpContext();
final HttpRequestWrapper reqw = new HttpRequestWrapper(request, formEncoding, containerEncoding);
httpContext.setRequest(reqw);
httpContext.setSession(reqw.getSession(false));
serializer.setHttpContext(httpContext);
// Serialize the document
try {
sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(SAXSerializer.class);
// use a stylesheet if specified in query parameters
if (stylesheet != null) {
serializer.setStylesheet(resource, stylesheet);
}
serializer.setProperties(outputProperties);
serializer.prepareStylesheets(resource);
if (asMimeType != null) { // was a mime-type specified?
response.setContentType(asMimeType + "; charset=" + encoding);
} else {
if (serializer.isStylesheetApplied()
|| serializer.hasXSLPi(resource) != null) {
asMimeType = serializer.getStylesheetProperty(OutputKeys.MEDIA_TYPE);
if (!useDynamicContentType || asMimeType == null) {
asMimeType = MimeType.HTML_TYPE.getName();
}
if (LOG.isDebugEnabled()) {
LOG.debug("media-type: " + asMimeType);
}
response.setContentType(asMimeType + "; charset=" + encoding);
} else {
asMimeType = resource.getMetadata().getMimeType();
response.setContentType(asMimeType + "; charset=" + encoding);
}
}
if (asMimeType.equals(MimeType.HTML_TYPE.getName())) {
outputProperties.setProperty("method", "xhtml");
outputProperties.setProperty("media-type", "text/html; charset=" + encoding);
outputProperties.setProperty("indent", "yes");
outputProperties.setProperty("omit-xml-declaration", "no");
}
final OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), encoding);
sax.setOutput(writer, outputProperties);
serializer.setSAXHandlers(sax, sax);
serializer.toSAX(resource);
writer.flush();
writer.close();
} catch (final SAXException saxe) {
LOG.warn(saxe);