}
byte[] bytes;
try {
bytes = contentString.getBytes(CharEncoding.UTF_8);
} catch (UnsupportedEncodingException e) {
throw new NSForwardException(e, "Can't convert string to UTF-8...you should get a better VM");
}
InputStream stream = new ByteArrayInputStream(bytes);
EGSimpleTableParser parser = new EGSimpleTableParser(stream, fonts(), styles());
try {
NSData data = parser.data();
if((hasBinding("data") && canSetValueForBinding("data")) ||
(hasBinding("stream") && canSetValueForBinding("stream"))
) {
if(hasBinding("data")) {
setValueForBinding(data, "data");
}
if(hasBinding("stream")) {
setValueForBinding(data.stream(), "stream");
}
response.appendContentString(contentString);
} else {
String fileName = fileName();
if(fileName == null) {
fileName = "results.xls";
}
response.disableClientCaching();
response.appendHeader(String.valueOf( data.length()), "Content-Length" );
response.setContent(data); // Changed by ishimoto because it was sooooo buggy and didn't work in Japanese
response.setHeader("inline; filename=\"" + fileName + "\"", "content-disposition");
response.setHeader("application/vnd.ms-excel", "content-type");
}
} catch (Exception ex) {
if (ex.getCause() instanceof SAXParseException) {
SAXParseException parseException = (SAXParseException)ex.getCause();
String logMessage = "'"+context().page().getClass().getName()+"' caused a SAXParseException";
logMessage += "\nMessage: '"+parseException.getMessage()+"'";
// weird but true, getLineNumber is off by 1 (for display purposes I think - mhast)
logMessage += "\nLine : "+(parseException.getLineNumber() - 1);
logMessage += "\nColumn : "+parseException.getColumnNumber();
logMessage += "\n--- content begin ---";
logMessage += addLineNumbers(contentString);
logMessage += "--- content end ---";
log.error(logMessage);
throw new NSForwardException(ex);
}
// else don't handle exception just pass it forward
else {
throw new NSForwardException(ex);
}
}
} else {
super.appendToResponse(response, context);
}