use of org.pentaho.reporting.libraries.repository.file.FileRepository in project pentaho-platform by pentaho.
the class JFreeReportDirectoryHtmlComponent method performExport.
@Override
protected boolean performExport(final MasterReport report) {
try {
final File targetFile = getInputFileValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_TARGETFILE);
if (targetFile == null) {
return false;
}
File dataDirectory = getInputFileValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_DATADIR);
if (dataDirectory == null) {
// $NON-NLS-1$
dataDirectory = new File(targetFile, "data/");
}
final File targetDirectory = targetFile.getParentFile();
if (dataDirectory.exists() && (dataDirectory.isDirectory() == false)) {
dataDirectory = dataDirectory.getParentFile();
if (dataDirectory.isDirectory() == false) {
String msg = // $NON-NLS-1$
Messages.getInstance().getErrorString(// $NON-NLS-1$
"JFreeReportDirectoryComponent.ERROR_0001_INVALID_DIR", dataDirectory.getPath());
throw new ReportProcessingException(msg);
}
} else if (dataDirectory.exists() == false) {
dataDirectory.mkdirs();
}
final FileRepository targetRepository = new FileRepository(targetDirectory);
final ContentLocation targetRoot = targetRepository.getRoot();
final FileRepository dataRepository = new FileRepository(dataDirectory);
final ContentLocation dataRoot = dataRepository.getRoot();
final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor();
final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, targetFile.getName()));
// $NON-NLS-1$
printer.setDataWriter(dataRoot, new DefaultNameGenerator(targetRoot, "content"));
printer.setUrlRewriter(new FileSystemURLRewriter());
outputProcessor.setPrinter(printer);
final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor);
final int yieldRate = getYieldRate();
if (yieldRate > 0) {
sp.addReportProgressListener(new YieldReportListener(yieldRate));
}
sp.processReport();
sp.close();
return true;
} catch (ReportProcessingException e) {
return false;
} catch (ContentIOException e) {
return false;
}
}
use of org.pentaho.reporting.libraries.repository.file.FileRepository in project pentaho-platform by pentaho.
the class JFreeReportHtmlComponent method performExport.
@SuppressWarnings("deprecation")
@Override
protected boolean performExport(final MasterReport report, final OutputStream outputStream) {
try {
String contentHandlerPattern = getInputStringValue(AbstractJFreeReportComponent.REPORTHTML_CONTENTHANDLER);
if (contentHandlerPattern == null) {
final Configuration globalConfig = ClassicEngineBoot.getInstance().getGlobalConfig();
// $NON-NLS-1$
contentHandlerPattern = globalConfig.getConfigProperty("org.pentaho.web.ContentHandler");
}
final IApplicationContext ctx = PentahoSystem.getApplicationContext();
final URLRewriter rewriter;
final ContentLocation dataLocation;
final NameGenerator dataNameGenerator;
if (ctx != null) {
// $NON-NLS-1$
File dataDirectory = new File(ctx.getFileOutputPath("system/tmp/"));
if (dataDirectory.exists() && (dataDirectory.isDirectory() == false)) {
dataDirectory = dataDirectory.getParentFile();
if (dataDirectory.isDirectory() == false) {
throw new ReportProcessingException(Messages.getInstance().getErrorString("JFreeReportDirectoryComponent.ERROR_0001_INVALID_DIR", // $NON-NLS-1$
dataDirectory.getPath()));
}
} else if (dataDirectory.exists() == false) {
dataDirectory.mkdirs();
}
final FileRepository dataRepository = new FileRepository(dataDirectory);
dataLocation = dataRepository.getRoot();
dataNameGenerator = new DefaultNameGenerator(dataLocation);
rewriter = new PentahoURLRewriter(contentHandlerPattern);
} else {
dataLocation = null;
dataNameGenerator = null;
rewriter = new PentahoURLRewriter(contentHandlerPattern);
}
final StreamRepository targetRepository = new StreamRepository(null, outputStream);
final ContentLocation targetRoot = targetRepository.getRoot();
final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor(report.getConfiguration());
final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
// $NON-NLS-1$//$NON-NLS-2$
printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, "index", "html"));
printer.setDataWriter(dataLocation, dataNameGenerator);
printer.setUrlRewriter(rewriter);
outputProcessor.setPrinter(printer);
final StreamReportProcessor sp = new StreamReportProcessor(report, outputProcessor);
final int yieldRate = getYieldRate();
if (yieldRate > 0) {
sp.addReportProgressListener(new YieldReportListener(yieldRate));
}
sp.processReport();
sp.close();
outputStream.flush();
close();
return true;
} catch (ReportProcessingException e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
return false;
} catch (IOException e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
return false;
} catch (ContentIOException e) {
// $NON-NLS-1$
error(Messages.getInstance().getString("JFreeReportHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
return false;
}
}
Aggregations