Search in sources :

Example 6 with ReportProcessingException

use of org.pentaho.reporting.engine.classic.core.ReportProcessingException 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 7 with ReportProcessingException

use of org.pentaho.reporting.engine.classic.core.ReportProcessingException 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 8 with ReportProcessingException

use of org.pentaho.reporting.engine.classic.core.ReportProcessingException in project pentaho-platform by pentaho.

the class JFreeReportCSVComponent method performExport.

@Override
protected boolean performExport(final MasterReport report, final OutputStream outputStream) {
    try {
        final StreamCSVOutputProcessor target = new StreamCSVOutputProcessor(outputStream);
        final StreamReportProcessor reportProcessor = new StreamReportProcessor(report, target);
        final int yieldRate = getYieldRate();
        if (yieldRate > 0) {
            reportProcessor.addReportProgressListener(new YieldReportListener(yieldRate));
        }
        reportProcessor.processReport();
        reportProcessor.close();
        outputStream.flush();
        close();
        return true;
    } catch (ReportProcessingException e) {
        return false;
    } catch (IOException e) {
        return false;
    }
}
Also used : StreamCSVOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.csv.StreamCSVOutputProcessor) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) YieldReportListener(org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener) StreamReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor) IOException(java.io.IOException)

Example 9 with ReportProcessingException

use of org.pentaho.reporting.engine.classic.core.ReportProcessingException in project pentaho-platform by pentaho.

the class JFreeReportExcelComponent method performExport.

@Override
protected boolean performExport(final MasterReport report, final OutputStream outputStream) {
    try {
        final FlowExcelOutputProcessor target = new FlowExcelOutputProcessor(report.getConfiguration(), outputStream, report.getResourceManager());
        final FlowReportProcessor reportProcessor = new FlowReportProcessor(report, target);
        if (isDefinedInput(AbstractJFreeReportComponent.WORKBOOK_PARAM)) {
            try {
                final InputStream inputStream = getInputStream(AbstractJFreeReportComponent.WORKBOOK_PARAM);
                target.setTemplateInputStream(inputStream);
            } catch (Exception e) {
                error(Messages.getInstance().getString("JFreeReportExcelComponent.ERROR_0037_ERROR_READING_REPORT_INPUT"), // $NON-NLS-1$
                e);
                return false;
            }
        }
        final int yieldRate = getYieldRate();
        if (yieldRate > 0) {
            reportProcessor.addReportProgressListener(new YieldReportListener(yieldRate));
        }
        reportProcessor.processReport();
        reportProcessor.close();
        outputStream.flush();
        close();
        return true;
    } catch (ReportProcessingException e) {
        return false;
    } catch (IOException e) {
        return false;
    }
}
Also used : ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) YieldReportListener(org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener) FlowExcelOutputProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.xls.FlowExcelOutputProcessor) InputStream(java.io.InputStream) FlowReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor) IOException(java.io.IOException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) IOException(java.io.IOException)

Example 10 with ReportProcessingException

use of org.pentaho.reporting.engine.classic.core.ReportProcessingException in project pentaho-kettle by pentaho.

the class ReportExportTask method run.

/**
 * When an object implementing interface <code>Runnable</code> is used to create a thread, starting the thread causes
 * the object's <code>run</code> method to be called in that separately executing thread.
 * <p/>
 * The general contract of the method <code>run</code> is that it may take any action whatsoever.
 *
 * @see Thread#run()
 */
public void run() {
    try {
        targetFile = KettleVFS.getFileObject(targetPath);
        if (targetFile.exists()) {
            if (!targetFile.delete()) {
                // $NON-NLS-1$
                throw new ReportProcessingException(messages.getErrorString("ReportExportTask.ERROR_0001_TARGET_EXISTS"));
            }
        }
        if (createParentFolder) {
            targetFile.getParent().createFolder();
        } else if (!targetFile.getParent().exists()) {
            throw new ReportProcessingException(messages.getString("ReportExportTask.PARENT_FOLDER_DOES_NOT_EXIST", targetFile.getParent().getName().getPath()));
        }
        execute();
    } catch (Exception ex) {
        // $NON-NLS-1$
        statusListener.setStatus(StatusType.ERROR, messages.getString("ReportExportTask.USER_EXPORT_FAILED"), ex);
        // $NON-NLS-1$
        logger.error("Failed");
    }
}
Also used : ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) MissingResourceException(java.util.MissingResourceException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException)

Aggregations

ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)15 IOException (java.io.IOException)11 YieldReportListener (org.pentaho.reporting.engine.classic.core.layout.output.YieldReportListener)10 StreamReportProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.base.StreamReportProcessor)7 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)7 AllItemsHtmlPrinter (org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter)5 HtmlPrinter (org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter)5 ContentLocation (org.pentaho.reporting.libraries.repository.ContentLocation)5 DefaultNameGenerator (org.pentaho.reporting.libraries.repository.DefaultNameGenerator)5 File (java.io.File)3 FlowReportProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor)3 HtmlOutputProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlOutputProcessor)3 StreamHtmlOutputProcessor (org.pentaho.reporting.engine.classic.core.modules.output.table.html.StreamHtmlOutputProcessor)3 FileRepository (org.pentaho.reporting.libraries.repository.file.FileRepository)3 StreamRepository (org.pentaho.reporting.libraries.repository.stream.StreamRepository)3 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintException (javax.print.PrintException)2 PrintService (javax.print.PrintService)2 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)2 PentahoURLRewriter (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoURLRewriter)2