- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Path resolvers are used by the template parser to load the source code for a
template. Implementations are given the path string extracted from
~%%include:/path/to/resource.html%%
and must return an InputStream
to the source code. This enables you to implement and use a custom mechanism for
loading templates. Klojang Templates provides two implementations itself:
one that loads templates from the file system (used under the hood by
Template.fromFile()
), and another one that loads
templates from the classpath (used by
Template.fromResource()
). You can use
different path resolvers for different templates, but nested templates always
inherit the PathResolver
from the root template (the template that was
explicitly instantiated using one of the fromXXX()
methods on the
Template
class.- Author:
- Ayco Holleman
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
isValidPath
(String path) Returns whether the path specified in an included template (like~%%include:/path/to/foo.html%%
) points to an existing resource.Returns anInputStream
to the resource denoted by the specified path.
-
Method Details
-
isValidPath
Returns whether the path specified in an included template (like~%%include:/path/to/foo.html%%
) points to an existing resource. If it is expensive to determine this (e.g. it requires a database lookup or an FTP connection), you may simply returntrue
. Parsing will still fail graciously when the path turns out to be invalid, but it will be some time after the included template was first encountered, which may make it harder to understand what was wrong with the template code. If this method returnsfalse
, parsing will be aborted immediately. The default implementation returnstrue
.- Parameters:
path
- the path to verify- Returns:
- whether it is a valid path
-
resolve
Returns anInputStream
to the resource denoted by the specified path.- Parameters:
path
- the path- Returns:
- an
InputStream
to the resource denoted by the specified path - Throws:
IOException
- If an error occurred while setting up theInputStream
.
-