Search in sources :

Example 1 with ResourceKeyCreationException

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

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResourceKey (org.pentaho.reporting.libraries.resourceloader.ResourceKey)1 ResourceKeyCreationException (org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException)1