public static boolean isSameBundle( final ResourceKey elementSource, final ResourceKey attributeValue ) { if ( attributeValue == null ) { throw new NullPointerException(); } if ( elementSource == null ) { return false; } if ( elementSource.getParent() != null && attributeValue.getParent() != null ) { // Check whether both keys are part of the same bundle. return ( ObjectUtilities.equal( elementSource.getParent(), attributeValue.getParent() ) ); } // Not bundle keys? Check whether both keys at least refer to the same schema .. // if (ObjectUtilities.equal(elementSource.getSchema(), attributeValue.getSchema())) // { // return true; // } return false; }
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 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; }
public ResourceBundleData deriveData( final ResourceKey key ) throws ResourceLoadingException { if ( key == null ) { throw new NullPointerException(); } if ( ObjectUtilities.equal( key.getParent(), bundleKey ) == false ) { throw new IllegalArgumentException( "This key is no derivate of the current bundle." ); } return new RepositoryResourceBundleData( bundleKey, repository, key, true ); }
/** * 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 ) { final ResourceKey parent = key.getParent(); if ( parent == null ) { return false; } if ( DirectoryResourceLoader.class.getName().equals( parent.getSchema() ) == false ) { return false; } if ( DirectoryResourceBundleLoader.class.getName().equals( key.getSchema() ) == false ) { return false; } return true; }
public long getVersion( final ResourceManager caller ) throws ResourceLoadingException { final ResourceKey parentKey = key.getParent(); final ResourceData data = caller.load( parentKey ); return data.getVersion( caller ); } }
/** * 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 ( bundleKey.equals( key ) ) { return true; } if ( bundleKey.equals( key.getParent() ) ) { return true; } return false; }
public ResourceData load( final ResourceKey key ) throws ResourceLoadingException { final ResourceBundleData bundle = loadResourceBundle( key ); if ( bundle != null ) { logger.debug( "Loaded bundle for key " + key ); return bundle; } final ResourceKey parent = key.getParent(); if ( parent != null ) { // try to load the bundle data of the parent final ResourceBundleData parentData = loadResourceBundle( parent ); if ( parentData != null ) { logger.debug( "Loaded bundle for key (derivate) " + key ); return parentData.deriveData( key ); } } return loadRawData( key ); }
public InputStream getResourceAsStream( final ResourceManager caller ) throws ResourceLoadingException { // again, this is going to hurt the performance. final ResourceKey parentKey = key.getParent(); final ResourceData data = caller.load( parentKey ); final ZipInputStream zin = new ZipInputStream( data.getResourceAsStream( caller ) ); try { try { ZipEntry zipEntry = zin.getNextEntry(); while ( zipEntry != null ) { if ( zipEntry.getName().equals( key.getIdentifier() ) == false ) { zipEntry = zin.getNextEntry(); continue; } // read from here .. return zin; } } finally { zin.close(); } } catch ( IOException e ) { throw new ResourceLoadingException ( "Reading the zip-file failed.", e ); } throw new ResourceLoadingException ( "The zip-file did not contain the specified entry" ); }
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 File ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a File object" ); } // Log information logger.debug( "Serializing a File Resource Key..." ); if ( key.getParent() != null ) { throw new ResourceException ( "Unable to serialize a File-ResourceKey with a parent. This type is not expected to have a parent." ); } // Create a string version of the identifier try { final File file = (File) key.getIdentifier(); final String strIdentifier = file.getCanonicalPath(); final String result = ResourceKeyUtils.createStringResourceKey ( key.getSchema().toString(), strIdentifier, key.getFactoryParameters() ); logger.debug( "Serialized File Resource Key: [" + result + "]" ); return result; } catch ( IOException ioe ) { throw new IllegalArgumentException( "Could not determine cononical path to file specified in ResourceKey: " + ioe.getMessage() ); } }
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 ); }
/** * 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 String ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a String object" ); } // Log information logger.debug( "Serializing a Classloader Resource Key..." ); if ( key.getParent() != null ) { throw new ResourceException ( "Cannot serialize this key, it contains a parent, but should not contain one at all." ); } // Serialize the key final String result = ResourceKeyUtils.createStringResourceKey( key.getSchema().toString(), (String) key.getIdentifier(), key.getFactoryParameters() ); logger.debug( "Serialized Classloader Resource Key: [" + result + "]" ); return result; }
/** * Parses the report using the provided resource manager. * * @param manager * the resource manager (can be null). * @param input * the resource key pointing to the report definition. * @param contextKey * the report's context (used to load content that has been referenced with relative URLs). * @return the parsed report. * @throws ResourceException * if parsing or loading failed for some reason. */ public MasterReport parseReport( ResourceManager manager, final ResourceKey input, final ResourceKey contextKey ) throws ResourceException { if ( manager == null ) { manager = new ResourceManager(); } final HashMap map = new HashMap( input.getFactoryParameters() ); final Iterator it = this.helperObjects.keySet().iterator(); while ( it.hasNext() ) { final String name = (String) it.next(); map.put( new FactoryParameterKey( name ), helperObjects.get( name ) ); } final ResourceKey key = new ResourceKey( input.getParent(), input.getSchema(), input.getIdentifier(), input.getFactoryParameters() ); final Resource resource = manager.create( key, contextKey, MasterReport.class ); return (MasterReport) resource.getResource(); }
map = parent.getFactoryParameters(); return new ResourceKey( parent.getParent(), parent.getSchema(), entry, map );
return new ResourceKey( parent.getParent(), parent.getSchema(), entry, map );
if ( key.getParent() != null ) { final ResourceManager resourceManager = getRootHandler().getResourceManager(); try { final Resource bundleData = resourceManager.create( key.getParent(), null, DocumentBundle.class ); final DocumentBundle documentBundle = (DocumentBundle) bundleData.getResource(); report.setBundle( documentBundle );