public class FileResourceLocator extends java.lang.Object implements ResourceLocator
ResourceLocator that loads files from the file system.| Modifier and Type | Class and Description |
|---|---|
static class |
FileResourceLocator.Builder
A builder for
FileResourceLocator. |
| Constructor and Description |
|---|
FileResourceLocator(Configuration config,
java.lang.String basePath)
Constructs a new
FileResourceLocator using the given Configuration and base path to search for
resources in. |
| Modifier and Type | Method and Description |
|---|---|
ResourceName |
findResource(ResourceName parent,
java.lang.String name)
Searches for a resource with the given name, returns the full path to it.
|
ResourceName |
findResource(java.lang.String name)
Searches for a resource with the given name, returns the full path to it.
|
long |
getModifiedTime(ResourceName resourceName)
Gets a value which indicates when the resource was modified.
|
java.io.Reader |
getReader(ResourceName resourceName)
Gets a
Reader to read the contents of the given resource. |
public FileResourceLocator(Configuration config, java.lang.String basePath)
FileResourceLocator using the given Configuration and base path to search for
resources in.config - The Configuration you used to construct the CarrotEngine.basePath - The path path to search for resources in.public ResourceName findResource(@Nullable ResourceName parent, java.lang.String name) throws CarrotException
ResourceLocatorThis will search for the resource in the given path first, if not found there will search a locator-specific search path for the resource before giving up.
findResource in interface ResourceLocatorparent - The parent to look for the resource in. If not found here, we will also do a search for a
non-relative name. May be null to search only in the search path.name - The name of the resource to search file.ResourceName representing the resolved name of the resource.CarrotException - If the resource cannot be found.public ResourceName findResource(java.lang.String name) throws CarrotException
ResourceLocatorfindResource in interface ResourceLocatorname - The name of the resource to search file.ResourceName representing the resolved name of the resource.CarrotException - If the resource cannot be found.public long getModifiedTime(ResourceName resourceName) throws CarrotException
ResourceLocatorThe value is used to determine whether we need to flush our caches, and this function will be called for every request to render a template, so calling this needs to be quick.
Zero indicates this ResourceLocator doesn't support modification detection, and resources will be cached
indefinitely.
getModifiedTime in interface ResourceLocatorresourceName - The ResourceName of the resource.CarrotException - If the resource cannot be found.public java.io.Reader getReader(ResourceName resourceName) throws CarrotException
ResourceLocatorReader to read the contents of the given resource.getReader in interface ResourceLocatorresourceName - The ResourceName of the resource.Reader for reading the contents of the resource.CarrotException - If the resource cannot be found.