Search in sources :

Example 6 with ContentLocation

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

the class JFreeReportZipHtmlComponent method performExport.

@Override
protected boolean performExport(final MasterReport report, final OutputStream outputStream) {
    try {
        String dataDirectory = getInputStringValue(AbstractJFreeReportComponent.REPORTDIRECTORYHTML_DATADIR);
        if (dataDirectory == null) {
            // $NON-NLS-1$
            dataDirectory = "data";
        }
        final ZipRepository zipRepository = new ZipRepository();
        final ContentLocation root = zipRepository.getRoot();
        final ContentLocation data = // $NON-NLS-1$
        RepositoryUtilities.createLocation(zipRepository, RepositoryUtilities.split(dataDirectory, "/"));
        final FlowHtmlOutputProcessor outputProcessor = new FlowHtmlOutputProcessor();
        final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
        // $NON-NLS-1$
        printer.setContentWriter(root, new DefaultNameGenerator(root, "report.html"));
        // $NON-NLS-1$
        printer.setDataWriter(data, new DefaultNameGenerator(data, "content"));
        printer.setUrlRewriter(new SingleRepositoryURLRewriter());
        outputProcessor.setPrinter(printer);
        final FlowReportProcessor sp = new FlowReportProcessor(report, outputProcessor);
        final int yieldRate = getYieldRate();
        if (yieldRate > 0) {
            sp.addReportProgressListener(new YieldReportListener(yieldRate));
        }
        sp.processReport();
        zipRepository.write(outputStream);
        close();
        return true;
    } catch (ReportProcessingException e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
        return false;
    } catch (IOException e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
        return false;
    } catch (ContentIOException e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getString("JFreeReportZipHtmlComponent.ERROR_0046_FAILED_TO_PROCESS_REPORT"), e);
        return false;
    }
}
Also used : 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) IOException(java.io.IOException) SingleRepositoryURLRewriter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.SingleRepositoryURLRewriter) 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) FlowReportProcessor(org.pentaho.reporting.engine.classic.core.modules.output.table.base.FlowReportProcessor) AllItemsHtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.AllItemsHtmlPrinter) HtmlPrinter(org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlPrinter) ZipRepository(org.pentaho.reporting.libraries.repository.zip.ZipRepository)

Example 7 with ContentLocation

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

the class PentahoURLRewriter method rewrite.

public String rewrite(final ContentEntity contentEntry, final ContentEntity dataEntity) throws URLRewriteException {
    try {
        final ArrayList<String> entityNames = new ArrayList<String>();
        entityNames.add(dataEntity.getName());
        ContentLocation location = dataEntity.getParent();
        while (location != null) {
            entityNames.add(location.getName());
            location = location.getParent();
        }
        final ArrayList<String> contentNames = new ArrayList<String>();
        location = dataEntity.getRepository().getRoot();
        while (location != null) {
            contentNames.add(location.getName());
            location = location.getParent();
        }
        // now remove all path elements that are equal ..
        while ((contentNames.isEmpty() == false) && (entityNames.isEmpty() == false)) {
            final String lastEntity = (String) entityNames.get(entityNames.size() - 1);
            final String lastContent = (String) contentNames.get(contentNames.size() - 1);
            if (lastContent.equals(lastEntity) == false) {
                break;
            }
            entityNames.remove(entityNames.size() - 1);
            contentNames.remove(contentNames.size() - 1);
        }
        final StringBuffer b = new StringBuffer();
        for (int i = entityNames.size() - 1; i >= 0; i--) {
            final String name = (String) entityNames.get(i);
            b.append(name);
            if (i != 0) {
                // $NON-NLS-1$
                b.append("/");
            }
        }
        if (pattern == null) {
            return b.toString();
        }
        return MessageFormat.format(pattern, new Object[] { b.toString() });
    } catch (ContentIOException cioe) {
        throw new URLRewriteException();
    }
}
Also used : ContentLocation(org.pentaho.reporting.libraries.repository.ContentLocation) ArrayList(java.util.ArrayList) URLRewriteException(org.pentaho.reporting.engine.classic.core.modules.output.table.html.URLRewriteException) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException)

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