private boolean parseStyles( final String stylefile ) throws ParseException { try { final Map parameters = deriveParseParameters(); parameters.put( new FactoryParameterKey( ReportParserUtil.HELPER_OBJ_REPORT_NAME ), report ); parameters.put( new FactoryParameterKey( ReportParserUtil.INCLUDE_PARSING_KEY ), ReportParserUtil.INCLUDE_PARSING_VALUE ); final MasterReport report = (MasterReport) performExternalParsing( stylefile, MasterReport.class, parameters ); return report == this.report; } catch ( ResourceLoadingException e ) { ContentRootElementHandler.logger.warn( "Unable to parse the parameter for this bundle from file: " + stylefile ); return false; } }
if ( key instanceof FactoryParameterKey ) { final FactoryParameterKey fkey = (FactoryParameterKey) key; entrySb.append( innerQuoter.doQuoting( "f:" + fkey.getName() ) ); } else if ( key instanceof LoaderParameterKey ) { final LoaderParameterKey fkey = (LoaderParameterKey) key;
private boolean parseLayout( final String layout ) throws ParseException { try { final Map parameters = deriveParseParameters(); parameters.put( new FactoryParameterKey( ReportParserUtil.HELPER_OBJ_REPORT_NAME ), report ); parameters.put( new FactoryParameterKey( ReportParserUtil.INCLUDE_PARSING_KEY ), ReportParserUtil.INCLUDE_PARSING_VALUE ); final MasterReport report = (MasterReport) performExternalParsing( layout, MasterReport.class, parameters ); return report == this.report; } catch ( ResourceLoadingException e ) { ContentRootElementHandler.logger.warn( "Unable to parse the parameter for this bundle from file: " + layout ); return false; } }
if ( o instanceof FactoryParameterKey ) { final FactoryParameterKey fpk = (FactoryParameterKey) o; handler.setHelperObject( fpk.getName(), parameters.get( fpk ) );
public RepositoryResourceBundleLoader( final Repository repository, final ResourceKey outsideContextKey ) { if ( repository == null ) { throw new NullPointerException(); } this.repository = repository; final HashMap<FactoryParameterKey, Object> map = new HashMap<FactoryParameterKey, Object>(); map.put( new FactoryParameterKey( "repository" ), repository ); map.put( new FactoryParameterKey( "repository-loader" ), this ); this.bundleKey = new ResourceKey( outsideContextKey, SCHEMA, new Object(), map ); final String bundleType = BundleUtilities.getBundleType( repository ); final String bundleMapping = BundleUtilities.getBundleMapping( bundleType ); if ( bundleMapping == null ) { throw new IllegalStateException( "Invalid configuration: No Bundle-Mapping for the bundle-type " + bundleType ); } this.mainKey = new ResourceKey( bundleKey, INNER_SCHEMA, bundleMapping, null ); }
if ( o instanceof FactoryParameterKey ) { final FactoryParameterKey fpk = (FactoryParameterKey) o; handler.setHelperObject( fpk.getName(), parameters.get( fpk ) );
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 ); } }
while ( it.hasNext() ) { final String name = (String) it.next(); map.put( new FactoryParameterKey( name ), helperObjects.get( name ) );
/** * Creates a working copy of the current parse state. * * @return the derived parse-parameters. * @noinspection ObjectAllocationInLoop as this is a cloning operation. */ protected Map deriveParseParameters() { final RootXmlReadHandler rootHandler = getRootHandler(); final HashMap map = new HashMap(); final String[] names = rootHandler.getHelperObjectNames(); final int length = names.length; for ( int i = 0; i < length; i++ ) { final String name = names[ i ]; final FactoryParameterKey key = new FactoryParameterKey( name ); map.put( key, rootHandler.getHelperObject( name ) ); } return map; } }
/** * Parsing the meta-data is error-resistant. If parsing the meta-data fails for a "file-not-found-error", the parse * continues. Meta-data parsing is not mergeable - there is only one source for the meta-data of a report-bundle. * * @return true, if the meta-data bundle has been updated, false otherwise. * @throws ParseException * if the parsing fails. */ private boolean parseDataSchema() throws ParseException { try { final Map parameters = deriveParseParameters(); parameters.put( new FactoryParameterKey( ReportParserUtil.HELPER_OBJ_REPORT_NAME ), null ); final DataSchemaDefinition metaData = (DataSchemaDefinition) performExternalParsing( "dataschema.xml", DataSchemaDefinition.class, parameters ); report.setDataSchemaDefinition( metaData ); return true; } catch ( ResourceLoadingException e ) { ContentRootElementHandler.logger.warn( "Unable to parse the dataschema for this bundle." ); return false; } }
/** * 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(); }
/** * Tries to load the bundle. If the key does not point to a usable resource-bundle, this method returns null. The * Exception is only thrown if the bundle is not readable because of IO-Errors. * <p/> * A resource-bundle loader should only load the bundle for the key itself, never for any of the derived subkeys. It * is the ResourceManager's responsibility to search the key's hierachy for the correct key. * * @param key the resource key pointing to the bundle. * @return the loaded bundle or null, if the resource was not understood. * @throws org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException if something goes wrong. */ public ResourceBundleData loadBundle( final ResourceManager resourceManager, final ResourceKey key ) throws ResourceLoadingException { if ( isSupportedKey( key ) == false ) { return null; } final RepositoryResourceBundleLoader o = (RepositoryResourceBundleLoader) key.getFactoryParameters().get( new FactoryParameterKey( "repository-loader" ) ); return o.loadBundle( resourceManager, key ); }
map.put( new FactoryParameterKey( "repository" ), repository ); map.put( new FactoryParameterKey( "repository-loader" ), this );
public ResourceKey createResourceKey( final String entryName, final Map factoryParameters ) throws ResourceKeyCreationException { if ( entryName == null ) { throw new NullPointerException(); } final ResourceKey bundleKey = getBundleMainKey().getParent(); final ResourceBundleLoader o = (ResourceBundleLoader) bundleKey.getFactoryParameters().get( new FactoryParameterKey( "repository-loader" ) ); if ( o == null ) { throw new ResourceKeyCreationException( "Unable to create a inner-bundle key, no loader available." ); } return o.deriveKey( getBundleMainKey(), entryName, factoryParameters ); }
final String keyString = innerTokenizer.nextToken(); if ( keyString.startsWith( "f:" ) ) { key = new FactoryParameterKey( keyString.substring( 2 ) ); } else if ( keyString.startsWith( "l:" ) ) { key = new LoaderParameterKey( keyString.substring( 2 ) );
while ( it.hasNext() ) { final String name = (String) it.next(); map.put( new FactoryParameterKey( name ), helperObjects.get( name ) );
private boolean parseSettings( final String settingsFile ) throws ParseException { try { final Map parameters = deriveParseParameters(); parameters.put( new FactoryParameterKey( ReportParserUtil.HELPER_OBJ_REPORT_NAME ), null ); final BundleSettings settings = (BundleSettings) performExternalParsing( settingsFile, BundleSettings.class, parameters ); // todo: Apply settings final Configuration configuration = settings.getConfiguration(); final Enumeration configProperties = configuration.getConfigProperties(); while ( configProperties.hasMoreElements() ) { final String key = (String) configProperties.nextElement(); final String value = configuration.getConfigProperty( key ); if ( value != null ) { report.getReportConfiguration().setConfigProperty( key, value ); } } return true; } catch ( ResourceLoadingException e ) { ContentRootElementHandler.logger.warn( "Unable to parse the settingsFile for this bundle from file: " + settingsFile ); return false; } }
/** * 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(); }
map.put( new FactoryParameterKey( "repository" ), zipReadRepository ); map.put( new FactoryParameterKey( "repository-loader" ), this );
/** * Starts parsing. * * @param attrs * the attributes. * @throws org.xml.sax.SAXException * if there is a parsing error. */ protected void startParsing( final Attributes attrs ) throws SAXException { final String file = attrs.getValue( getUri(), "href" ); if ( file != null ) { final Map parameters = deriveParseParameters(); parameters.put( new FactoryParameterKey( ReportParserUtil.HELPER_OBJ_REPORT_NAME ), null ); parameters.put( new FactoryParameterKey( ReportParserUtil.INCLUDE_PARSING_KEY ), ReportParserUtil.INCLUDE_PARSING_VALUE ); try { report = (SubReport) performExternalParsing( file, targetClass, parameters ); } catch ( ResourceLoadingException e ) { throw new ParseException( "The specified subreport was not found or could not be loaded.", e ); } } else { throw new ParseException( "Required attribute 'href' is missing.", getLocator() ); } initialize( elementType ); super.startParsing( attrs ); // clear the href, this is used only for internal purposes ... report.setAttribute( getUri(), "href", null ); }