Search in sources :

Example 1 with ContentLocation

use of org.pentaho.reporting.libraries.repository.ContentLocation 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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StreamCSVOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.csv.StreamCSVOutputProcessor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) FlowExcelOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.xls.FlowExcelOutputProcessor) OutputStream(java.io.OutputStream) FastHtmlContentItems(org.pentaho.reporting.engine.classic.core.modules.output.fast.html.FastHtmlContentItems) StreamRTFOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.StreamRTFOutputProcessor) ReportStructureValidator(org.pentaho.reporting.engine.classic.core.modules.output.fast.validator.ReportStructureValidator) FileObjectRepository(org.pentaho.di.trans.steps.pentahoreporting.urlrepository.FileObjectRepository) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) FlowHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FlowHtmlOutputProcessor) HtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor) ReportParameterDefinition(org.pentaho.reporting.engine.classic.core.parameters.ReportParameterDefinition) PageableReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.pageable.base.PageableReportProcessor) FileSystemURLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FileSystemURLRewriter) FlowReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor) FastHtmlExportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.fast.html.FastHtmlExportProcessor) FileObject(org.apache.commons.vfs2.FileObject) FastCsvExportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.fast.csv.FastCsvExportProcessor) ReportParameterValues(org.pentaho.reporting.engine.classic.core.util.ReportParameterValues) PdfOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfOutputProcessor) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) FlowHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FlowHtmlOutputProcessor) FlowReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor) ReportProcessor(org.pentaho.reporting.engine.classic.core.layout.output.ReportProcessor) PageableReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.pageable.base.PageableReportProcessor) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) ResultFile(org.pentaho.di.core.ResultFile) BigDecimal(java.math.BigDecimal) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) FastExcelExportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.fast.xls.FastExcelExportProcessor) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) FileObject(org.apache.commons.vfs2.FileObject) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter)

Example 2 with ContentLocation

use of org.pentaho.reporting.libraries.repository.ContentLocation 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;
    }
}
Also used : FileRepository(org.pentaho.reporting.libraries.repository.file.FileRepository) Configuration(org.pentaho.reporting.libraries.base.config.Configuration) ModifiableConfiguration(org.pentaho.reporting.libraries.base.config.ModifiableConfiguration) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) NameGenerator(org.pentaho.reporting.libraries.repository.NameGenerator) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) IOException(java.io.IOException) PentahoURLRewriter(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) HtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) URLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriter) PentahoURLRewriter(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) YieldReportListener(org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) File(java.io.File) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter) StreamRepository(org.pentaho.reporting.libraries.repository.stream.StreamRepository)

Example 3 with ContentLocation

use of org.pentaho.reporting.libraries.repository.ContentLocation in project pentaho-platform by pentaho.

the class JFreeReportStreamHtmlComponent method performExport.

@SuppressWarnings("deprecation")
@Override
protected boolean performExport(final MasterReport report, final OutputStream outputStream) {
    try {
        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(null, null);
        printer.setUrlRewriter(new FileSystemURLRewriter());
        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) {
        return false;
    } catch (IOException e) {
        return false;
    }
}
Also used : DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) IOException(java.io.IOException) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) HtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) YieldReportListener(org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) FileSystemURLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FileSystemURLRewriter) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter) StreamRepository(org.pentaho.reporting.libraries.repository.stream.StreamRepository)

Example 4 with ContentLocation

use of org.pentaho.reporting.libraries.repository.ContentLocation 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;
    }
}
Also used : FileRepository(org.pentaho.reporting.libraries.repository.file.FileRepository) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) FlowHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FlowHtmlOutputProcessor) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) YieldReportListener(org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) FileSystemURLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.FileSystemURLRewriter) FlowReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor) File(java.io.File) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter)

Example 5 with ContentLocation

use of org.pentaho.reporting.libraries.repository.ContentLocation 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;
    }
}
Also used : FileRepository(org.pentaho.reporting.libraries.repository.file.FileRepository) Configuration(org.pentaho.reporting.libraries.base.config.Configuration) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) NameGenerator(org.pentaho.reporting.libraries.repository.NameGenerator) DefaultNameGenerator(org.pentaho.reporting.libraries.repository.DefaultNameGenerator) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) IOException(java.io.IOException) PentahoURLRewriter(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) HtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) URLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriter) PentahoURLRewriter(org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) YieldReportListener(org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) StreamHtmlOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) File(java.io.File) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter) StreamRepository(org.pentaho.reporting.libraries.repository.stream.StreamRepository)

Aggregations

ContentLocation (org.pentaho.reporting.libraries.repository.ContentLocation)7 AllItemsHtmlPrinter (org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter)6 HtmlPrinter (org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter)6 DefaultNameGenerator (org.pentaho.reporting.libraries.repository.DefaultNameGenerator)6 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)5 YieldReportListener (org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener)5 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)5 IOException (java.io.IOException)4 StreamReportProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor)4 HtmlOutputProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor)4 StreamHtmlOutputProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor)4 File (java.io.File)3 FlowReportProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor)3 FileSystemURLRewriter (org.pentaho.reporting.engine.classic.core.modules.output.table.html.FileSystemURLRewriter)3 FlowHtmlOutputProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.html.FlowHtmlOutputProcessor)3 FileRepository (org.pentaho.reporting.libraries.repository.file.FileRepository)3 StreamRepository (org.pentaho.reporting.libraries.repository.stream.StreamRepository)3 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)2 PentahoURLRewriter (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter)2 URLRewriter (org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriter)2