public static MasterReport loadMasterReport( String sourceFilename ) throws Exception { ResourceManager manager = new ResourceManager(); manager.registerDefaults(); FileObject fileObject = KettleVFS.getFileObject( sourceFilename ); URL url = new URL( fileObject.getName().getURI() ); Resource resource = manager.createDirectly( url, MasterReport.class ); MasterReport report = (MasterReport) resource.getResource(); return report; }
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 DocumentBundle getBundle( final File file ) throws ResourceException { if ( file == null ) { throw new NullPointerException(); } final ResourceManager resManager = new ResourceManager(); final Resource directly = resManager.createDirectly( file, DocumentBundle.class ); return (DocumentBundle) directly.getResource(); }
public ResourceManager getResourceManager() { if ( resourceManager == null ) { resourceManager = new ResourceManager(); resourceManager.registerDefaults(); } return resourceManager; }
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 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(); }
manager = new ResourceManager(); final ResourceKey resourceKey = manager.deriveKey( baseKey, propsName ); final ResourceData resource = manager.load( resourceKey ); final ResourceKey resourceKey = manager.createKey( "res://" + propsName ); // NON-NLS final ResourceData resource = manager.load( resourceKey );
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; }
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(); } }
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 ); } }
@Test public void testExportReportWithSupportedLocale() { when( masterReport.getConfiguration() ).thenReturn( mock( Configuration.class ) ); when( masterReport.getResourceManager() ).thenReturn( new ResourceManager() ); when( swingGuiContext.getLocale() ).thenReturn( Locale.US ); when( swingGuiContext.getStatusListener() ).thenReturn( mock( StatusListener.class ) ); Runnable exportTask = new ReportExportTask( masterReport, swingGuiContext, targetPath, createParentFolder ) { protected ReportProcessor createReportProcessor( OutputStream fout ) throws Exception { PdfOutputProcessor outputProcessor = new PdfOutputProcessor( masterReport.getConfiguration(), fout, masterReport.getResourceManager() ); return new PageableReportProcessor( masterReport, outputProcessor ); } }; assertNotNull( exportTask ); exportTask.run(); assertThat( swingGuiContext.getStatusType(), not( StatusType.ERROR ) ); }
private EncodingRegistry() { this.manager = new ResourceManager(); this.manager.registerFactoryCache(); this.manager.registerDataCache(); this.manager.registerDefaultLoaders(); this.manager.registerFactory( new EncodingFactory() ); this.manager.registerFactory( new PropertiesResourceFactory() ); this.encodingsMapping = new HashMap(); this.generatedMapping = new HashMap(); this.fallbackMapping = new HashMap(); this.aliases = new HashMap(); }
protected void loadFromCache( final String encoding, final String filename ) { final ResourceManager resourceManager = new ResourceManager(); final File location = createStorageLocation(); if ( location == null ) { final ResourceKey resourceKey = resourceManager.createKey( ttfCache ); final ResourceData data = resourceManager.load( resourceKey ); final InputStream stream = data.getResourceAsStream( resourceManager );
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 ); } }
public Resource create( final ResourceKey key, final ResourceKey context ) throws ResourceLoadingException, ResourceCreationException { return create( key, context, (Class[]) null ); }
/** * 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() ); } }
/** * 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 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; } }
if ( urlImage.isLoadable() && isSupportedImageFormat( url ) ) { try { final ResourceData data = resourceManager.load( url ); final byte[] imageData = data.getResource( resourceManager ); final String mimeType = queryMimeType( imageData ); final URL maybeRealURL = resourceManager.toURL( url ); if ( maybeRealURL != null ) { final String originalFileName = IOUtils.getInstance().getFileName( maybeRealURL ); if ( url != null ) { try { final Resource resource = resourceManager.createDirectly( url, Image.class ); awtImage = (Image) resource.getResource(); } catch ( ResourceException e ) { final String originalFileName; if ( url != null ) { final URL maybeRealURL = resourceManager.toURL( url ); if ( maybeRealURL != null ) { originalFileName = IOUtils.getInstance().getFileName( maybeRealURL );