Class ResourceLoader

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String className
      Class name for this loader, for logging/debuggin purposes.
      protected boolean isCachingOn
      Does this loader want templates produced with it cached in the Runtime.
      protected org.slf4j.Logger log  
      protected long modificationCheckInterval
      This property will be passed on to the templates that are created with this loader.
      protected RuntimeServices rsvc  
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceLoader()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.io.Reader buildReader​(java.io.InputStream rawStream, java.lang.String encoding)
      Builds a Reader given a raw InputStream and an encoding.
      void commonInit​(RuntimeServices rs, ExtProperties configuration)
      This initialization is used by all resource loaders and must be called to set up common properties shared by all resource loaders
      java.lang.String getClassName()
      Return the class name of this resource Loader
      abstract long getLastModified​(Resource resource)
      Get the last modified time of the InputStream source that was used to create the template.
      long getModificationCheckInterval()
      Get the interval at which the InputStream source should be checked for modifications.
      abstract java.io.Reader getResourceReader​(java.lang.String source, java.lang.String encoding)
      Get the Reader that the Runtime will parse to create a template.
      abstract void init​(ExtProperties configuration)
      Initialize the template loader with a a resources class.
      boolean isCachingOn()
      The Runtime uses this to find out whether this template loader wants the Runtime to cache templates created with InputStreams provided by this loader.
      abstract boolean isSourceModified​(Resource resource)
      Given a template, check to see if the source of InputStream has been modified.
      boolean resourceExists​(java.lang.String resourceName)
      Check whether any given resource exists.
      void setCachingOn​(boolean value)
      Set the caching state.
      void setModificationCheckInterval​(long modificationCheckInterval)
      Set the interval at which the InputStream source should be checked for modifications.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • isCachingOn

        protected boolean isCachingOn
        Does this loader want templates produced with it cached in the Runtime.
      • modificationCheckInterval

        protected long modificationCheckInterval
        This property will be passed on to the templates that are created with this loader.
      • className

        protected java.lang.String className
        Class name for this loader, for logging/debuggin purposes.
      • log

        protected org.slf4j.Logger log
    • Constructor Detail

      • ResourceLoader

        public ResourceLoader()
    • Method Detail

      • commonInit

        public void commonInit​(RuntimeServices rs,
                               ExtProperties configuration)
        This initialization is used by all resource loaders and must be called to set up common properties shared by all resource loaders
        Parameters:
        rs -
        configuration -
      • init

        public abstract void init​(ExtProperties configuration)
        Initialize the template loader with a a resources class.
        Parameters:
        configuration -
      • getResourceReader

        public abstract java.io.Reader getResourceReader​(java.lang.String source,
                                                         java.lang.String encoding)
                                                  throws ResourceNotFoundException
        Get the Reader that the Runtime will parse to create a template.
        Parameters:
        source -
        encoding -
        Returns:
        The reader for the requested resource.
        Throws:
        ResourceNotFoundException
        Since:
        2.0
      • isSourceModified

        public abstract boolean isSourceModified​(Resource resource)
        Given a template, check to see if the source of InputStream has been modified.
        Parameters:
        resource -
        Returns:
        True if the resource has been modified.
      • getLastModified

        public abstract long getLastModified​(Resource resource)
        Get the last modified time of the InputStream source that was used to create the template. We need the template here because we have to extract the name of the template in order to locate the InputStream source.
        Parameters:
        resource -
        Returns:
        Time in millis when the resource has been modified.
      • getClassName

        public java.lang.String getClassName()
        Return the class name of this resource Loader
        Returns:
        Class name of the resource loader.
      • setCachingOn

        public void setCachingOn​(boolean value)
        Set the caching state. If true, then this loader would like the Runtime to cache templates that have been created with InputStreams provided by this loader.
        Parameters:
        value -
      • isCachingOn

        public boolean isCachingOn()
        The Runtime uses this to find out whether this template loader wants the Runtime to cache templates created with InputStreams provided by this loader.
        Returns:
        True if this resource loader caches.
      • setModificationCheckInterval

        public void setModificationCheckInterval​(long modificationCheckInterval)
        Set the interval at which the InputStream source should be checked for modifications.
        Parameters:
        modificationCheckInterval -
      • getModificationCheckInterval

        public long getModificationCheckInterval()
        Get the interval at which the InputStream source should be checked for modifications.
        Returns:
        The modification check interval.
      • resourceExists

        public boolean resourceExists​(java.lang.String resourceName)
        Check whether any given resource exists. This is not really a very efficient test and it can and should be overridden in the subclasses extending ResourceLoader2.
        Parameters:
        resourceName - The name of a resource.
        Returns:
        true if a resource exists and can be accessed.
        Since:
        1.6
      • buildReader

        protected java.io.Reader buildReader​(java.io.InputStream rawStream,
                                             java.lang.String encoding)
                                      throws java.io.IOException
        Builds a Reader given a raw InputStream and an encoding. Should be use by every subclass that whishes to accept optional BOMs in resources. This method does *not* close the given input stream whenever an exception is thrown.
        Parameters:
        rawStream - The raw input stream.
        encoding - The asked encoding.
        Returns:
        found reader
        Throws:
        java.io.IOException
        java.io.UnsupportedEncodingException
        Since:
        2.0