use of org.pentaho.reporting.libraries.repository.file.FileRepository in project pentaho-platform by pentaho.
the class JFreeReportComponent method writeHtml.
public boolean writeHtml(final MasterReport report, final OutputStream outputStream, final int yieldRate, String htmlContentHandlerUrlPattern) {
try {
if (htmlContentHandlerUrlPattern == null) {
final Configuration globalConfig = ClassicEngineBoot.getInstance().getGlobalConfig();
htmlContentHandlerUrlPattern = PentahoRequestContextHolder.getRequestContext().getContextPath();
// $NON-NLS-1$
htmlContentHandlerUrlPattern += 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(htmlContentHandlerUrlPattern);
} else {
dataLocation = null;
dataNameGenerator = null;
rewriter = new PentahoURLRewriter(htmlContentHandlerUrlPattern);
}
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);
if (yieldRate > 0) {
sp.addReportProgressListener(new YieldReportListener(yieldRate));
}
sp.processReport();
sp.close();
outputStream.flush();
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;
}
}
use of org.pentaho.reporting.libraries.repository.file.FileRepository in project pentaho-platform by pentaho.
the class PentahoURLRewriterTest method testRewriteRoot.
@Test
public void testRewriteRoot() throws Exception {
String pattern = TEST_SRC + "/solution/test/reporting/system/{0}/param";
PentahoURLRewriter rewriter = new PentahoURLRewriter(pattern);
File dataDirectory = new File("/");
FileRepository dataRepository = new FileRepository(dataDirectory);
File contentEntryBackend = new File(TEST_SRC + "/solution/test/reporting/contentEntryBackend");
File dataEntityBackend = new File(TEST_SRC + "/solution/test/reporting/dataEntityBackend");
ContentEntity contentEntry = new FileContentItem(dataRepository.getRoot(), contentEntryBackend);
ContentEntity dataEntity = new FileContentItem(dataRepository.getRoot(), dataEntityBackend);
String result = rewriter.rewrite(contentEntry, dataEntity);
assertEquals(TEST_SRC + "/solution/test/reporting/system/dataEntityBackend/param", result);
}
use of org.pentaho.reporting.libraries.repository.file.FileRepository in project pentaho-platform by pentaho.
the class PentahoURLRewriterTest method testRewriteWithPatternParam.
@Test
public void testRewriteWithPatternParam() throws Exception {
String pattern = TEST_SRC + "/solution/test/reporting/system/{0}/param";
PentahoURLRewriter rewriter = new PentahoURLRewriter(pattern);
File dataDirectory = new File(TEST_SRC + "/solution/test/reporting/");
FileRepository dataRepository = new FileRepository(dataDirectory);
File contentEntryBackend = new File(TEST_SRC + "/solution/test/reporting/contentEntryBackend");
File dataEntityBackend = new File(TEST_SRC + "/solution/test/reporting/dataEntityBackend");
ContentEntity contentEntry = new FileContentItem(dataRepository.getRoot(), contentEntryBackend);
ContentEntity dataEntity = new FileContentItem(dataRepository.getRoot(), dataEntityBackend);
String result = rewriter.rewrite(contentEntry, dataEntity);
assertEquals(TEST_SRC + "/solution/test/reporting/system/dataEntityBackend/param", result);
}
use of org.pentaho.reporting.libraries.repository.file.FileRepository in project pentaho-platform by pentaho.
the class PentahoURLRewriterTest method testRewriteWithSimplePattern.
@Test
public void testRewriteWithSimplePattern() throws Exception {
String pattern = TEST_SRC + "/solution/test/reporting/system";
PentahoURLRewriter rewriter = new PentahoURLRewriter(pattern);
File dataDirectory = new File(TEST_SRC + "/solution/test/reporting/");
FileRepository dataRepository = new FileRepository(dataDirectory);
File contentEntryBackend = new File(TEST_SRC + "/solution/test/reporting/contentEntryBackend");
File dataEntityBackend = new File(TEST_SRC + "/solution/test/reporting/dataEntityBackend");
ContentEntity contentEntry = new FileContentItem(dataRepository.getRoot(), contentEntryBackend);
ContentEntity dataEntity = new FileContentItem(dataRepository.getRoot(), dataEntityBackend);
String result = rewriter.rewrite(contentEntry, dataEntity);
assertEquals(pattern, result);
}
use of org.pentaho.reporting.libraries.repository.file.FileRepository in project pentaho-platform by pentaho.
the class PentahoURLRewriterTest method testRewriteWithNullPattern.
@Test
public void testRewriteWithNullPattern() throws Exception {
String pattern = null;
PentahoURLRewriter rewriter = new PentahoURLRewriter(pattern);
File dataDirectory = new File(TEST_SRC + "/solution/test/reporting/");
FileRepository dataRepository = new FileRepository(dataDirectory);
File contentEntryBackend = new File(TEST_SRC + "/solution/test/reporting/contentEntryBackend");
File dataEntityBackend = new File(TEST_SRC + "/solution/test/reporting/dataEntityBackend");
ContentEntity contentEntry = new FileContentItem(dataRepository.getRoot(), contentEntryBackend);
ContentEntity dataEntity = new FileContentItem(dataRepository.getRoot(), dataEntityBackend);
String result = rewriter.rewrite(contentEntry, dataEntity);
assertEquals("dataEntityBackend", result);
}
Aggregations