Class AbstractXmlResourceFactory

  • All Implemented Interfaces:
    org.pentaho.reporting.libraries.resourceloader.ResourceFactory

    public abstract class AbstractXmlResourceFactory
    extends Object
    implements org.pentaho.reporting.libraries.resourceloader.ResourceFactory
    A base-class for resource-factories that load their resources from XML files. This class provides a multiplexing option. For this, the parser looks at the root-element of the document to be parsed and selects the most suitable XmlFactoryModule implementation registered.
    Author:
    Thomas Morgner
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String CONTENTBASE_KEY
      A key for the content base.
      • Fields inherited from interface org.pentaho.reporting.libraries.resourceloader.ResourceFactory

        CONFIG_PREFIX
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void configureReader​(XMLReader reader, RootXmlReadHandler handler)
      Configures the xml reader.
      org.pentaho.reporting.libraries.resourceloader.Resource create​(org.pentaho.reporting.libraries.resourceloader.ResourceManager manager, org.pentaho.reporting.libraries.resourceloader.ResourceData data, org.pentaho.reporting.libraries.resourceloader.ResourceKey context)
      Creates a resource by interpreting the data given in the resource-data object.
      protected org.pentaho.reporting.libraries.resourceloader.Resource createResource​(org.pentaho.reporting.libraries.resourceloader.ResourceKey targetKey, RootXmlReadHandler handler, Object createdProduct, Class createdType)
      Creates a Resource object for the given product.
      protected RootXmlReadHandler createRootHandler​(org.pentaho.reporting.libraries.resourceloader.ResourceManager manager, org.pentaho.reporting.libraries.resourceloader.ResourceKey targetKey, XmlFactoryModule[] rootHandlers, org.pentaho.reporting.libraries.resourceloader.ResourceKey contextKey, long version)  
      protected Object finishResult​(Object res, org.pentaho.reporting.libraries.resourceloader.ResourceManager manager, org.pentaho.reporting.libraries.resourceloader.ResourceData data, org.pentaho.reporting.libraries.resourceloader.ResourceKey context)
      Finishes up the result.
      protected abstract org.pentaho.reporting.libraries.base.config.Configuration getConfiguration()
      Returns the configuration that should be used to initialize this factory.
      protected ErrorHandler getErrorHandler()
      Returns the XML-Error handler that should be registered with the XML parser.
      protected XmlFactoryModule[] getModules()
      Returns the registered XmlFactoryModules as array.
      protected SAXParser getParser()
      Returns a SAX parser.
      void initializeDefaults()
      Loads all XmlFactoryModule-implementations from the given configuration.
      Object parseDirectly​(org.pentaho.reporting.libraries.resourceloader.ResourceManager manager, InputSource input, org.pentaho.reporting.libraries.resourceloader.ResourceKey context, Map parameters)
      A method to allow to invoke the parsing without accessing the LibLoader layer.
      void registerModule​(XmlFactoryModule factoryModule)
      Registers a factory module for being used during the parsing.
      • Methods inherited from interface org.pentaho.reporting.libraries.resourceloader.ResourceFactory

        getFactoryType
    • Constructor Detail

      • AbstractXmlResourceFactory

        protected AbstractXmlResourceFactory()
        Default-Constructor.
    • Method Detail

      • configureReader

        protected void configureReader​(XMLReader reader,
                                       RootXmlReadHandler handler)
        Configures the xml reader. Use this to set features or properties before the documents get parsed.
        Parameters:
        handler - the parser implementation that will handle the SAX-Callbacks.
        reader - the xml reader that should be configured.
      • create

        public org.pentaho.reporting.libraries.resourceloader.Resource create​(org.pentaho.reporting.libraries.resourceloader.ResourceManager manager,
                                                                              org.pentaho.reporting.libraries.resourceloader.ResourceData data,
                                                                              org.pentaho.reporting.libraries.resourceloader.ResourceKey context)
                                                                       throws org.pentaho.reporting.libraries.resourceloader.ResourceCreationException,
                                                                              org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException
        Creates a resource by interpreting the data given in the resource-data object. If additional datastreams need to be parsed, the provided resource manager should be used. This method parses the given resource-data as XML stream.
        Specified by:
        create in interface org.pentaho.reporting.libraries.resourceloader.ResourceFactory
        Parameters:
        manager - the resource manager used for all resource loading.
        data - the resource-data from where the binary data is read.
        context - the resource context used to resolve relative resource paths.
        Returns:
        the parsed result, never null.
        Throws:
        org.pentaho.reporting.libraries.resourceloader.ResourceCreationException - if the resource could not be parsed due to syntaxctial or logical errors in the data.
        org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException - if the resource could not be accessed from the physical storage.
      • createRootHandler

        protected RootXmlReadHandler createRootHandler​(org.pentaho.reporting.libraries.resourceloader.ResourceManager manager,
                                                       org.pentaho.reporting.libraries.resourceloader.ResourceKey targetKey,
                                                       XmlFactoryModule[] rootHandlers,
                                                       org.pentaho.reporting.libraries.resourceloader.ResourceKey contextKey,
                                                       long version)
      • parseDirectly

        public Object parseDirectly​(org.pentaho.reporting.libraries.resourceloader.ResourceManager manager,
                                    InputSource input,
                                    org.pentaho.reporting.libraries.resourceloader.ResourceKey context,
                                    Map parameters)
                             throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException,
                                    org.pentaho.reporting.libraries.resourceloader.ResourceCreationException,
                                    org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException
        A method to allow to invoke the parsing without accessing the LibLoader layer. The data to be parsed is held in the given InputSource object.
        Parameters:
        manager - the resource manager used for all resource loading.
        input - the raw-data given as SAX-InputSource.
        context - the resource context used to resolve relative resource paths.
        parameters - the parse parameters.
        Returns:
        the parsed result, never null.
        Throws:
        org.pentaho.reporting.libraries.resourceloader.ResourceCreationException - if the resource could not be parsed due to syntaxctial or logical errors in the data.
        org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException - if the resource could not be accessed from the physical storage.
        org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException - if creating the context key failed.
      • getModules

        protected final XmlFactoryModule[] getModules()
        Returns the registered XmlFactoryModules as array. We assume that the modules are evaluated in the given order. The modules from the configuration are listed first (highest priority, as they may be supplied by user-overrides), then the modules that have been registered manually, where the oldest modules are returned as lowest priority elements.
        Returns:
        the modules as array.
      • createResource

        protected org.pentaho.reporting.libraries.resourceloader.Resource createResource​(org.pentaho.reporting.libraries.resourceloader.ResourceKey targetKey,
                                                                                         RootXmlReadHandler handler,
                                                                                         Object createdProduct,
                                                                                         Class createdType)
        Creates a Resource object for the given product. By default this returns a compound-resource that holds all the key that identify the resources used during the content production.
        Parameters:
        targetKey - the target key.
        handler - the root handler used for the parsing.
        createdProduct - the created product.
        createdType - the type information for the object that has been parsed.
        Returns:
        the product wrapped into a resource object.
      • finishResult

        protected Object finishResult​(Object res,
                                      org.pentaho.reporting.libraries.resourceloader.ResourceManager manager,
                                      org.pentaho.reporting.libraries.resourceloader.ResourceData data,
                                      org.pentaho.reporting.libraries.resourceloader.ResourceKey context)
                               throws org.pentaho.reporting.libraries.resourceloader.ResourceCreationException,
                                      org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException
        Finishes up the result. This can be used for general clean up and post-parse initializaion of the result. The default implementation does nothing and just returns the object itself.
        Parameters:
        res - the parsed resource.
        manager - the resource manager that was used to load the resource.
        data - the data object from where the resource is loaded.
        context - the context that resolves relative resource paths.
        Returns:
        the parsed resource.
        Throws:
        org.pentaho.reporting.libraries.resourceloader.ResourceCreationException - if the post initialization fails.
        org.pentaho.reporting.libraries.resourceloader.ResourceLoadingException - if loading external resources failed with an IO error.
      • getConfiguration

        protected abstract org.pentaho.reporting.libraries.base.config.Configuration getConfiguration()
        Returns the configuration that should be used to initialize this factory.
        Returns:
        the configuration for initializing the factory.
      • initializeDefaults

        public void initializeDefaults()
        Loads all XmlFactoryModule-implementations from the given configuration.
        Specified by:
        initializeDefaults in interface org.pentaho.reporting.libraries.resourceloader.ResourceFactory
        See Also:
        getConfiguration()
      • registerModule

        public void registerModule​(XmlFactoryModule factoryModule)
        Registers a factory module for being used during the parsing. If the factory module does not return a result that matches the factory's type, the parsing will always fail.
        Parameters:
        factoryModule - the factory module.
        Throws:
        NullPointerException - if the module given is null.
      • getErrorHandler

        protected ErrorHandler getErrorHandler()
        Returns the XML-Error handler that should be registered with the XML parser. By default, this returns a logger.
        Returns:
        the error handler.