public class Tagliatelle extends Object
Helps to resolve and compile templates and also to generate a context used to render their output.
Modifier and Type | Field and Description |
---|---|
static sirius.kernel.health.Log |
LOG
Logs everything related to resolving, compiling and rendering tagliatelle templates.
|
protected static String |
PRAGMA_ALIAS |
Constructor and Description |
---|
Tagliatelle() |
Modifier and Type | Method and Description |
---|---|
CompilationContext |
createCompilationContext(String path,
Resource resource,
CompilationContext parent)
Creates a new
CompilationContext for the given path and resource. |
List<Object> |
createEnvironment()
Creates a new list of global variables used to initialize a global render context.
|
GlobalRenderContext |
createRenderContext()
Creates a new render context.
|
static void |
ensureProperTemplatePath(String path)
For security reasons we only invoke templates that end with .pasta.
|
Map<String,Class<?>> |
getClassAliases()
Provides all known class aliases.
|
List<Template> |
getCompiledTemplates()
Provides a list of all currently compiled templates.
|
List<sirius.kernel.commons.Tuple<String,Class<?>>> |
getGlobalVariables()
Returns the names and types of the known global variables to assist the
Compiler . |
List<sirius.kernel.commons.Tuple<String,String>> |
getTagLibs()
Returns a list of all tag lib prefixes and descriptions.
|
sirius.kernel.commons.MultiMap<String,String> |
getTagLibTags()
Returns all taglibs and all tags within this taglib.
|
static boolean |
isAssignable(Object from,
Class<?> to)
Determines if the type to is assignable from the given object.
|
static boolean |
isAssignableTo(Class<?> from,
Class<?> to)
Determines if the type to is assignable from the given type from.
|
boolean |
isTaglib(String prefix)
Determines if a taglib with the given prefix exists.
|
Optional<Template> |
resolve(String path)
|
Optional<Template> |
resolve(String path,
CompilationContext parentContext)
|
String |
resolveTagName(String qualifiedTagName)
Computes the effective path name for a tag.
|
public static final sirius.kernel.health.Log LOG
protected static final String PRAGMA_ALIAS
public sirius.kernel.commons.MultiMap<String,String> getTagLibTags()
public List<sirius.kernel.commons.Tuple<String,String>> getTagLibs()
public boolean isTaglib(String prefix)
prefix
- the prefix to checkpublic Map<String,Class<?>> getClassAliases()
public List<Object> createEnvironment()
public List<sirius.kernel.commons.Tuple<String,Class<?>>> getGlobalVariables()
Compiler
.public CompilationContext createCompilationContext(@Nonnull String path, @Nullable Resource resource, @Nullable CompilationContext parent)
CompilationContext
for the given path and resource.path
- the path of the template being compiledresource
- the actual resource which was used to determine the source code of the templateparent
- if the compilation was started while compiling another template, its context is given here. This
is mainly used to detect and abort cyclic dependencies at compile time.public GlobalRenderContext createRenderContext()
public static boolean isAssignable(Object from, Class<?> to)
In contrast to Class.isAssignableFrom(Class)
, this also handles autoboxing appropriately.
from
- the object to assignto
- the type to assign topublic static boolean isAssignableTo(Class<?> from, Class<?> to)
In contrast to Class.isAssignableFrom(Class)
, this also handles autoboxing appropriately.
from
- the type to assignto
- the type to assign topublic Optional<Template> resolve(String path) throws CompileException
path
- the path to resolveResource
was found.CompileException
- in case of one or more compilation errors in the templatepublic Optional<Template> resolve(String path, @Nullable CompilationContext parentContext) throws CompileException
Resources
and compiles it into a Template
.
If the template is resolved as part of another compilation process, the context is passed in as parentContext to detect and abort cyclic references.
path
- the path to resolveparentContext
- the outer compilation context which is in charge of compiling the calleeResource
was found.CompileException
- in case of one or more compilation errors in the templatepublic static void ensureProperTemplatePath(String path)
Otherwise one could customize a template and try to include a configuration file or class file and therefore obtain private data.
path
- the path to checkpublic String resolveTagName(String qualifiedTagName)
A template for a tag named <prefix:tagName> is expected to reside in /taglib/prefix/tagName.html.pasta.
qualifiedTagName
- the qualified tag name, e.g. prefix:tagNamepublic List<Template> getCompiledTemplates()
Note that this directly accesses an inner cache. Therefore some templates which were rendered some time ago, might have been dropped out of the cache and will therefore not occur in this list.
Copyright © 2018. All rights reserved.