/** * Derives a new key from the given resource-key. Only keys for a hierarchical storage system (like file-systems or * URLs) can have derived keys. Since LibLoader 0.3.0 only hierarchical keys can be derived. For that, the deriving * path must be given as String. * <p/> * Before trying to derive the key, the system tries to interpret the path as absolute key-value. * * @param parent the parent key, must never be null * @param path the relative path, that is used to derive the key. * @return the derived key. * @throws ResourceKeyCreationException if deriving the key failed. */ public ResourceKey deriveKey( final ResourceKey parent, final String path ) throws ResourceKeyCreationException { return deriveKey( parent, path, null ); }
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; } }
private ResourceKey createKeyFromString( final ResourceManager resourceManager, final ResourceKey contextKey, final String file ) { try { if ( contextKey != null ) { return resourceManager.deriveKey( contextKey, file ); } } catch ( ResourceException re ) { // failed to load from context logger.debug( "Failed to load datasource as derived path: ", re ); } try { return resourceManager.createKey( new URL( file ) ); } catch ( ResourceException re ) { logger.debug( "Failed to load datasource as URL: ", re ); } catch ( MalformedURLException e ) { // } try { return resourceManager.createKey( new File( file ) ); } catch ( ResourceException re ) { // failed to load from context logger.debug( "Failed to load datasource as file: ", re ); } return null; } }
private ResourceKey createKeyFromString( final ResourceKey contextKey, final String file ) throws ResourceKeyCreationException { try { if ( contextKey != null ) { return deriveKey( contextKey, file ); } } catch ( ResourceException re ) { // failed to load from context logger.debug( "Failed to load datasource as derived path: ", re ); } try { return createKey( new URL( file ) ); } catch ( ResourceException re ) { logger.debug( "Failed to load datasource as URL: ", re ); } catch ( MalformedURLException e ) { // } try { return createKey( new File( file ) ); } catch ( ResourceException re ) { // failed to load from context logger.debug( "Failed to load datasource as file: ", re ); } return createKey( file ); } }
public static ResourceKey createURI( final String uri, final DocumentContext layoutProcess ) { try { final ResourceKey base = layoutProcess.getContextKey(); final ResourceManager resourceManager = layoutProcess.getResourceManager(); if ( base != null ) { try { return resourceManager.deriveKey( base, uri ); } catch ( ResourceKeyCreationException ex ) { // ignore .. } } return resourceManager.createKey( uri ); } catch ( Exception e ) { return null; } } }
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. }
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 ); } }
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(); } }
private void handleLinkNode( final Object styleResource, final ArrayList<ElementStyleRule> styleRules, final ArrayList<CSSCounterRule> counterRules ) { // do some external parsing // (Same as the <link> element of HTML) try { final String href = (String) styleResource; final ResourceKey baseKey = context.getContextKey(); final ResourceKey derivedKey; if ( baseKey == null ) { derivedKey = resourceManager.createKey( href ); } else { derivedKey = resourceManager.deriveKey( baseKey, String.valueOf( href ) ); } final ElementStyleDefinition styleSheet = parseStyleSheet( derivedKey, null ); if ( styleSheet == null ) { return; } addStyleRules( styleSheet, styleRules ); addCounterRules( styleSheet, counterRules ); } catch ( ResourceKeyCreationException e ) { e.printStackTrace(); } }
try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) );
try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) );
try { final ResourceKey path = resourceManager.deriveKey( contentBase, String.valueOf( attributeValue ) );
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 ); } }
private void handleLinkNode( final DocumentContext context, final StyleReference node, final ArrayList styleRules, final ArrayList pageRules, final ArrayList counterRules ) { // do some external parsing // (Same as the <link> element of HTML) try { final String href = node.getStyleContent(); final ResourceKey baseKey = context.getContextKey(); final ResourceKey derivedKey; if ( baseKey == null ) { derivedKey = resourceManager.createKey( href ); } else { derivedKey = resourceManager.deriveKey( baseKey, String.valueOf( href ) ); } final StyleSheet styleSheet = parseStyleSheet( derivedKey, null ); if ( styleSheet == null ) { return; } addStyleRules( styleSheet, styleRules ); addPageRules( styleSheet, pageRules ); addCounterRules( styleSheet, counterRules ); } catch ( ResourceKeyCreationException e ) { e.printStackTrace(); } }
/** * 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 ); } } }
/** * 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() ); } }
final ResourceKey target = resourceManager.deriveKey( source, file, map ); final DependencyCollector dc = rootHandler.getDependencyCollector();
final ResourceManager manager = getRootHandler().getResourceManager(); try { final ResourceKey derivedKey = manager.deriveKey( key, href ); final Resource resource = manager.create( derivedKey, null, DataFactory.class ); getRootHandler().getDependencyCollector().add( resource );
key = manager.createKey( uri ); } else { key = manager.deriveKey( source, uri );