/** * 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 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 ); }
/** * 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 File ) { final File f = (File) value; if ( f.exists() && f.isFile() ) { return new ResourceKey( SCHEMA_NAME, f, factoryKeys ); } } else if ( value instanceof String ) { final File f = new File( String.valueOf( value ) ); if ( f.exists() && f.isFile() ) { return new ResourceKey( SCHEMA_NAME, f, factoryKeys ); } } return null; }
/** * Creates a new resource key from the given object and the factory keys. * * @param value * @param factoryKeys * @return the created key or null, if the value object was not supported. * @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 == null ) { throw new NullPointerException(); } if ( value instanceof File ) { final File f = (File) value; if ( f.exists() && f.isDirectory() ) { return new ResourceKey( DirectoryResourceLoader.class.getName(), f, factoryKeys ); } } else if ( value instanceof String ) { final File f = new File( String.valueOf( value ) ); if ( f.exists() && f.isDirectory() ) { return new ResourceKey( DirectoryResourceLoader.class.getName(), f, factoryKeys ); } } return null; }
/** * 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 URL ) { return new ResourceKey( SCHEMA_NAME, value, factoryKeys ); } if ( value instanceof String ) { final String valueString = (String) value; // the 'file' schema is defined to have double-slashes, but the JDK // ignores RFC 1738 in that case. So we have to check for these beasts // directly .. if ( valueString.indexOf( "://" ) >= 0 || valueString.startsWith( "file:/" ) ) { try { return new ResourceKey( SCHEMA_NAME, new URL( valueString ), factoryKeys ); } catch ( MalformedURLException mfue ) { // we dont take this easy! throw new ResourceKeyCreationException( "Malformed value: " + value ); } } } return null; }
/** * 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 String ) { final String valueString = (String) value; if ( valueString.startsWith( RES_PREFIX ) ) { final String resourcePath = valueString.substring( 6 ); if ( ObjectUtilities.getResource( resourcePath, ClassloaderResourceData.class ) != null ) { return new ResourceKey( SCHEMA_NAME, value, factoryKeys ); } } } return null; }
public RepositoryResourceBundleLoader( final Repository repository, final ResourceKey outsideContextKey ) { if ( repository == null ) { throw new NullPointerException(); } this.repository = repository; final HashMap<FactoryParameterKey, Object> map = new HashMap<FactoryParameterKey, Object>(); map.put( new FactoryParameterKey( "repository" ), repository ); map.put( new FactoryParameterKey( "repository-loader" ), this ); this.bundleKey = new ResourceKey( outsideContextKey, SCHEMA, new Object(), map ); final String bundleType = BundleUtilities.getBundleType( repository ); final String bundleMapping = BundleUtilities.getBundleMapping( bundleType ); if ( bundleMapping == null ) { throw new IllegalStateException( "Invalid configuration: No Bundle-Mapping for the bundle-type " + bundleType ); } this.mainKey = new ResourceKey( bundleKey, INNER_SCHEMA, bundleMapping, null ); }
public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { // Parse the data final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); // Validate the data if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of key does not contain correct schema" ); } // Create a new file based on the path provided final File file = new File( keyData.getIdentifier() ); return new ResourceKey( SCHEMA_NAME, file, keyData.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 ZipEntryKey == false ) { return null; } final ZipEntryKey entryKey = (ZipEntryKey) value; final ResourceKey parentKey = entryKey.getZipFile().getKey(); return new ResourceKey( parentKey, SCHEMA_NAME, entryKey.getEntryName(), factoryKeys ); }
/** * 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.getSchema(), resource, map );
map = parent.getFactoryParameters(); return new ResourceKey( parent.getSchema(), target, map ); } catch ( IOException ioe ) { throw new ResourceKeyCreationException( "Failed to create key", ioe );
/** * Derives a new resource key from the given key. If neither a path nor new factory-keys are given, the parent key is * returned. * * @param parent the parent * @param path the derived path (can be null). * @param factoryKeys the optional factory keys (can be null). * @return the derived key. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException if the key cannot be derived * for any reason. */ public ResourceKey deriveKey( final ResourceKey parent, final String path, final Map factoryKeys ) throws ResourceKeyCreationException { if ( path != null ) { throw new ResourceKeyCreationException( "Unable to derive key for new path." ); } if ( isSupportedKey( parent ) == false ) { throw new ResourceKeyCreationException( "Assertation: Unsupported parent key type" ); } if ( factoryKeys == null ) { return parent; } final HashMap map = new HashMap(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); return new ResourceKey( parent.getSchema(), parent.getIdentifier(), map ); }
/** * Creates a <code>ResourceKey</code> based off the <code>String</code> representation of the key. The * <code>String</code> should have been created using the <code>serialize</code> method. * * @param bundleKey * @param stringKey the <code>String</code> representation of the <code>ResourceKey</code> @return a * <code>ResourceKey</code> which matches the <code>String</code> representation * @throws ResourceKeyCreationException indicates an error occurred in the creation or deserialization of the * <code>ResourceKey</code> */ public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { final ResourceKeyData resourceKeyData = ResourceKeyUtils.parse( stringKey ); // Validate the data if ( INNER_SCHEMA.equals( resourceKeyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of key does not contain correct schema" ); } return new ResourceKey( bundleKey, resourceKeyData.getSchema(), resourceKeyData.getIdentifier(), resourceKeyData.getFactoryParameters() ); }
map = parent.getFactoryParameters(); return new ResourceKey( parent.getSchema(), url, map ); } catch ( MalformedURLException e ) { throw new ResourceKeyCreationException( "Malformed value: " + path );
map = parent.getFactoryParameters(); return new ResourceKey( parent.getParent(), parent.getSchema(), entry, map );
@Test public void testInitialize() throws ReportDataFactoryException { DataFactoryContext dataFactoryContext = mock( DataFactoryContext.class ); Configuration conf = mock( Configuration.class ); ResourceBundleFactory bundleFactory = mock( ResourceBundleFactory.class ); ResourceManagerBackend resourceManagerBackend = mock( ResourceManagerBackend.class ); ResourceManager manager = new ResourceManager( resourceManagerBackend ); ResourceKey key = new ResourceKey( "schema", "identifier", null ); doReturn( conf ).when( dataFactoryContext ).getConfiguration(); doReturn( bundleFactory ).when( dataFactoryContext ).getResourceBundleFactory(); doReturn( manager ).when( dataFactoryContext ).getResourceManager(); doReturn( key ).when( dataFactoryContext ).getContextKey(); factory.initialize( dataFactoryContext ); assertThat( factory.getConfiguration(), is( equalTo( conf ) ) ); assertThat( factory.getResourceBundleFactory(), is( equalTo( bundleFactory ) ) ); assertThat( factory.getResourceManager(), is( equalTo( manager ) ) ); assertThat( factory.getContextKey(), is( equalTo( key ) ) ); assertThat( factory.getLocale(), is( equalTo( Locale.getDefault() ) ) ); }
ResourceManager resourceManager = new ResourceManager( resourceManagerBackend ); ResourceKey contentBase = new ResourceKey( "contentBase_schema", "contentBase_id", null ); ResourceKey elementSource = new ResourceKey( "elementSource_schema", "elementSource_id", null ); ResourceKey attributeValue = new ResourceKey( "attributeValue_schema", "attributeValue_id", null );
ResourceManager resourceManager = new ResourceManager( resourceManagerBackend ); ResourceKey contentBase = new ResourceKey( "contentBase_schema", "contentBase_id", null ); ResourceKey elementSource = new ResourceKey( "elementSource_schema", "elementSource_id", null ); ResourceKey attributeValue = new ResourceKey( "attributeValue_schema", "attributeValue_id", null );
ResourceManager resourceManager = new ResourceManager( resourceManagerBackend ); ResourceKey contentBase = new ResourceKey( "contentBase_schema", "contentBase_id", null ); ResourceKey elementSource = new ResourceKey( "elementSource_schema", "elementSource_id", null ); ResourceKey attributeValue = new ResourceKey( "attributeValue_schema", "attributeValue_id", null );