public ZipEntryKey( final ResourceManager manager, final File zipFile, final String entryName ) throws ResourceKeyCreationException, ResourceLoadingException { if ( zipFile == null ) { throw new NullPointerException(); } if ( entryName == null ) { throw new NullPointerException(); } this.zipFile = manager.load( manager.createKey( zipFile ) ); this.entryName = entryName; }
public ZipEntryKey( final ResourceManager manager, final URL zipFile, final String entryName ) throws ResourceKeyCreationException, ResourceLoadingException { if ( zipFile == null ) { throw new NullPointerException(); } if ( entryName == null ) { throw new NullPointerException(); } this.zipFile = manager.load( manager.createKey( zipFile ) ); this.entryName = entryName; }
public ZipEntryKey( final ResourceManager manager, final String zipFile, final String entryName ) throws ResourceKeyCreationException, ResourceLoadingException { if ( zipFile == null ) { throw new NullPointerException(); } if ( entryName == null ) { throw new NullPointerException(); } this.zipFile = manager.load( manager.createKey( zipFile ) ); this.entryName = entryName; }
private String readBundleType() { try { final ResourceKey mimeKey = this.resourceManager.deriveKey( bundleKey, "mimetype" ); final ResourceData mimeData = this.resourceManager.load( mimeKey ); final byte[] data = mimeData.getResource( this.resourceManager ); return new String( data, "ASCII" ); } catch ( Exception cioe ) { return null; } }
public void readFullyAt( final long position, final byte[] buffer, final int length ) throws IOException { if ( rawData == null ) { try { rawData = loader.load( source ); } catch ( ResourceLoadingException e ) { throw new IOException( "Failed to load the raw data." ); } } final int iPos = (int) ( position & 0x7fffffff ); try { rawData.getResource( loader, buffer, iPos, length ); } catch ( ResourceLoadingException e ) { throw new IOException( "Unable to load data: " + e.getMessage() ); } } //
public long getVersion( final ResourceManager caller ) throws ResourceLoadingException { final ResourceKey parentKey = key.getParent(); final ResourceData data = caller.load( parentKey ); return data.getVersion( caller ); } }
public int readAt( final long position ) throws IOException { if ( rawData == null ) { try { rawData = loader.load( source ); } catch ( ResourceLoadingException e ) { throw new IOException( "Failed to load the raw data." ); } } final int iPos = (int) ( position & 0x7fffffff ); final byte[] buffer = new byte[ 1 ]; final long length = rawData.getLength(); if ( ( length > -1 ) && ( iPos >= length ) ) { return -1; } try { rawData.getResource( loader, buffer, iPos, 1 ); return buffer[ 0 ]; } catch ( IndexOutOfBoundsException e ) { return -1; } catch ( ResourceLoadingException e ) { throw new IOException( "Failed to read stream." ); } }
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; }
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 boolean isResourceUnchanged( final ResourceManager frontEnd, final Resource resource ) throws ResourceLoadingException { if ( frontEnd == null ) { throw new NullPointerException(); } if ( resource == null ) { throw new NullPointerException(); } final ResourceKey[] deps = resource.getDependencies(); for ( int i = 0; i < deps.length; i++ ) { final ResourceKey dep = deps[ i ]; final long version = resource.getVersion( dep ); if ( version == -1 ) { // non-versioning key, ignore it. continue; } final ResourceData data = frontEnd.load( dep ); if ( data.getVersion( frontEnd ) != version ) { // oh, my bad, an outdated or changed entry. // We have to re-read the whole thing. return false; } } // all versions have been confirmed to be valid. Nice, we can use the // cached product. return true; }
throw new IllegalArgumentException(); final ResourceData resourceData = manager.load( source );
final ResourceData resourceData = resourceManager.load( dataKey ); String contentType = (String) resourceData.getAttribute( ResourceData.CONTENT_TYPE ); if ( contentType == null ) {
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 ); } }
try { final ResourceKey resourceKey = resourceManager.createKey( ttfCache ); final ResourceData data = resourceManager.load( resourceKey ); final InputStream stream = data.getResourceAsStream( resourceManager );
final ResourceData resourceData = resourceManager.load( source ); final String mimeType = queryMimeType( resourceData ); if ( isValidImage( mimeType ) ) {
public Object evalFile( final String file, final String defaultScriptLanguage, final String encoding ) throws ScriptException { final ResourceKey resourceKey = createKeyFromString( resourceManager, contextKey, file ); if ( resourceKey == null ) { throw new ScriptException( "Unable to load script" ); } try { final ResourceData loadedResource = resourceManager.load( resourceKey ); final byte[] resource = loadedResource.getResource( resourceManager ); return eval( new String( resource, encoding ), defaultScriptLanguage ); } catch ( ResourceLoadingException e ) { throw new ScriptException( e ); } catch ( UnsupportedEncodingException e ) { throw new ScriptException( e ); } }
private BundleMetaData createMetaData( final ResourceManager resourceManager, final ResourceKey bundleKey ) throws ResourceException { try { final ResourceKey metaDataKey = resourceManager.deriveKey( bundleKey, "/meta.xml" ); // make sure we trigger a resource-loading exception .. final ResourceData metaDataBytes = resourceManager.load( metaDataKey ); final Resource metaDataResource = resourceManager.create( metaDataKey, null, BundleMetaData.class ); return (BundleMetaData) metaDataResource.getResource(); } catch ( ResourceKeyCreationException e ) { return new DefaultBundleMetaData(); } catch ( ResourceLoadingException e ) { return new DefaultBundleMetaData(); } }
instance = maybeImage; } else { final ResourceData data = resourceManager.load( resource ); instance = com.lowagie.text.Image.getInstance( data.getResource( resourceManager ) ); imageCache.put( resource, instance );
final ResourceData loadedData = load( key ); final Resource newResource; if ( loadedData instanceof ResourceBundleData ) {