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; }
if ( factoryKeys != null ) { map = new HashMap(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters();
/** * 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 ); }
/** * 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() ); }
/** * 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() ); }
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() ); } }
/** * 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(); }
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 ); }
if ( factoryKeys != null ) { map = new HashMap(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters();
( key.getSchema().toString(), url.toExternalForm(), key.getFactoryParameters() ); logger.debug( "Serialized Classloader Resource Key: [" + result + "]" ); return result;
if ( factoryKeys != null ) { map = new HashMap(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters();
if ( factoryKeys != null ) { map = new HashMap(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters();
/** * 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; }
/** * 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 ); }
if ( factoryKeys != null ) { map = new HashMap(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters();
public Resource create( final ResourceManager manager, final ResourceData data, final ResourceKey context ) throws ResourceCreationException, ResourceLoadingException { final ResourceKey key = data.getKey(); final Map factoryParameters = key.getFactoryParameters(); final boolean embedded = Boolean.TRUE.equals( factoryParameters.get( BaseFontResourceFactory.EMBEDDED ) ); final String encoding = String.valueOf( factoryParameters.get( BaseFontResourceFactory.ENCODING ) ); final String fontType = String.valueOf( factoryParameters.get( BaseFontResourceFactory.FONTNAME ) ); final DependencyCollector dc = new DependencyCollector( key, data.getVersion( manager ) ); final byte[] ttfAfm = data.getResource( manager ); byte[] pfb = null; if ( embedded && ( fontType.endsWith( ".afm" ) || fontType.endsWith( ".pfm" ) ) ) { final String pfbFileName = fontType.substring( 0, fontType.length() - 4 ) + ".pfb"; try { final ResourceKey pfbKey = manager.deriveKey( key, pfbFileName ); final ResourceData res = manager.load( pfbKey ); pfb = res.getResource( manager ); dc.add( pfbKey, res.getVersion( manager ) ); } catch ( ResourceException e ) { // ignore .. } } try { final BaseFont baseFont = BaseFont.createFont( fontType, encoding, embedded, false, ttfAfm, pfb ); return new CompoundResource( key, dc, baseFont, getFactoryType() ); } catch ( Exception e ) { throw new ResourceCreationException( "Failed to create the font " + fontType, e ); } }
if ( factoryKeys != null ) { map = new HashMap<ParameterKey, Object>(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters(); try { final ZipReadRepository repository = (ZipReadRepository) parent.getFactoryParameters().get( new FactoryParameterKey( "repository" ) ); if ( RepositoryUtilities.isExistsEntity( repository, RepositoryUtilities.split( entry, "/" ) ) == false ) { throw new ResourceKeyCreationException( "The key does not exist: " + entry );
if ( factoryKeys != null ) { map = new HashMap<ParameterKey, Object>(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters(); try { final FileRepository repository = (FileRepository) parent.getFactoryParameters().get( new FactoryParameterKey( "repository" ) ); if ( RepositoryUtilities.isExistsEntity( repository, RepositoryUtilities.split( entry, "/" ) ) == false ) { throw new ResourceKeyCreationException( "The key does not exist: " + entry );
if ( factoryKeys != null ) { map = new HashMap<ParameterKey, Object>(); map.putAll( parent.getFactoryParameters() ); map.putAll( factoryKeys ); } else { map = parent.getFactoryParameters();
parent.getFactoryParameters().get( new FactoryParameterKey( "repository-loader" ) ); try { final Repository repository = (Repository) parent.getFactoryParameters().get( new FactoryParameterKey( "repository" ) ); if ( RepositoryUtilities.isExistsEntity( repository, RepositoryUtilities.split( path, "/" ) ) == false ) { throw new ResourceKeyCreationException( "The key does not exist: " + path );