Search in sources :

Example 1 with ResourceKey

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

the class PentahoResourceLoader method deriveKey.

/**
 * derive a key from an existing key, used when a relative path is given.
 *
 * @param parent
 *          the parent key
 * @param data
 *          the new data to be keyed
 * @return derived key
 * @throws ResourceKeyCreationException
 */
public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map data) throws ResourceKeyCreationException {
    if (isSupportedKey(parent) == false) {
        // $NON-NLS-1$
        throw new ResourceKeyCreationException("Assertation: Unsupported parent key type");
    }
    String resource;
    if (path.startsWith("solution://")) {
        resource = path;
    } else if (path.startsWith("/")) {
        // $NON-NLS-1$
        resource = "solution:/" + path;
    } else {
        resource = LoaderUtils.mergePaths((String) parent.getIdentifier(), path);
        // add the slash. We do need to make sure that the resource is not a url
        if (!resource.startsWith(HTTP_URL_PREFIX) && !resource.startsWith(PATH_SEPARATOR)) {
            resource = PATH_SEPARATOR + resource;
        }
    }
    final Map map;
    if (data != null) {
        map = new HashMap();
        map.putAll(parent.getFactoryParameters());
        map.putAll(data);
    } else {
        map = parent.getFactoryParameters();
    }
    return new ResourceKey(parent.getSchema(), resource, map);
}
Also used : ResourceKeyCreationException(org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) ResourceKey(org.pentaho.reporting.libraries.resourceloader.ResourceKey)

Example 2 with ResourceKey

use of org.pentaho.reporting.libraries.resourceloader.ResourceKey in project pentaho-kettle by pentaho.

the class PentahoReportingOutputTest method setUp.

@Before
public void setUp() throws ResourceException {
    testResourceUrl = this.getClass().getResource("relative-path.prpt");
    resourceKey = new ResourceKey("org.pentaho.reporting.libraries.resourceloader.loader.URLResourceLoader", testResourceUrl, null);
    DataFactory mockedDataFactory = mock(DataFactory.class);
    when(mockedDataFactory.getQueryNames()).thenReturn(new String[] { QUERY_NAME });
    ResourceManager manager = new ResourceManager();
    manager.registerDefaults();
    MasterReport mockedMasterReport = mock(MasterReport.class);
    when(mockedMasterReport.getDataFactory()).thenReturn(mockedDataFactory);
    when(mockedMasterReport.getResourceManager()).thenReturn(manager);
    Resource resource = mock(CompoundResource.class);
    when(resource.getResource()).thenReturn(mockedMasterReport);
    when(resource.getDependencies()).thenReturn(new ResourceKey[] {});
    when(resource.getSource()).thenReturn(resourceKey);
    when(resource.getTargetType()).thenReturn(MasterReport.class);
    manager.getFactoryCache().put(resource);
    PowerMockito.stub(PowerMockito.method(DefaultResourceManagerBackend.class, "create")).toReturn(resource);
}
Also used : MasterReport(org.pentaho.reporting.engine.classic.core.MasterReport) Resource(org.pentaho.reporting.libraries.resourceloader.Resource) CompoundResource(org.pentaho.reporting.libraries.resourceloader.CompoundResource) DataFactory(org.pentaho.reporting.engine.classic.core.DataFactory) ResourceManager(org.pentaho.reporting.libraries.resourceloader.ResourceManager) ResourceKey(org.pentaho.reporting.libraries.resourceloader.ResourceKey) Before(org.junit.Before)

Example 3 with ResourceKey

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

the class JFreeReportComponent method parseReport.

private MasterReport parseReport(final IActionSequenceResource resource) {
    try {
        // define the resource url so that PentahoResourceLoader recognizes the path.
        String resourceUrl = PentahoResourceLoader.SOLUTION_SCHEMA_NAME + PentahoResourceLoader.SCHEMA_SEPARATOR + resource.getAddress();
        String fullyQualifiedServerURL = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
        HashMap<FactoryParameterKey, Object> helperObjects = new HashMap<FactoryParameterKey, Object>();
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        helperObjects.put(new FactoryParameterKey("pentahoBaseURL"), fullyQualifiedServerURL);
        // trim out the server and port
        helperObjects.put(new FactoryParameterKey("serverBaseURL"), getBaseServerURL(fullyQualifiedServerURL));
        // $NON-NLS-1$
        helperObjects.put(new FactoryParameterKey("solutionRoot"), // $NON-NLS-1$ //$NON-NLS-2$
        PentahoSystem.getApplicationContext().getSolutionPath(""));
        // get the host:port portion only
        // $NON-NLS-1$
        helperObjects.put(new FactoryParameterKey("hostColonPort"), getHostColonPort(fullyQualifiedServerURL));
        // get the requestContextPath
        helperObjects.put(new FactoryParameterKey("requestContextPath"), // $NON-NLS-1$
        PentahoRequestContextHolder.getRequestContext().getContextPath());
        Iterator it = getInputNames().iterator();
        while (it.hasNext()) {
            try {
                String inputName = (String) it.next();
                // on how the report definition would be parsed
                if (AbstractJFreeReportComponent.DATACOMPONENT_DATAINPUT.equals(inputName)) {
                    continue;
                }
                String inputValue = getInputStringValue(inputName);
                helperObjects.put(new FactoryParameterKey(inputName), inputValue);
            } catch (Exception e) {
            // ignore
            }
        }
        ResourceManager resourceManager = new ResourceManager();
        resourceManager.registerDefaults();
        ResourceKey contextKey = resourceManager.createKey(resourceUrl, helperObjects);
        ResourceKey key = resourceManager.createKey(resourceUrl, helperObjects);
        return ReportGenerator.getInstance().parseReport(resourceManager, key, contextKey);
    } catch (Exception ex) {
        error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0007_COULD_NOT_PARSE", resource.getAddress()), // $NON-NLS-1$
        ex);
        return null;
    }
}
Also used : FactoryParameterKey(org.pentaho.reporting.libraries.resourceloader.FactoryParameterKey) HashMap(java.util.HashMap) Iterator(java.util.Iterator) ResourceManager(org.pentaho.reporting.libraries.resourceloader.ResourceManager) 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) ResourceKey(org.pentaho.reporting.libraries.resourceloader.ResourceKey)

Example 4 with ResourceKey

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

the class JFreeReportLoadComponent method parseReport.

/**
 * Parses the report, using the given ActionResource as initial report definition.
 *
 * @param resource
 * @return
 */
private MasterReport parseReport(final IActionSequenceResource resource) {
    try {
        // define the resource url so that PentahoResourceLoader recognizes the path.
        String resourceUrl = PentahoResourceLoader.SOLUTION_SCHEMA_NAME + PentahoResourceLoader.SCHEMA_SEPARATOR + resource.getAddress();
        String fullyQualifiedServerUrl = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
        HashMap helperObjects = new HashMap();
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        helperObjects.put(new FactoryParameterKey("pentahoBaseURL"), fullyQualifiedServerUrl);
        // trim out the server and port
        // $NON-NLS-1$
        helperObjects.put(new FactoryParameterKey("serverBaseURL"), getBaseServerURL(fullyQualifiedServerUrl));
        helperObjects.put(new FactoryParameterKey("solutionRoot"), // $NON-NLS-1$ //$NON-NLS-2$
        PentahoSystem.getApplicationContext().getSolutionPath(""));
        // get the host:port portion only
        // $NON-NLS-1$
        helperObjects.put(new FactoryParameterKey("hostColonPort"), getHostColonPort(fullyQualifiedServerUrl));
        // get the requestContextPath
        helperObjects.put(new FactoryParameterKey("requestContextPath"), // $NON-NLS-1$
        PentahoRequestContextHolder.getRequestContext().getContextPath());
        Iterator it = getInputNames().iterator();
        while (it.hasNext()) {
            try {
                String inputName = (String) it.next();
                String inputValue = getInputStringValue(inputName);
                helperObjects.put(new FactoryParameterKey(inputName), inputValue);
            } catch (Exception e) {
            // ignore
            }
        }
        ResourceManager resourceManager = new ResourceManager();
        resourceManager.registerDefaults();
        ResourceKey contextKey = resourceManager.createKey(resourceUrl, helperObjects);
        ResourceKey key = resourceManager.createKey(resourceUrl, helperObjects);
        return ReportGenerator.getInstance().parseReport(resourceManager, key, contextKey);
    } catch (Exception ex) {
        error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0007_COULD_NOT_PARSE", resource.getAddress()), // $NON-NLS-1$
        ex);
        return null;
    }
}
Also used : HashMap(java.util.HashMap) FactoryParameterKey(org.pentaho.reporting.libraries.resourceloader.FactoryParameterKey) Iterator(java.util.Iterator) ResourceManager(org.pentaho.reporting.libraries.resourceloader.ResourceManager) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResourceKey(org.pentaho.reporting.libraries.resourceloader.ResourceKey)

Aggregations

ResourceKey (org.pentaho.reporting.libraries.resourceloader.ResourceKey)4 HashMap (java.util.HashMap)3 ResourceManager (org.pentaho.reporting.libraries.resourceloader.ResourceManager)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Iterator (java.util.Iterator)2 FactoryParameterKey (org.pentaho.reporting.libraries.resourceloader.FactoryParameterKey)2 ResourceException (org.pentaho.reporting.libraries.resourceloader.ResourceException)2 FileNotFoundException (java.io.FileNotFoundException)1 Map (java.util.Map)1 PrintException (javax.print.PrintException)1 Before (org.junit.Before)1 DataFactory (org.pentaho.reporting.engine.classic.core.DataFactory)1 MasterReport (org.pentaho.reporting.engine.classic.core.MasterReport)1 ReportProcessingException (org.pentaho.reporting.engine.classic.core.ReportProcessingException)1 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)1 CompoundResource (org.pentaho.reporting.libraries.resourceloader.CompoundResource)1 Resource (org.pentaho.reporting.libraries.resourceloader.Resource)1 ResourceKeyCreationException (org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException)1