final ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
final PluginClassLoader tempLoader = (PluginClassLoader) pm.getClassLoader(PLUGIN_ID);
final IParameterProvider requestParams = getRequestParameters();
OutputStream out = null;
if( outputHandler == null ) {
throw new InvalidParameterException( "SimpleContentGenerator.ERROR_0001_NO_OUTPUT_HANDLER" ); //$NON-NLS-1$
}
String solutionName = null;
if (requestParams != null){
solutionName = requestParams.getStringParameter("solution", null); //$NON-NLS-1$
}
if (solutionName == null){
solutionName = "NONE";
}
String filename = requestParams.getStringParameter("action", null);
filename = filename == null ? "" : filename;
DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
String date = df.format(new Date());
filename = filename + date;
String mimeType = "text/plain";
ExporterResource ex = (ExporterResource) appContext.getBean("exporterBean");
if (ex != null) {
String solution = requestParams.getStringParameter("solution", null);
String path = requestParams.getStringParameter("path", null);
String action = requestParams.getStringParameter("action", null);
String schedule = requestParams.getStringParameter("schedule", null);
if (schedule != null) {
return;
}
String file = (solution != null ? solution + "/" : "")
+ (path != null ? (path + "/") : "")
+ (action != null ? action : "");
// String exportType = requestParams.getStringParameter("export", null);
String exportType = "XLS";
try {
Thread.currentThread().setContextClassLoader(tempLoader);
Response r = null;
if (exportType == null || "XLS".equals(exportType.toUpperCase())) {
r = ex.exportExcel(file, null, null);
mimeType = "application/vnd.ms-excel";
filename += ".xls";
} else if ("CSV".equals(exportType.toUpperCase())) {
r = ex.exportCsv(file, null, null);
mimeType = "application/csv";
filename += ".csv";
}
setInstanceId(filename);
IContentItem contentItem = outputHandler.getOutputContentItem( "response", "content", solutionName, instanceId, mimeType ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if( contentItem == null ) {
error("SimpleContentGenerator.ERROR_0002_NO_CONTENT_ITEM"); //$NON-NLS-1$
throw new InvalidParameterException("SimpleContentGenerator.ERROR_0002_NO_CONTENT_ITEM"); //$NON-NLS-1$
}
contentItem.setName(filename);
//
// logger.error("item: " + itemName);
// logger.error("instance: " + instanceId);
out = contentItem.getOutputStream( itemName );
if( out == null ) {
error("SimpleContentGenerator.ERROR_0003_NO_OUTPUT_STREAM"); //$NON-NLS-1$
throw new InvalidParameterException("SimpleContentGenerator.ERROR_0003_NO_OUTPUT_STREAM"); //$NON-NLS-1$
}
if (r.getStatus() == 200) {
out.write( ((byte[]) r.getEntity()));
try {