public Resource createDirectly( final Object keyValue, final Class target ) throws ResourceLoadingException, ResourceCreationException, ResourceKeyCreationException { final ResourceKey key = createKey( keyValue ); return create( key, null, target ); }
public Resource create( final ResourceKey key, final ResourceKey context ) throws ResourceLoadingException, ResourceCreationException { return create( key, context, (Class[]) null ); }
final Resource resource = resManager.create( key, contentBase, target ); final Object resourceContent = resource.getResource(); if ( resourceContent instanceof Element ) {
public Resource create( final ResourceKey key, final ResourceKey context, final Class target ) throws ResourceLoadingException, ResourceCreationException { if ( target == null ) { throw new NullPointerException( "Target must not be null" ); } if ( key == null ) { throw new NullPointerException( "Key must not be null." ); } return create( key, context, new Class[] { target } ); }
/** * Parses the report from a given URL. * * @param file * the report definition location. * @param contentBase * 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. */ private MasterReport parse( final URL file, final URL contentBase ) throws ResourceException { final ResourceManager resourceManager = new ResourceManager(); final ResourceKey contextKey = resourceManager.createKey( contentBase ); // Build the main key. That key also contains all context/parse-time // parameters as they will influence the resulting report. It is not // wise to keep caching independent from that. final HashMap map = new HashMap(); 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 = resourceManager.createKey( file, map ); final Resource resource = resourceManager.create( key, contextKey, MasterReport.class ); return (MasterReport) resource.getResource(); }
private StyleSheet parseStyleSheet( final ResourceKey key, final ResourceKey context ) { try { final Resource resource = resourceManager.create ( key, context, StyleSheet.class ); return (StyleSheet) resource.getResource(); } catch ( ResourceException e ) { // Log.info("Unable to parse StyleSheet: " + e.getLocalizedMessage()); } return null; }
final Resource resource = resourceManager.create( key, contextKey, MasterReport.class ); return (MasterReport) resource.getResource();
private ElementStyleDefinition parseStyleSheet( final ResourceKey key, final ResourceKey context ) { try { final Resource resource = resourceManager.create( key, context, ElementStyleDefinition.class ); return (ElementStyleDefinition) resource.getResource(); } catch ( ResourceException e ) { // Log.info("Unable to parse StyleSheet: " + e.getLocalizedMessage()); } return null; }
public static CSSResourceValue loadResource( final DocumentContext process, final Object value, final Class[] type ) throws FunctionEvaluationException { // ok, this is going to be expensive. Kids, you dont wanna try this at home ... final ResourceManager manager = process.getResourceManager(); final ResourceKey baseKey = process.getContextKey(); try { final ResourceKey key; if ( value instanceof ResourceKey ) { key = (ResourceKey) value; } else if ( baseKey == null ) { key = manager.createKey( value ); } else if ( value instanceof String ) { key = manager.deriveKey( baseKey, (String) value ); } else { throw new FunctionEvaluationException ( "Failed to create URI: Resource loading failed: Key not derivable" ); } final Resource res = manager.create( key, baseKey, type ); return new CSSResourceValue( res ); } catch ( Exception e ) { throw new FunctionEvaluationException ( "Failed to create URI: Resource loading failed: " + e.getMessage(), e ); } }
public StaticDocumentMetaData( final ResourceManager resourceManager, final ResourceKey bundleKey ) throws ResourceException { if ( resourceManager == null ) { throw new NullPointerException(); } if ( bundleKey == null ) { throw new NullPointerException(); } this.resourceManager = resourceManager; this.bundleKey = bundleKey; // A bundle without a manifest is not valid. final ResourceKey manifestDataKey = resourceManager.deriveKey( bundleKey, "/META-INF/manifest.xml" ); final Resource manifestDataResource = resourceManager.create( manifestDataKey, null, BundleManifest.class ); manifest = (BundleManifest) manifestDataResource.getResource(); metaData = createMetaData( resourceManager, bundleKey ); bundleType = readBundleType(); if ( bundleType == null ) { bundleType = manifest.getMimeType( "/" ); } // bundle type can still be null. }
/** * 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(); }
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(); } }
final Resource resource = resourceManager.create( sourceURL, null, Image.class ); return (Image) resource.getResource(); } catch ( ResourceException e ) {
public Encoding getEncoding( final String name ) { final String key = normalizeEncodingName( name ); final String manual = (String) encodingsMapping.get( key ); if ( manual != null ) { // we tested the instantiation during the initialization, // so we can be sure that no errors appear here return (Encoding) ObjectUtilities.loadAndInstantiate ( manual, EncodingRegistry.class, Encoding.class ); } final ResourceKey generated = (ResourceKey) generatedMapping.get( key ); if ( generated != null ) { try { final Resource res = manager.create( generated, null, Encoding.class ); final Object o = res.getResource(); if ( o instanceof EncodingCore ) { return new ExternalEncoding( name, (EncodingCore) o, res ); } } catch ( Exception e ) { // fall back ... logger.warn( "Failed to create external-encoding instance for key " + key, e ); } } if ( isEncodingSupportedJVM( name ) ) { return new BuiltInJavaEncoding( name, true ); } else if ( isEncodingSupportedJVM( key ) ) { return new BuiltInJavaEncoding( key, true ); } else { return new Ascii(); } }
final Resource resource = resourceManager.create( sourceURL, null, Image.class ); final Image image = (Image) resource.getResource(); drawImage( content, image );
/** * Starts parsing. * * @param attrs * the attributes. * @throws SAXException * if there is a parsing error. */ protected void startParsing( final Attributes attrs ) throws SAXException { super.startParsing( attrs ); final ResourceManager resourceManager = getRootHandler().getResourceManager(); final ResourceKey context = getRootHandler().getContext(); final Configuration configuration = ClassicEngineBoot.getInstance().getGlobalConfig(); final Iterator keys = configuration.findPropertyKeys( ElementMetaDataParser.GLOBAL_INCLUDES_PREFIX ); while ( keys.hasNext() ) { final String key = (String) keys.next(); final String href = configuration.getConfigProperty( key ); if ( StringUtils.isEmpty( href, true ) ) { continue; } try { final ResourceKey resourceKey = resourceManager.deriveKey( context, href ); final Resource resource = resourceManager.create( resourceKey, null, GlobalMetaDefinition.class ); globalMetaDefinition.merge( (GlobalMetaDefinition) resource.getResource() ); } catch ( ResourceException e ) { logger.warn( "Failed to parse included global definitions: " + getLocator(), e ); } } }
final Resource resource = resourceManager.create( url, null, Image.class ); image = (Image) resource.getResource(); } catch ( final ResourceException e ) {
/** * Starts parsing. * * @param attrs * the attributes. * @throws SAXException * if there is a parsing error. */ protected void startParsing( final Attributes attrs ) throws SAXException { final String href = attrs.getValue( getUri(), "src" ); if ( href == null ) { throw new ParseException( "Required attribute 'src' is missing", getLocator() ); } final ResourceManager resourceManager = getRootHandler().getResourceManager(); final ResourceKey context = getRootHandler().getContext(); try { final ResourceKey resourceKey = resourceManager.deriveKey( context, href ); final Resource resource = resourceManager.create( resourceKey, null, GlobalMetaDefinition.class ); result = (GlobalMetaDefinition) resource.getResource(); } catch ( ResourceException e ) { throw new ParseException( "Failed to parse included global definitions", e, getLocator() ); } if ( globalMetaDefinition != null ) { globalMetaDefinition.merge( result ); } }
/** * Parses an external file using LibLoader and returns the parsed result as an object of type * <code>targetClass</code>. The file is given as relative pathname (relative to the current source file). The current * helper-methods are used as parse-parameters for the external parsing. * * @param file the file to be parsed. * @param targetClass the target type of the parse operation. * @param map the map of parse parameters. * @return the result, never null. * @throws ParseException if parsing the result failed for some reason. * @throws ResourceLoadingException if there was an IO error loading the resource. * @see #deriveParseParameters() */ protected Object performExternalParsing( final String file, final Class targetClass, final Map map ) throws ParseException, ResourceLoadingException { try { final ResourceManager resourceManager = rootHandler.getResourceManager(); final ResourceKey source = rootHandler.getSource(); final ResourceKey target = resourceManager.deriveKey( source, file, map ); final DependencyCollector dc = rootHandler.getDependencyCollector(); final Resource resource = resourceManager.create( target, rootHandler.getContext(), targetClass ); dc.add( resource ); return resource.getResource(); } catch ( ResourceLoadingException rle ) { throw rle; } catch ( ResourceException e ) { throw new ParseException( "Failure while loading data: " + file, e, getLocator() ); } }
try { final ResourceKey derivedKey = manager.deriveKey( key, href ); final Resource resource = manager.create( derivedKey, null, DataFactory.class ); getRootHandler().getDependencyCollector().add( resource ); dataFactory = (DataFactory) resource.getResource();