use of org.pentaho.reporting.engine.classic.core.layout.output.ReportProcessor in project pentaho-kettle by pentaho.
the class PentahoReportingOutput method processReport.
private void processReport(Object[] r, String sourceFilename, String targetFilename, ProcessorType outputProcessorType, Boolean createParentFolder) throws KettleException {
try {
// Load the master report from the PRPT
//
MasterReport report = loadMasterReport(sourceFilename);
// Set the parameters values that are present in the various fields...
//
ReportParameterValues values = report.getParameterValues();
ReportParameterDefinition definition = report.getParameterDefinition();
for (String parameterName : meta.getParameterFieldMap().keySet()) {
String fieldName = meta.getParameterFieldMap().get(parameterName);
if (fieldName != null) {
int index = getInputRowMeta().indexOfValue(fieldName);
if (index < 0) {
throw new KettleException(BaseMessages.getString(PKG, "PentahoReportingOutput.Exception.CanNotFindField", fieldName));
}
Class<?> clazz = findParameterClass(definition, parameterName);
Object value = null;
if (clazz != null) {
if (clazz.equals(String.class)) {
value = getInputRowMeta().getString(r, index);
} else if (clazz.equals((new String[0]).getClass())) {
value = getInputRowMeta().getString(r, index).split("\t");
} else if (clazz.equals(Date.class)) {
value = getInputRowMeta().getDate(r, index);
} else if (clazz.equals(byte.class) || clazz.equals(Byte.class)) {
value = getInputRowMeta().getInteger(r, index).byteValue();
} else if (clazz.equals(Short.class) || clazz.equals(short.class)) {
value = getInputRowMeta().getInteger(r, index).shortValue();
} else if (clazz.equals(Integer.class) || clazz.equals(int.class)) {
value = getInputRowMeta().getInteger(r, index).intValue();
} else if (clazz.equals(Long.class) || clazz.equals(long.class)) {
value = getInputRowMeta().getInteger(r, index);
} else if (clazz.equals(Double.class) || clazz.equals(double.class)) {
value = getInputRowMeta().getNumber(r, index);
} else if (clazz.equals(Float.class) || clazz.equals(float.class)) {
value = getInputRowMeta().getNumber(r, index).floatValue();
} else if (clazz.equals(Number.class)) {
value = getInputRowMeta().getBigNumber(r, index).floatValue();
} else if (clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {
value = getInputRowMeta().getBoolean(r, index);
} else if (clazz.equals(BigDecimal.class)) {
value = getInputRowMeta().getBigNumber(r, index);
} else if (clazz.equals((new byte[0]).getClass())) {
value = getInputRowMeta().getBinary(r, index);
} else {
value = getInputRowMeta().getValueMeta(index).convertToNormalStorageType(r[index]);
}
values.put(parameterName, value);
} else {
// This parameter was not found, log this as a warning...
//
logBasic(BaseMessages.getString(PKG, "PentahoReportingOutput.Log.ParameterNotFoundInReport", parameterName, sourceFilename));
}
}
}
Runnable exportTask;
PentahoReportingSwingGuiContext context = new PentahoReportingSwingGuiContext();
switch(outputProcessorType) {
case PDF:
exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {
protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
PdfOutputProcessor outputProcessor = new PdfOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
return new PageableReportProcessor(report, outputProcessor);
}
};
break;
case CSV:
exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {
protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
ReportStructureValidator validator = new ReportStructureValidator();
if (validator.isValidForFastProcessing(report) == false) {
StreamCSVOutputProcessor target = new StreamCSVOutputProcessor(fout);
return new StreamReportProcessor(report, target);
} else {
return new FastCsvExportProcessor(report, fout);
}
}
};
break;
case Excel:
exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {
protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
ReportStructureValidator validator = new ReportStructureValidator();
if (validator.isValidForFastProcessing(report) == false) {
final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
target.setUseXlsxFormat(false);
return new FlowReportProcessor(report, target);
} else {
return new FastExcelExportProcessor(report, fout, false);
}
}
};
break;
case Excel_2007:
exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {
protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
ReportStructureValidator validator = new ReportStructureValidator();
if (validator.isValidForFastProcessing(report) == false) {
final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
target.setUseXlsxFormat(true);
return new FlowReportProcessor(report, target);
} else {
return new FastExcelExportProcessor(report, fout, true);
}
}
};
break;
case StreamingHTML:
exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {
protected String filename, suffix;
protected ContentLocation targetRoot;
@Override
protected void execute() throws Exception {
FileObject targetDirectory = targetFile.getParent();
FileObjectRepository targetRepository = new FileObjectRepository(targetDirectory);
targetRoot = targetRepository.getRoot();
suffix = getSuffix(targetPath);
filename = IOUtils.getInstance().stripFileExtension(targetFile.getName().toString());
ReportProcessor reportProcessor = createReportProcessor(null);
try {
reportProcessor.processReport();
} finally {
reportProcessor.close();
}
}
protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
ReportStructureValidator validator = new ReportStructureValidator();
if (validator.isValidForFastProcessing(report) == false) {
final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor(report.getConfiguration());
final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, filename, suffix));
// $NON-NLS-1$
printer.setDataWriter(null, null);
printer.setUrlRewriter(new FileSystemURLRewriter());
outputProcessor.setPrinter(printer);
return new StreamReportProcessor(report, outputProcessor);
} else {
FastHtmlContentItems printer = new FastHtmlContentItems();
printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, filename, suffix));
// $NON-NLS-1$
printer.setDataWriter(null, null);
printer.setUrlRewriter(new FileSystemURLRewriter());
return new FastHtmlExportProcessor(report, printer);
}
}
};
break;
case PagedHTML:
exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {
protected String filename, suffix;
protected ContentLocation targetRoot;
@Override
protected void execute() throws Exception {
FileObject targetDirectory = targetFile.getParent();
FileObjectRepository targetRepository = new FileObjectRepository(targetDirectory);
targetRoot = targetRepository.getRoot();
suffix = getSuffix(targetPath);
filename = IOUtils.getInstance().stripFileExtension(targetFile.getName().toString());
ReportProcessor reportProcessor = createReportProcessor(null);
try {
reportProcessor.processReport();
} finally {
reportProcessor.close();
}
}
protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor();
final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, filename, suffix));
printer.setDataWriter(targetRoot, new DefaultNameGenerator(targetRoot, "content"));
printer.setUrlRewriter(new FileSystemURLRewriter());
outputProcessor.setPrinter(printer);
return new FlowReportProcessor(report, outputProcessor);
}
};
break;
case RTF:
exportTask = new ReportExportTask(report, context, targetFilename, createParentFolder) {
protected ReportProcessor createReportProcessor(OutputStream fout) throws Exception {
StreamRTFOutputProcessor target = new StreamRTFOutputProcessor(report.getConfiguration(), fout, report.getResourceManager());
return new StreamReportProcessor(report, target);
}
};
break;
default:
exportTask = null;
break;
}
if (exportTask != null) {
exportTask.run();
}
if (context.getStatusType() == StatusType.ERROR) {
KettleVFS.getFileObject(targetFilename, getTransMeta()).delete();
if (context.getCause() != null) {
throw context.getCause();
}
throw new KettleStepException(context.getMessage());
}
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(targetFilename, getTransMeta()), getTransMeta().getName(), getStepname());
resultFile.setComment("This file was created with a Pentaho Reporting Output step");
addResultFile(resultFile);
} catch (Throwable e) {
throw new KettleException(BaseMessages.getString(PKG, "PentahoReportingOutput.Exception.UnexpectedErrorRenderingReport", sourceFilename, targetFilename, outputProcessorType.getDescription()), e);
}
}
use of org.pentaho.reporting.engine.classic.core.layout.output.ReportProcessor in project pentaho-kettle by pentaho.
the class ReportExportTask method execute.
protected void execute() throws Exception {
BufferedOutputStream fout = null;
ReportProcessor reportProcessor = null;
try {
fout = new BufferedOutputStream(targetFile.getContent().getOutputStream());
reportProcessor = createReportProcessor(fout);
reportProcessor.processReport();
// $NON-NLS-1$
statusListener.setStatus(// $NON-NLS-1$
StatusType.INFORMATION, // $NON-NLS-1$
messages.getString("ReportExportTask.USER_EXPORT_COMPLETE"), null);
reportProcessor.close();
try {
fout.close();
} catch (Exception ex) {
}
} catch (Exception ex) {
try {
reportProcessor.close();
} catch (Exception ex2) {
}
try {
fout.close();
} catch (Exception ex2) {
}
try {
if (targetFile.exists() && !targetFile.delete()) {
// $NON-NLS-1$
logger.warn("Unable to delete incomplete export: " + targetFile);
}
} catch (Exception ex2) {
// $NON-NLS-1$
logger.warn("Unable to delete incomplete export: " + targetFile);
}
throw ex;
}
}
Aggregations