private boolean isResourceDataCacheable( final ResourceData data ) { try { return data.getVersion( this ) != -1; } catch ( ResourceLoadingException e ) { return false; } }
public long getVersion( final ResourceManager caller ) throws ResourceLoadingException { return data.getVersion( caller ); }
public DefaultResourceDataCacheEntry( final ResourceData data, final ResourceManager manager ) throws ResourceLoadingException { if ( data == null ) { throw new NullPointerException(); } this.version = data.getVersion( manager ); this.data = data; }
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { final long version = data.getVersion( caller ); final Image image = Toolkit.getDefaultToolkit().createImage( data.getResource( caller ) ); return new SimpleResource( data.getKey(), image, Image.class, version ); } }
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { final long version = data.getVersion( caller ); final Image image = Toolkit.getDefaultToolkit().createImage( data.getResource( caller ) ); return new SimpleResource( data.getKey(), image, Image.class, version ); } }
public long getVersion( final ResourceManager caller ) throws ResourceLoadingException { final ResourceKey parentKey = key.getParent(); final ResourceData data = caller.load( parentKey ); return data.getVersion( caller ); } }
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { final long version = data.getVersion( caller ); final Image image = Toolkit.getDefaultToolkit().createImage( data.getResource( caller ) ); return new SimpleResource( data.getKey(), image, Image.class, version ); } }
public Resource create( final ResourceManager manager, final ResourceData data, final ResourceKey context ) throws ResourceCreationException, ResourceLoadingException { try { final Properties properties = new Properties(); final InputStream stream = data.getResourceAsStream( manager ); try { properties.load( stream ); } finally { stream.close(); } return new SimpleResource( data.getKey(), properties, Properties.class, data.getVersion( manager ) ); } catch ( IOException e ) { throw new ResourceLoadingException( "Failed to load the properties file.", e ); } }
private boolean isValidData( final ResourceDataCacheEntry cached, final ResourceData data ) throws ResourceLoadingException { // check, whether it is valid. if ( cached.getStoredVersion() < 0 ) { // a non versioned entry is always valid. (Maybe this is from a Jar-URL?) return true; } final long version = data.getVersion( this ); if ( version < 0 ) { // the system is no longer able to retrieve the version information? // (but versioning information must have been available in the past) // oh, that's bad. Assume the worst and re-read the data. return false; } if ( cached.getStoredVersion() == version ) { return true; } else { return false; } }
/** * Creates a new InputSource using the given resource-data and resource-manager as source. * * @param data the resource-data object holding the raw-data. * @param caller the resource manager that is loading the current resource. * @throws ResourceLoadingException if an error occurs. * @see #setPublicId * @see #setSystemId * @see #setByteStream * @see #setCharacterStream * @see #setEncoding */ public ResourceDataInputSource( final ResourceData data, final ResourceManager caller ) throws ResourceLoadingException { if ( data == null ) { throw new NullPointerException( "Data must not be null" ); } if ( caller == null ) { throw new NullPointerException( "ResourceManager must not be null" ); } this.data = data; this.version = data.getVersion( caller ); this.caller = caller; final URL url = caller.toURL( data.getKey() ); if ( url != null ) { setSystemId( url.toExternalForm() ); } }
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; }
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 ); } }
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { try { final long version = data.getVersion( caller ); final InputStream stream = data.getResourceAsStream( caller ); try { final WmfFile wmfFile = new WmfFile( stream, -1, -1 ); return new SimpleResource( data.getKey(), wmfFile, DrawableWrapper.class, version ); } finally { stream.close(); } } catch ( IOException e ) { throw new ResourceLoadingException( "Failed to process WMF file", e ); } }
throws ResourceLoadingException { try { final long version = data.getVersion( caller ); final HeadlessSVGUserAgent userAgent = new HeadlessSVGUserAgent(); final DocumentLoader loader = new DocumentLoader( userAgent );
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { try { final long version = data.getVersion( caller ); final InputStream stream = data.getResourceAsStream( caller ); try { final WmfFile wmfFile = new WmfFile( stream, -1, -1 ); final Image image = wmfFile.replay(); return new SimpleResource( data.getKey(), image, Image.class, version ); } finally { stream.close(); } } catch ( IOException e ) { throw new ResourceLoadingException( "Failed to process WMF file", e ); } }
public Resource create( final ResourceManager manager, final ResourceData data, final ResourceKey context ) throws ResourceCreationException, ResourceLoadingException { try { final InputStream in = data.getResourceAsStream( manager ); final ObjectInputStream oin = new ObjectInputStream( in ); try { final Object ob = oin.readObject(); // yes, that will be more generic in the future ... if ( ob instanceof External8BitEncodingData == false ) { throw new ResourceCreationException( "This is no 8Bit Encoding data" ); } final External8BitEncodingData encData = (External8BitEncodingData) ob; final External8BitEncodingCore encCore = new External8BitEncodingCore( encData ); return new SimpleResource( data.getKey(), encCore, getFactoryType(), data.getVersion( manager ) ); } finally { oin.close(); } } catch ( IOException e ) { throw new ResourceLoadingException( "Failed to load resource", e ); } catch ( ClassNotFoundException e ) { throw new ResourceCreationException ( "Missing class definition: Failed to create encoding." ); } }
db.setErrorHandler( new LoggingErrorHandler() ); final ResourceDataInputSource input = new ResourceDataInputSource( data, manager ); return new DomResource( data.getKey(), db.parse( input ), data.getVersion( manager ) ); } catch ( ParserConfigurationException e ) { throw new ResourceCreationException( "Unable to initialize the XML-Parser", e );
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceCreationException, ResourceLoadingException { final long version = data.getVersion( caller ); final byte[] resource = data.getResource( caller ); final Image image; try { image = createImage( resource ); } catch ( IOException e ) { throw new ResourceCreationException( "Failed to load the image.", e ); } if ( image == null ) { throw new ResourceCreationException( "Failed to load the image. ImageIO#read returned null" ); } return new SimpleResource( data.getKey(), image, Image.class, version ); }
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { try { final long version = data.getVersion( caller ); final HeadlessSVGUserAgent userAgent = new HeadlessSVGUserAgent(); final DocumentLoader loader = new DocumentLoader( userAgent ); final ResourceKey key = data.getKey(); URL url = caller.toURL( key ); if ( url == null ) { url = new File( "." ).toURI().toURL(); } final SVGDocument document = (SVGDocument) loader.loadDocument ( url.toURI().toASCIIString(), data.getResourceAsStream( caller ) ); final BridgeContext ctx = new BridgeContext( userAgent, loader ); final GVTBuilder builder = new GVTBuilder(); final GraphicsNode node = builder.build( ctx, document ); return new SimpleResource( data.getKey(), new SVGDrawable( node ), DrawableWrapper.class, version ); } catch ( IOException e ) { throw new ResourceLoadingException( "Failed to process SVG file", e ); } catch ( URISyntaxException e ) { throw new ResourceLoadingException( "Failed to process SVG file", e ); } }
public Resource create( final ResourceManager manager, ResourceData data, final ResourceKey context ) throws ResourceCreationException, ResourceLoadingException { if ( data instanceof CachingResourceBundleData ) { // todo: Friggin' cheap hack final CachingResourceBundleData cachingResourceBundleData = (CachingResourceBundleData) data; data = cachingResourceBundleData.getBackend(); } if ( data instanceof RepositoryResourceBundleData == false ) { data = manager.loadResourceBundle( data.getKey() ); if ( data instanceof CachingResourceBundleData ) { // todo: Friggin' cheap hack 2 final CachingResourceBundleData cachingResourceBundleData = (CachingResourceBundleData) data; data = cachingResourceBundleData.getBackend(); } } if ( data instanceof RepositoryResourceBundleData == false ) { throw new ContentNotRecognizedException( "No valid handler for the given content." ); } final RepositoryResourceBundleData bdata = (RepositoryResourceBundleData) data; final Repository repository = bdata.getRepository(); try { final StaticDocumentBundle bundle = new StaticDocumentBundle( repository, manager, bdata.getBundleKey() ); return new SimpleResource( data.getKey(), bundle, getFactoryType(), data.getVersion( manager ) ); } catch ( ResourceException e ) { throw new ResourceCreationException( "Unable to interpret document-bundle", e ); } }