if (outPage.getContentType().equals("application/pdf") && !outPage.getStyleSheet().equals("")) {
//--- build the xml data for the XSL/FO translation
String styleSheet = outPage.getStyleSheet();
Element guiElem;
TimerContext guiServicesTimerContext = context.getMonitorManager().getTimer(ServiceManagerGuiServicesTimer.class).time();
try {
guiElem = outPage.invokeGuiServices(context, response, vDefaultGui);
} finally {
guiServicesTimerContext.stop();
}
addPrefixes(guiElem, context.getLanguage(), req.getService(), context.getApplicationContext().getBean(NodeInfo.class)
.getId());
Element rootElem = new Element(Jeeves.Elem.ROOT)
.addContent(guiElem)
.addContent(response);
Element reqElem = (Element) req.getParams().clone();
reqElem.setName(Jeeves.Elem.REQUEST);
rootElem.addContent(reqElem);
//--- do an XSL transformation
styleSheet = appPath + Jeeves.Path.XSL + styleSheet;
if (!new File(styleSheet).exists())
error(" -> stylesheet not found on disk, aborting : " + styleSheet);
else {
info(" -> transforming with stylesheet : " + styleSheet);
try {
TimerContext timerContext = context.getMonitorManager().getTimer(ServiceManagerXslOutputTransformTimer.class)
.time();
String file;
try {
//--- first we do the transformation
file = Xml.transformFOP(uploadDir, rootElem, styleSheet);
} finally {
timerContext.stop();
}
response = BinaryFile.encode(200, file, "document.pdf", true);
} catch (Exception e) {
error(" -> exception during XSL/FO transformation for : " + req.getService());
error(" -> (C) stylesheet : " + styleSheet);
error(" -> (C) message : " + e.getMessage());
error(" -> (C) exception : " + e.getClass().getSimpleName());
throw e;
}
info(" -> end transformation for : " + req.getService());
}
}
String contentType = BinaryFile.getContentType(response);
if (contentType == null)
contentType = "application/octet-stream";
String contentDisposition = BinaryFile.getContentDisposition(response);
String contentLength = BinaryFile.getContentLength(response);
int cl = (contentLength == null) ? -1 : Integer.parseInt(contentLength);
// Did we set up a status code for the response?
if (context.getStatusCode() != null) {
((ServiceRequest) req).setStatusCode(context.getStatusCode());
}
req.beginStream(contentType, cl, contentDisposition, cache);
BinaryFile.write(response, req.getOutputStream());
req.endStream();
BinaryFile.removeIfTheCase(response);
}
//--- BLOB output
else if (outPage.isBLOB()) {
String contentType = BLOB.getContentType(response);
if (contentType == null)
contentType = "application/octet-stream";
String contentDisposition = BLOB.getContentDisposition(response);
String contentLength = BLOB.getContentLength(response);
int cl = (contentLength == null) ? -1 : Integer.parseInt(contentLength);
req.beginStream(contentType, cl, contentDisposition, cache);
BLOB.write(response, req.getOutputStream());
req.endStream();
}
//--- HTML/XML output
else {
//--- build the xml data for the XSL translation
String styleSheet = outPage.getStyleSheet();
Element guiElem;
TimerContext guiServicesTimerContext = getMonitorManager().getTimer(ServiceManagerGuiServicesTimer.class).time();
try {
guiElem = outPage.invokeGuiServices(context, response, vDefaultGui);
} finally {
guiServicesTimerContext.stop();
}
addPrefixes(guiElem, context.getLanguage(), req.getService(), context.getApplicationContext().getBean(NodeInfo.class).getId
());
Element rootElem = new Element(Jeeves.Elem.ROOT)
.addContent(guiElem)
.addContent(response);
Element reqElem = (Element) req.getParams().clone();
reqElem.setName(Jeeves.Elem.REQUEST);
rootElem.addContent(reqElem);
//--- do an XSL translation or send xml data to a debug routine
if (req.hasDebug()) {
req.beginStream("application/xml; charset=UTF-8", cache);
req.write(rootElem);
} else {
//--- do an XSL transformation
styleSheet = appPath + Jeeves.Path.XSL + styleSheet;
if (!new File(styleSheet).exists())
error(" -> stylesheet not found on disk, aborting : " + styleSheet);
else {
info(" -> transforming with stylesheet : " + styleSheet);
try {
//--- then we set the content-type and output the result
// If JSON output requested, run the XSLT transformation and the JSON
if (req.hasJSONOutput()) {
Element xsltResponse = null;
TimerContext timerContext = context.getMonitorManager().getTimer(ServiceManagerXslOutputTransformTimer
.class).time();
try {
//--- first we do the transformation
xsltResponse = Xml.transform(rootElem, styleSheet);
} finally {
timerContext.stop();
}
req.beginStream("application/json; charset=UTF-8", cache);
req.getOutputStream().write(Xml.getJSON(xsltResponse).getBytes(Constants.ENCODING));
req.endStream();
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TimerContext timerContext = context.getMonitorManager().getTimer(ServiceManagerXslOutputTransformTimer
.class).time();
try {
//--- first we do the transformation
Xml.transform(rootElem, styleSheet, baos);
} finally {
timerContext.stop();
}
req.beginStream(outPage.getContentType(), cache);
req.getOutputStream().write(baos.toByteArray());
req.endStream();
}