/** * Creates a ResourceKey that carries no Loader-Parameters from the given object. * * @param data the key-data * @return the generated resource-key, never null. * @throws ResourceKeyCreationException if the key-creation failed. */ public ResourceKey createKey( final Object data ) throws ResourceKeyCreationException { return createKey( data, null ); }
public Resource createDirectly( final Object keyValue, final Class target ) throws ResourceLoadingException, ResourceCreationException, ResourceKeyCreationException { final ResourceKey key = createKey( keyValue ); return create( key, null, target ); }
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 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 ); } }
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; } }
/** * 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 MasterReport parseReportDirectly( final InputSource input, final URL contentBase ) throws ResourceKeyCreationException, ResourceCreationException, ResourceLoadingException { final ResourceManager manager = new ResourceManager(); 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 MasterReportXmlResourceFactory resourceFactory = new MasterReportXmlResourceFactory(); resourceFactory.initializeDefaults(); if ( contentBase != null ) { return (MasterReport) resourceFactory.parseDirectly( manager, input, manager.createKey( contentBase ), map ); } else { return (MasterReport) resourceFactory.parseDirectly( manager, input, null, map ); } }
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; }
final ResourceKey contextKey; if ( contentBase != null ) { contextKey = resourceManager.createKey( contentBase ); } else { contextKey = null; final ResourceKey key = resourceManager.createKey( bytes, map ); final Resource resource = resourceManager.create( key, contextKey, MasterReport.class ); return (MasterReport) resource.getResource();
IOUtils.getInstance().copyStreams( in, out ); return manager.createKey( out.toByteArray(), factoryParameters ); } finally { try {
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; } } }
private void handleStyleNode( final DocumentContext context, final StyleReference node, final ArrayList styleRules, final ArrayList pageRules, final ArrayList counterRules ) { // do some inline parsing // (Same as the <style> element of HTML) // we also accept preparsed content ... final String styleText = node.getStyleContent(); try { final byte[] bytes = styleText.getBytes( "UTF-8" ); final ResourceKey rawKey = resourceManager.createKey( bytes ); final ResourceKey baseKey = context.getContextKey(); final StyleSheet styleSheet = parseStyleSheet( rawKey, baseKey ); if ( styleSheet == null ) { return; } addStyleRules( styleSheet, styleRules ); addPageRules( styleSheet, pageRules ); addCounterRules( styleSheet, counterRules ); } catch ( UnsupportedEncodingException e ) { e.printStackTrace(); } catch ( ResourceKeyCreationException e ) { e.printStackTrace(); } }
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.createKey( attributeValue ); final boolean linked = BundleUtilities.isSameBundle( elementSource, path ) == false; return new ResourceReference[] { new ResourceReference( path, linked ) };
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(); } }
/** * This constructor exists for test-case use only. If you use this to process a real report, most of the settings of * the report will be ignored and your export will not work as expected. */ public DefaultProcessingContext() { outputProcessorMetaData = new GenericOutputProcessorMetaData(); resourceBundleFactory = new DefaultResourceBundleFactory(); configuration = ClassicEngineBoot.getInstance().getGlobalConfig(); resourceManager = new ResourceManager(); reportEnvironment = new CachingReportEnvironment( new DefaultReportEnvironment( configuration ) ); try { this.contentBase = resourceManager.createKey( new File( "." ) ); } catch ( ResourceKeyCreationException rkce ) { this.contentBase = null; } formulaContext = DefaultFormulaContextFactory.INSTANCE.create( resourceBundleFactory.getLocale(), resourceBundleFactory .getTimeZone() ); metaData = new MemoryDocumentMetaData(); compatibilityLevel = -1; }