FreeMarker loads template "files" through objects that implement this interface, thus the templates need not be real files, and can come from any kind of data source (like classpath, servlet context, database, etc). While FreeMarker provides a few TemplateLoader implementations out-of-the-bo
| 74 | * by the {@link TemplateCache}, and templates are get via the {@link TemplateCache} API-s. |
| 75 | */ |
| 76 | public interface TemplateLoader { |
| 77 | |
| 78 | /** |
| 79 | * Finds the object that acts as the source of the template with the |
| 80 | * given name. This method is called by the {@link TemplateCache} when a template |
| 81 | * is requested, before calling either {@link #getLastModified(Object)} or |
| 82 | * {@link #getReader(Object, String)}. |
| 83 | * |
| 84 | * @param name the name of the template, already localized and normalized by |
| 85 | * the {@link freemarker.cache.TemplateCache cache}. |
| 86 | * It is completely up to the loader implementation to interpret |
| 87 | * the name, however it should expect to receive hierarchical paths where |
| 88 | * path components are separated by a slash (not backslash). Backslashes |
| 89 | * (or any other OS specific separator character) are not considered as separators by |
| 90 | * FreeMarker, and thus they will not be replaced with slash before passing to this method, |
| 91 | * so it is up to the template loader to handle them (say, be throwing and exception that |
| 92 | * tells the user that the path (s)he has entered is invalid, as (s)he must use slash -- |
| 93 | * typical mistake of Windows users). |
| 94 | * The passed names are always considered relative to some loader-defined root |
| 95 | * location (often referred as the "template root directory"), and will never start with |
| 96 | * a slash, nor will they contain a path component consisting of either a single or a double |
| 97 | * dot -- these are all resolved by the template cache before passing the name to the |
| 98 | * loader. As a side effect, paths that trivially reach outside template root directory, |
| 99 | * such as <tt>../my.ftl</tt>, will be rejected by the template cache, so they never |
| 100 | * reach the template loader. Note again, that if the path uses backslash as path separator |
| 101 | * instead of slash as (the template loader should not accept that), the normalization will |
| 102 | * not properly happen, as FreeMarker (the cache) recognizes only the slashes as separators. |
| 103 | * |
| 104 | * @return an object representing the template source, which can be |
| 105 | * supplied in subsequent calls to {@link #getLastModified(Object)} and |
| 106 | * {@link #getReader(Object, String)}. Null must be returned if the source |
| 107 | * for the template can not be found (do not throw <code>FileNotFoundException</code>!). |
| 108 | * The returned object may will be compared with a cached template source |
| 109 | * object for equality, using the <code>equals</code> method. Thus, |
| 110 | * objects returned for the same physical source must be equivalent |
| 111 | * according to <code>equals</code> method, otherwise template caching |
| 112 | * can become very ineffective! |
| 113 | */ |
| 114 | public Object findTemplateSource(String name) |
| 115 | throws |
| 116 | IOException; |
| 117 | |
| 118 | /** |
| 119 | * Returns the time of last modification of the specified template source. |
| 120 | * This method is called after <code>findTemplateSource()</code>. |
| 121 | * @param templateSource an object representing a template source, obtained |
| 122 | * through a prior call to {@link #findTemplateSource(String)}. |
| 123 | * @return the time of last modification of the specified template source, |
| 124 | * or -1 if the time is not known. |
| 125 | */ |
| 126 | public long getLastModified(Object templateSource); |
| 127 | |
| 128 | /** |
| 129 | * Returns the character stream of a template represented by the specified |
| 130 | * template source. This method is called after <code>getLastModified()</code> |
| 131 | * if it is determined that a cached copy of the template is unavailable |
| 132 | * or stale. |
| 133 | * @param templateSource an object representing a template source, obtained |
no outgoing calls
no test coverage detected
searching dependent graphs…