Class ClassTemplateLoader

    • Constructor Detail

      • ClassTemplateLoader

        public ClassTemplateLoader​(Class resourceLoaderClass)
        Deprecated.
        It's confusing that the base path is ""; use ClassTemplateLoader(Class, String) instead.
        Creates a template loader that will use the Class.getResource(String) method of the specified class to load the resources, and "" as base package path. This means that template paths will be resolved relatively to the class location, that is, relatively to the directory (package) of the class.
        Parameters:
        resourceLoaderClass - the class whose Class.getResource(String) will be used to load the templates.
      • ClassTemplateLoader

        public ClassTemplateLoader​(Class resourceLoaderClass,
                                   String basePackagePath)
        Creates a template loader that will use the Class.getResource(String) method of the specified class to load the resources, and the specified base package path (absolute or relative).

        Examples:

        • Relative base path (will load from the com.example.myapplication.templates package):
          new ClassTemplateLoader(com.example.myapplication.SomeClass.class, "templates")
        • Absolute base path:
          new ClassTemplateLoader(somepackage.SomeClass.class, "/com/example/myapplication/templates")
        Parameters:
        resourceLoaderClass - The class whose Class.getResource(String) method will be used to load the templates. Be sure that you chose a class whose defining class-loader sees the templates. This parameter can't be null.
        basePackagePath - The package that contains the templates, in path (/-separated) format. If it doesn't start with a / then it's relative to the path (package) of the resourceLoaderClass class. If it starts with / then it's relative to the root of the package hierarchy. Note that path components should be separated by forward slashes independently of the separator character used by the underlying operating system. This parameter can't be null.
        See Also:
        ClassTemplateLoader(ClassLoader, String)
    • Method Detail

      • getURL

        protected URL getURL​(String name)
        Description copied from class: URLTemplateLoader
        Given a template name (plus potential locale decorations) retrieves an URL that points the template source.
        Specified by:
        getURL in class URLTemplateLoader
        Parameters:
        name - the name of the sought template, including the locale decorations.
        Returns:
        an URL that points to the template source, or null if it can determine that the template source does not exist.
      • toString

        public String toString()
        Show class name and some details that are useful in template-not-found errors.
        Overrides:
        toString in class Object
        Since:
        2.3.21
      • getResourceLoaderClass

        public Class getResourceLoaderClass()
        See the similar parameter of ClassTemplateLoader(Class, String); null when other mechanism is used to load the resources.
        Since:
        2.3.22