Class StaticContentByRegexResourceLoader

  • All Implemented Interfaces:
    ResourceLoader

    public class StaticContentByRegexResourceLoader
    extends java.lang.Object
    implements ResourceLoader
    Responsible for returning default resource for paths whose match regular expression. This loader stores resource mapping in format: regular expression → default resource path.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.InputStream getResourceAsStream​(java.lang.String path)
      Returns default resource when the path match regular expression.
      protected java.io.InputStream getResourceByPath​(java.lang.String path)
      Returns resource identified by path as InputStream or null if resource does not exist.
      boolean hasResource​(java.lang.String path)
      Checks whether this loader can load resource identified by path.
      protected boolean isResourceExisting​(java.lang.String path)
      Checks whether a resource identified by path exist.
      void setMapping​(java.util.Map<java.lang.String,​java.lang.String> mapping)
      Sets mapping used to match resource path to default resource path.
      • Methods inherited from class java.lang.Object

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

      • StaticContentByRegexResourceLoader

        public StaticContentByRegexResourceLoader()
        Constructs a new instance.
      • StaticContentByRegexResourceLoader

        public StaticContentByRegexResourceLoader​(java.util.Map<java.lang.String,​java.lang.String> mapping)
        Constructs a new instance and sets resource mapping.
        Parameters:
        mapping - the mapping in format: regular expression → default resource path.
        Throws:
        java.lang.IllegalArgumentException - if the mapping is blank.
    • Method Detail

      • setMapping

        public void setMapping​(java.util.Map<java.lang.String,​java.lang.String> mapping)
        Sets mapping used to match resource path to default resource path.
        Parameters:
        mapping - the mapping in format: regular expression → default resource path.
        Throws:
        java.lang.IllegalArgumentException - if the mapping is blank.
      • hasResource

        public boolean hasResource​(java.lang.String path)
        Description copied from interface: ResourceLoader
        Checks whether this loader can load resource identified by path.
        Specified by:
        hasResource in interface ResourceLoader
        Parameters:
        path - the path identifying resource.
        Returns:
        true whether this loader can load resource, otherwise false.
      • isResourceExisting

        protected boolean isResourceExisting​(java.lang.String path)
        Checks whether a resource identified by path exist.
        Parameters:
        path - the path identifying resource.
        Returns:
        true if the resource exists, otherwise false.
      • getResourceAsStream

        public java.io.InputStream getResourceAsStream​(java.lang.String path)
        Returns default resource when the path match regular expression. It matches path to regular expressions in turn until one match and the default resource exists.
        Specified by:
        getResourceAsStream in interface ResourceLoader
        Parameters:
        path - the path identifying resource.
        Returns:
        Resource as InputStream or null.
        Throws:
        java.lang.IllegalArgumentException - if the path is blank.
      • getResourceByPath

        protected java.io.InputStream getResourceByPath​(java.lang.String path)
        Returns resource identified by path as InputStream or null if resource does not exist.
        Parameters:
        path - the path identifying resource.
        Returns:
        the input stream or null if the resource does not exist.