Search in sources :

Example 1 with NonCachingPipeline

use of org.apache.cocoon.pipeline.NonCachingPipeline in project syncope by apache.

the class ReportLogic method exportExecutionResult.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
public void exportExecutionResult(final OutputStream os, final ReportExec reportExec, final ReportExecExportFormat format) {
    // streaming SAX handler from a compressed byte array stream
    try (ByteArrayInputStream bais = new ByteArrayInputStream(reportExec.getExecResult());
        ZipInputStream zis = new ZipInputStream(bais)) {
        // a single ZipEntry in the ZipInputStream (see ReportJob)
        zis.getNextEntry();
        Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<>();
        pipeline.addComponent(new XMLGenerator(zis));
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("status", reportExec.getStatus());
        parameters.put("message", reportExec.getMessage());
        parameters.put("start", reportExec.getStart());
        parameters.put("end", reportExec.getEnd());
        switch(format) {
            case HTML:
                XSLTTransformer xsl2html = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getHTMLTemplate(), StandardCharsets.UTF_8)));
                xsl2html.setParameters(parameters);
                pipeline.addComponent(xsl2html);
                pipeline.addComponent(XMLSerializer.createXHTMLSerializer());
                break;
            case PDF:
                XSLTTransformer xsl2pdf = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getFOTemplate(), StandardCharsets.UTF_8)));
                xsl2pdf.setParameters(parameters);
                pipeline.addComponent(xsl2pdf);
                pipeline.addComponent(new FopSerializer(MimeConstants.MIME_PDF));
                break;
            case RTF:
                XSLTTransformer xsl2rtf = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getFOTemplate(), StandardCharsets.UTF_8)));
                xsl2rtf.setParameters(parameters);
                pipeline.addComponent(xsl2rtf);
                pipeline.addComponent(new FopSerializer(MimeConstants.MIME_RTF));
                break;
            case CSV:
                XSLTTransformer xsl2csv = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getCSVTemplate(), StandardCharsets.UTF_8)));
                xsl2csv.setParameters(parameters);
                pipeline.addComponent(xsl2csv);
                pipeline.addComponent(new TextSerializer());
                break;
            case XML:
            default:
                pipeline.addComponent(XMLSerializer.createXMLSerializer());
        }
        pipeline.setup(os);
        pipeline.execute();
        LOG.debug("Result of {} successfully exported as {}", reportExec, format);
    } catch (Exception e) {
        LOG.error("While exporting content", e);
    }
}
Also used : HashMap(java.util.HashMap) StreamSource(javax.xml.transform.stream.StreamSource) XMLGenerator(org.apache.cocoon.sax.component.XMLGenerator) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SchedulerException(org.quartz.SchedulerException) FopSerializer(org.apache.syncope.core.logic.cocoon.FopSerializer) ZipInputStream(java.util.zip.ZipInputStream) NonCachingPipeline(org.apache.cocoon.pipeline.NonCachingPipeline) TextSerializer(org.apache.syncope.core.logic.cocoon.TextSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) XSLTTransformer(org.apache.syncope.core.logic.cocoon.XSLTTransformer) SAXPipelineComponent(org.apache.cocoon.sax.SAXPipelineComponent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with NonCachingPipeline

use of org.apache.cocoon.pipeline.NonCachingPipeline in project sling by apache.

the class PipelineImpl method eval.

@Override
public void eval() throws Exception {
    try {
        this.getEnv().setCcPipeline(new NonCachingPipeline());
        // generator
        AbstractGenerator generator = new SlingGenerator(this.getEnv().getSling());
        this.getEnv().getCcPipeline().addComponent(generator);
        // subpipeline evaluated
        for (Step step : this.getSubpipeline()) {
            step.eval();
        }
        this.getEnv().getCcPipeline().addComponent(new XMLSerializer());
        // Don't retrieve OutputStream from response until actually writing
        // to response, so that error handlers can retrieve it without getting
        // an error
        final OutputStream out = new OutputStreamWrapper() {

            @Override
            protected OutputStream getWrappedStream() throws IOException {
                return getEnv().getSling().getResponse().getOutputStream();
            }
        };
        this.getEnv().getCcPipeline().setup(out);
        this.getEnv().getCcPipeline().execute();
    } catch (Exception e) {
        String absPath = this.getEnv().getSling().getRequest().getResource().getPath();
        throw new Exception("Error in pipeline for resource: " + absPath, e);
    }
}
Also used : NonCachingPipeline(org.apache.cocoon.pipeline.NonCachingPipeline) XMLSerializer(org.apache.cocoon.pipeline.component.sax.XMLSerializer) SlingGenerator(org.apache.sling.scripting.xproc.cocoon.generator.SlingGenerator) AbstractGenerator(org.apache.cocoon.pipeline.component.sax.AbstractGenerator) OutputStream(java.io.OutputStream) Step(org.apache.sling.scripting.xproc.xpl.api.Step) IOException(java.io.IOException)

Aggregations

NonCachingPipeline (org.apache.cocoon.pipeline.NonCachingPipeline)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 ZipInputStream (java.util.zip.ZipInputStream)1 StreamSource (javax.xml.transform.stream.StreamSource)1 AbstractGenerator (org.apache.cocoon.pipeline.component.sax.AbstractGenerator)1 XMLSerializer (org.apache.cocoon.pipeline.component.sax.XMLSerializer)1 SAXPipelineComponent (org.apache.cocoon.sax.SAXPipelineComponent)1 XMLGenerator (org.apache.cocoon.sax.component.XMLGenerator)1 SlingGenerator (org.apache.sling.scripting.xproc.cocoon.generator.SlingGenerator)1 Step (org.apache.sling.scripting.xproc.xpl.api.Step)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 FopSerializer (org.apache.syncope.core.logic.cocoon.FopSerializer)1 TextSerializer (org.apache.syncope.core.logic.cocoon.TextSerializer)1 XSLTTransformer (org.apache.syncope.core.logic.cocoon.XSLTTransformer)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 SchedulerException (org.quartz.SchedulerException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1