Search in sources :

Example 1 with ReportGenerator

use of org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator in project pentaho-platform by pentaho.

the class JFreeReportComponent method getReportFromResource.

private MasterReport getReportFromResource() throws ResourceException, IOException {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    MasterReport report = null;
    Object reportDefinition = jFreeReportAction.getReportDefinition();
    IActionSequenceResource resource = null;
    if (reportDefinition instanceof ActionResource) {
        resource = getResource(((ActionResource) reportDefinition).getName());
    }
    if (resource != null) {
        if (resource.getSourceType() == IActionResource.XML) {
            String repDef = resource.getAddress();
            ReportGenerator generator = ReportGenerator.createInstance();
            // add the runtime context so that PentahoResourceData class can get access to the solution repo
            // generator.setObject(PentahoResourceData.PENTAHO_RUNTIME_CONTEXT_KEY, getRuntimeContext());
            // Read the encoding from the XML file - see BISERVER-895
            final String encoding = XmlHelper.getEncoding(repDef, null);
            ByteArrayInputStream inStream = new ByteArrayInputStream(repDef.getBytes(encoding));
            InputSource repDefInputSource = new InputSource(inStream);
            repDefInputSource.setEncoding(encoding);
            report = generator.parseReport(repDefInputSource, getDefinedResourceURL(null));
        } else {
            report = parseReport(resource);
        }
    }
    return report;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) ReportGenerator(org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) IActionResource(org.pentaho.actionsequence.dom.IActionResource) ActionResource(org.pentaho.actionsequence.dom.ActionResource) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 2 with ReportGenerator

use of org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator in project pentaho-platform by pentaho.

the class JFreeReportComponent method getReportFromJar.

private MasterReport getReportFromJar() throws Exception {
    JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
    MasterReport report;
    org.pentaho.actionsequence.dom.IActionResource reportJar = jFreeReportAction.getReportDefinitionJar().getJar();
    final IActionSequenceResource resource = getResource(reportJar.getName());
    final ClassLoader loader = ReportUtils.createJarLoader(getSession(), resource);
    if (loader == null) {
        throw new Exception(Messages.getInstance().getString(// $NON-NLS-1$
        "JFreeReportLoadComponent.ERROR_0035_COULD_NOT_CREATE_CLASSLOADER"));
    }
    String reportLocation = jFreeReportAction.getReportDefinitionJar().getReportLocation();
    URL resourceUrl = loader.getResource(reportLocation);
    if (resourceUrl == null) {
        throw new Exception(// $NON-NLS-1$
        Messages.getInstance().getErrorString(// $NON-NLS-1$
        "JFreeReport.ERROR_0016_REPORT_RESOURCE_INVALID", reportLocation, resource.getAddress()));
    }
    try {
        ReportGenerator generator = ReportGenerator.getInstance();
        // add the runtime context so that PentahoResourceData class can get access to the solution repo
        // generator.setObject(PentahoResourceData.PENTAHO_RUNTIME_CONTEXT_KEY, getRuntimeContext());
        report = generator.parseReport(resourceUrl, getDefinedResourceURL(resourceUrl));
    } catch (Exception ex) {
        throw new Exception(Messages.getInstance().getErrorString("JFreeReport.ERROR_0007_COULD_NOT_PARSE", reportLocation), // $NON-NLS-1$
        ex);
    }
    return report;
}
Also used : JFreeReportAction(org.pentaho.actionsequence.dom.actions.JFreeReportAction) MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) IActionResource(org.pentaho.actionsequence.dom.IActionResource) ReportGenerator(org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator) PrintException(javax.print.PrintException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException) URL(java.net.URL) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 3 with ReportGenerator

use of org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator in project pentaho-platform by pentaho.

the class JFreeReportComponent method createReport.

protected MasterReport createReport(final String reportDefinition) throws ResourceException, IOException {
    ReportGenerator generator = ReportGenerator.createInstance();
    // add the runtime context so that PentahoResourceData class can get access to the solution repo
    // generator.setObject(PentahoResourceData.PENTAHO_RUNTIME_CONTEXT_KEY, getRuntimeContext());
    URL url = null;
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        url = new URL(requestContext.getContextPath());
    } catch (Exception e) {
        // a null URL is ok
        // $NON-NLS-1$
        warn(Messages.getInstance().getString("JFreeReportLoadComponent.WARN_COULD_NOT_CREATE_URL"));
    }
    // Read the encoding from the XML file - see BISERVER-895
    final String encoding = XmlHelper.getEncoding(reportDefinition, null);
    ByteArrayInputStream inStream = new ByteArrayInputStream(reportDefinition.getBytes(encoding));
    InputSource reportDefinitionInputSource = new InputSource(inStream);
    reportDefinitionInputSource.setEncoding(encoding);
    return generator.parseReport(reportDefinitionInputSource, getDefinedResourceURL(url));
}
Also used : ReportGenerator(org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) URL(java.net.URL) PrintException(javax.print.PrintException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) ReportProcessingException(org.pentaho.reporting.engine.classic.core.ReportProcessingException) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException)

Example 4 with ReportGenerator

use of org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator in project pentaho-platform by pentaho.

the class JFreeReportLoadComponent method getReportFromResource.

private MasterReport getReportFromResource() throws ResourceException, IOException {
    MasterReport report = null;
    if (isDefinedResource(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN)) {
        final IActionSequenceResource resource = getResource(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN);
        if (resource.getSourceType() == IActionResource.XML) {
            String repDef = resource.getAddress();
            ReportGenerator generator = ReportGenerator.getInstance();
            report = generator.parseReport(new InputSource(new ByteArrayInputStream(repDef.getBytes())), getDefinedResourceURL(null));
        }
        report = parseReport(resource);
    } else if (isDefinedInput(AbstractJFreeReportComponent.REPORTLOAD_RESOURCENAME)) {
        final String resName = getInputStringValue(AbstractJFreeReportComponent.REPORTLOAD_RESOURCENAME);
        if (isDefinedResource(resName)) {
            final IActionSequenceResource resource = getResource(resName);
            report = parseReport(resource);
        }
    }
    return report;
}
Also used : MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) ReportGenerator(org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 5 with ReportGenerator

use of org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator in project pentaho-platform by pentaho.

the class JFreeReportLoadComponent method getReportFromInputParam.

private MasterReport getReportFromInputParam() throws ResourceException, UnsupportedEncodingException, IOException {
    MasterReport report = null;
    if (isDefinedInput(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN)) {
        IActionParameter o = getInputParameter(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN);
        if (o != null) {
            String repDef = o.getStringValue();
            ReportGenerator generator = ReportGenerator.getInstance();
            IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
            URL url = null;
            try {
                url = new URL(requestContext.getContextPath());
            } catch (Exception e) {
                // a null URL is ok
                // $NON-NLS-1$
                warn(Messages.getInstance().getString("JFreeReportLoadComponent.WARN_COULD_NOT_CREATE_URL"));
            }
            report = generator.parseReport(new InputSource(new ByteArrayInputStream(repDef.getBytes("UTF-8"))), // $NON-NLS-1$
            getDefinedResourceURL(url));
        }
    }
    return report;
}
Also used : MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) ReportGenerator(org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) URL(java.net.URL) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ReportGenerator (org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator)6 MasterReport (org.pentaho.reporting.engine.classic.core.MasterReport)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URL (java.net.URL)4 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)4 ResourceException (org.pentaho.reporting.libraries.resourceloader.ResourceException)4 InputSource (org.xml.sax.InputSource)4 FileNotFoundException (java.io.FileNotFoundException)2 PrintException (javax.print.PrintException)2 IActionResource (org.pentaho.actionsequence.dom.IActionResource)2 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)2 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)2 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)2 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)2 ActionResource (org.pentaho.actionsequence.dom.ActionResource)1 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)1