entry = LoaderUtils.mergePaths( (String) parent.getIdentifier(), path ); } else { entry = (String) parent.getIdentifier(); if ( factoryKeys != null ) { map = new HashMap(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters(); return new ResourceKey( parent.getParent(), parent.getSchema(), entry, map );
public static boolean isEmbeddedKey( final MasterReport report, final ResourceKey resourceKey ) { final ResourceKey contentBase = report.getContentBase(); if ( contentBase == null ) { return false; } ResourceKey bundleKey = contentBase.getParent(); while ( bundleKey != null ) { if ( bundleKey.equals( resourceKey.getParent() ) ) { return true; } bundleKey = bundleKey.getParent(); } return false; }
public int hashCode() { int result = loader.hashCode(); result = 29 * result + source.hashCode(); return result; } }
public static File getContextAsFile( ResourceKey key ) { while ( key != null ) { final Object identifier = key.getIdentifier(); if ( identifier instanceof File ) { return (File) identifier; } key = key.getParent(); } return null; }
/** * Checks, whether this resource loader implementation was responsible for creating this key. * * @param key the key that should be tested. * @return true, if the key is supported. */ public boolean isSupportedKey( final ResourceKey key ) { if ( key == null ) { throw new NullPointerException(); } if ( key.getParent() == null ) { return false; } if ( ZipResourceBundleLoader.class.getName().equals( key.getSchema() ) == false ) { return false; } return true; }
/** * Serializes the resource key to a String representation which can be recreated using the * <code>deserialize(ResourceKey)<code> method. * * @param bundleKey * @param key * @return a <code>String<code> which is a serialized version of the <code>ResourceKey</code> * @throws ResourceException indicates an error serializing the resource key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof String ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a byte[] object" ); } final String data = (String) key.getIdentifier(); return ResourceKeyUtils.createStringResourceKey ( String.valueOf( key.getSchema() ), data, key.getFactoryParameters() ); }
/** * Creates a new resource key from the given object and the factory keys. * * @param value * @param factoryKeys * @return the created key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException if creating the key failed. */ public ResourceKey createKey( final Object value, final Map factoryKeys ) throws ResourceKeyCreationException { if ( value instanceof byte[] == false ) { return null; } return new ResourceKey( SCHEMA_NAME, value, factoryKeys ); }
public URL toURL( final ResourceKey key ) { return (URL) key.getIdentifier(); }
final Map factoryParameters = resourceKey.getFactoryParameters(); if ( embedded == false && "true".equals( factoryParameters.get( ClassicEngineFactoryParameters.EMBED ) ) == false && RawResourceLoader.SCHEMA_NAME.equals( resourceKey.getSchema() ) == false ) { return null; pattern = derivePatternFromPath( mimeRegistry, mimeType, resourceKey.getIdentifierAsString() ); pattern, mimeType, newFactoryParameters ); if ( log.isDebugEnabled() ) { log.debug( "Resouce Embedded: [" + newResourceKey.getIdentifierAsString() + "]" );
public long getVersion( final ResourceKey key ) { if ( key.equals( this.key ) ) { return version; } // -1 is the placeholder for: not known. return -1; }
final Object identifier = key.getIdentifier(); if ( identifier instanceof File == false ) { return null; // Not a valid key for creating a file-repository map.put( new FactoryParameterKey( "repository-loader" ), this ); final ResourceKey mainKey = new ResourceKey ( key, DirectoryResourceBundleLoader.class.getName(), bundleMapping, map );
public ResourceKey createResourceKey( final String entryName, final Map factoryParameters ) throws ResourceKeyCreationException { if ( entryName == null ) { throw new NullPointerException(); } final ResourceKey bundleKey = getBundleMainKey().getParent(); final ResourceBundleLoader o = (ResourceBundleLoader) bundleKey.getFactoryParameters().get( new FactoryParameterKey( "repository-loader" ) ); if ( o == null ) { throw new ResourceKeyCreationException( "Unable to create a inner-bundle key, no loader available." ); } return o.deriveKey( getBundleMainKey(), entryName, factoryParameters ); }
private ResourceKey localizeKey( final ResourceManager resourceManager, final ResourceKey valueKey ) { final Object object = valueKey.getFactoryParameters().get( ClassicEngineFactoryParameters.EMBED ); if ( "false".equals( object ) ) { return valueKey; } if ( "org.pentaho.reporting.libraries.docbundle.bundleloader.RepositoryResourceBundleLoader".equals( valueKey .getSchema() ) == false && object == null ) { return valueKey; } try { final ResourceData resourceData = resourceManager.load( valueKey ); final byte[] resource = resourceData.getResource( resourceManager ); return resourceManager.createKey( resource, valueKey.getFactoryParameters() ); } catch ( ResourceException e ) { if ( logger.isDebugEnabled() ) { logger.info( "Unable to normalize embedded resource-key, using ordinary key-object instead.", e ); } else { logger.info( "Unable to normalize embedded resource-key, using ordinary key-object instead." ); } } return valueKey; }
/** * Checks, whether this resource loader implementation was responsible for creating this key. * * @param key * @return */ public boolean isSupportedKey( final ResourceKey key ) { return SCHEMA_NAME.equals( key.getSchema() ); }
/** * Tries to load the bundle. If the key does not point to a usable resource-bundle, this method returns null. The * Exception is only thrown if the bundle is not readable because of IO-Errors. * <p/> * A resource-bundle loader should only load the bundle for the key itself, never for any of the derived subkeys. It * is the ResourceManager's responsibility to search the key's hierachy for the correct key. * * @param key the resource key pointing to the bundle. * @return the loaded bundle or null, if the resource was not understood. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException if something goes wrong. */ public ResourceBundleData loadBundle( final ResourceManager resourceManager, final ResourceKey key ) throws ResourceLoadingException { if ( isSupportedKey( key ) == false ) { return null; } final RepositoryResourceBundleLoader o = (RepositoryResourceBundleLoader) key.getFactoryParameters().get( new FactoryParameterKey( "repository-loader" ) ); return o.loadBundle( resourceManager, key ); }
if ( value instanceof ResourceKey ) { final ResourceKey reskey = (ResourceKey) value; final String identifierAsString = reskey.getIdentifierAsString(); attList.setAttribute( namespace, name, "resource-key:" + reskey.getSchema() + ":" + identifierAsString ); this.xmlWriter .writeTag( XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList, XmlWriter.CLOSE );
/** * Removes the specified resource from the resource bundle if that resource exists. * * @param documentBundle the bundle from which the resource will be removed * @param resource the reference to the resource to be removed * @return <code>true</code> if the resource was removed, <code>false</code> otherwise * @throws IOException indicates an error trying to remove the resource from the bundle */ public static boolean removeResource( final WriteableDocumentBundle documentBundle, final ResourceKey resource ) throws IOException { if ( documentBundle == null ) { throw new IllegalArgumentException(); } if ( resource == null ) { throw new IllegalArgumentException(); } if ( documentBundle.isEmbeddedKey( resource ) ) { return documentBundle.removeEntry( resource.getIdentifierAsString() ); } return false; }
/** * Creates a String version of the resource key that can be used to generate a new ResourceKey object via * deserialization * * @param bundleKey * @param key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof byte[] ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a byte[] object" ); } final byte[] data = (byte[]) key.getIdentifier(); final char[] cdata = new char[ data.length ]; for ( int i = 0; i < data.length; i++ ) { cdata[ i ] = (char) ( data[ i ] & 0xFF ); } return ResourceKeyUtils.createStringResourceKey ( String.valueOf( key.getSchema() ), new String( cdata ), key.getFactoryParameters() ); }
public static ResourceKey createAsDerived( final ResourceKey parent, final ResourceKey child ) { if ( child.parent != null ) { throw new IllegalArgumentException(); } return new ResourceKey( parent, child.schema, child.identifier, child.factoryParameters ); }