Search in sources :

Example 1 with ContentIOException

use of org.pentaho.reporting.libraries.repository.ContentIOException in project pentaho-kettle by pentaho.

the class FileObjectContentLocation method getEntry.

/**
 * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised.
 *
 * @param name the name of the entity to be retrieved.
 * @return the content entity for this name, never null.
 * @throws ContentIOException if an repository error occured.
 */
public ContentEntity getEntry(final String name) throws ContentIOException {
    try {
        if (RepositoryUtilities.isInvalidPathName(name)) {
            throw new IllegalArgumentException("The name given is not valid.");
        }
        final FileObject file = getBackend();
        final FileObject child = file.resolveFile(name);
        if (child.exists() == false) {
            throw new ContentIOException("Not found:" + child);
        }
        if (child.isFolder()) {
            return new FileObjectContentLocation(this, child);
        } else if (child.isFile()) {
            return new FileObjectContentItem(this, child);
        } else {
            throw new ContentIOException("Not File nor directory.");
        }
    } catch (FileSystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException)

Example 2 with ContentIOException

use of org.pentaho.reporting.libraries.repository.ContentIOException 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 ContentIOException

use of org.pentaho.reporting.libraries.repository.ContentIOException 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 4 with ContentIOException

use of org.pentaho.reporting.libraries.repository.ContentIOException 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)

Example 5 with ContentIOException

use of org.pentaho.reporting.libraries.repository.ContentIOException in project pentaho-kettle by pentaho.

the class FileObjectContentLocation method createLocation.

/**
 * Creates a new content location in the current location. This method must never return null. This method will fail
 * if an entity with the same name exists in this location.
 *
 * @param name the name of the new entity.
 * @return the newly created entity, never null.
 * @throws ContentCreationException if the item could not be created.
 */
public ContentLocation createLocation(final String name) throws ContentCreationException {
    if (RepositoryUtilities.isInvalidPathName(name)) {
        throw new IllegalArgumentException("The name given is not valid.");
    }
    try {
        final FileObject file = getBackend();
        final FileObject child = file.resolveFile(name);
        if (child.exists()) {
            throw new ContentCreationException("File already exists.");
        }
        child.createFile();
        try {
            return new FileObjectContentLocation(this, child);
        } catch (ContentIOException e) {
            throw new ContentCreationException("Failed to create the content-location", e);
        }
    } catch (FileSystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ContentCreationException(org.pentaho.reporting.libraries.repository.ContentCreationException) FileObject(org.apache.commons.vfs2.FileObject) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException)

Aggregations

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