Search in sources :

Example 1 with ResourceException

use of org.pentaho.reporting.libraries.resourceloader.ResourceException in project pentaho-platform by pentaho.

the class PRPTImportHandler method extractMetaData.

// keep it protected for test goal, we should not add any logic for this method such we just
// incapsulate getting information from external class
/**
 * extract metadata from input bundle
 *
 * @param bytes
 * @return
 * @throws PlatformImportException if we are failed to create metadata from input data
 */
protected DocumentMetaData extractMetaData(byte[] bytes) throws PlatformImportException {
    try {
        ResourceManager mgr = new ResourceManager();
        MasterReport report = (MasterReport) mgr.createDirectly(bytes, MasterReport.class).getResource();
        return report.getBundle().getMetaData();
    } catch (ResourceException e) {
        throw new PlatformImportException("An unexpected error occurred while parsing a report definition", e);
    }
}
Also used : MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) ResourceManager(org.pentaho.reporting.libraries.resourceloader.ResourceManager)

Example 2 with ResourceException

use of org.pentaho.reporting.libraries.resourceloader.ResourceException 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 3 with ResourceException

use of org.pentaho.reporting.libraries.resourceloader.ResourceException 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

ResourceException (org.pentaho.reporting.libraries.resourceloader.ResourceException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URL (java.net.URL)2 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)2 MasterReport (org.pentaho.reporting.engine.classic.core.MasterReport)2 ReportGenerator (org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator)2 InputSource (org.xml.sax.InputSource)2 FileNotFoundException (java.io.FileNotFoundException)1 PrintException (javax.print.PrintException)1 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)1 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)1 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)1 ResourceManager (org.pentaho.reporting.libraries.resourceloader.ResourceManager)1