Class FileResourceLoader


  • public class FileResourceLoader
    extends ResourceLoader
    A loader for templates stored on the file system. Treats the template as relative to the configured root path. If the root path is empty treats the template name as an absolute path.
    Version:
    $Id: FileResourceLoader.java 743616 2009-02-12 04:38:53Z nbubna $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List paths
      The paths to search for templates.
      private java.util.Map templatePaths
      Used to map the path that a template was found on so that we can properly check the modification times of the files.
      private boolean unicode
      Shall we inspect unicode files to see what encoding they contain?.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void closeQuiet​(java.io.InputStream is)  
      private java.io.InputStream findTemplate​(java.lang.String path, java.lang.String template)
      Try to find a template given a normalized path.
      private java.io.File getFile​(java.lang.String path, java.lang.String template)
      Create a File based on either a relative path if given, or absolute path otherwise
      long getLastModified​(Resource resource)
      Get the last modified time of the InputStream source that was used to create the template.
      java.io.InputStream getResourceStream​(java.lang.String templateName)
      Get an InputStream so that the Runtime can build a template with it.
      void init​(org.apache.commons.collections.ExtendedProperties configuration)
      Initialize the template loader with a a resources class.
      boolean isSourceModified​(Resource resource)
      How to keep track of all the modified times across the paths.
      boolean resourceExists​(java.lang.String name)
      Overrides superclass for better performance.
      • Methods inherited from class java.lang.Object

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

      • paths

        private java.util.List paths
        The paths to search for templates.
      • templatePaths

        private java.util.Map templatePaths
        Used to map the path that a template was found on so that we can properly check the modification times of the files. This is synchronizedMap instance.
      • unicode

        private boolean unicode
        Shall we inspect unicode files to see what encoding they contain?.
    • Constructor Detail

      • FileResourceLoader

        public FileResourceLoader()
    • Method Detail

      • getResourceStream

        public java.io.InputStream getResourceStream​(java.lang.String templateName)
                                              throws ResourceNotFoundException
        Get an InputStream so that the Runtime can build a template with it.
        Specified by:
        getResourceStream in class ResourceLoader
        Parameters:
        templateName - name of template to get
        Returns:
        InputStream containing the template
        Throws:
        ResourceNotFoundException - if template not found in the file template path.
      • resourceExists

        public boolean resourceExists​(java.lang.String name)
        Overrides superclass for better performance.
        Overrides:
        resourceExists in class ResourceLoader
        Parameters:
        name - The name of a resource.
        Returns:
        true if a resource exists and can be accessed.
        Since:
        1.6
      • findTemplate

        private java.io.InputStream findTemplate​(java.lang.String path,
                                                 java.lang.String template)
                                          throws java.io.IOException
        Try to find a template given a normalized path.
        Parameters:
        path - a normalized path
        template - name of template to find
        Returns:
        InputStream input stream that will be parsed
        Throws:
        java.io.IOException
      • closeQuiet

        private void closeQuiet​(java.io.InputStream is)
      • isSourceModified

        public boolean isSourceModified​(Resource resource)
        How to keep track of all the modified times across the paths. Note that a file might have appeared in a directory which is earlier in the path; so we should search the path and see if the file we find that way is the same as the one that we have cached.
        Specified by:
        isSourceModified in class ResourceLoader
        Parameters:
        resource -
        Returns:
        True if the source has been modified.
      • getFile

        private java.io.File getFile​(java.lang.String path,
                                     java.lang.String template)
        Create a File based on either a relative path if given, or absolute path otherwise