Package org.apache.velocity.runtime
Class VelocimacroFactory
java.lang.Object
org.apache.velocity.runtime.VelocimacroFactory
VelocimacroFactory.java
manages the set of VMs in a running Velocity engine.
- Version:
- $Id$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
small container class to hold the tuple of a template and modification time. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
controls if new VMs can be added.private boolean
determines if the libraries are auto-loaded when they changeprivate Map<String,
VelocimacroFactory.Twonk> map of the library Template objects used for reload determinationprivate org.slf4j.Logger
the log for this instancevector of the library namesprivate boolean
determines if replacement of global VMs are allowed controlled by VM_PERM_ALLOW_INLINE_REPLACE_GLOBALprivate final RuntimeServices
runtime services for this instanceprivate boolean
sets if template-local namespace in usedprivate VelocimacroManager
VMManager: deal with namespace management and actually keeps all the VM definitions -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addVelocimacro
(String name, Node macroBody, List<Macro.MacroArg> macroArgs, Template definingTemplate) Adds a macro to the factory.private boolean
canAddVelocimacro
(String name, Template definingTemplate) determines if a given macro/namespace (name, source) combo is allowed to be addedprivate boolean
get the switch for automatic reloading of global library-based VMsprivate boolean
getVelocimacro
(String vmName, Template renderingTemplate, Template sourceTemplate) actual factory: creates a Directive that will behave correctly wrt getting the framework to dig out the correct # of argsvoid
initialize the factory - setup all permissions load all global libraries.boolean
isVelocimacro
(String vm, Template template) Tells the world if a given directive string is a Velocimacroprivate boolean
setAddMacroPermission
(boolean addNewAllowed) sets the permission to add new macrosprivate void
setAutoload
(boolean b) set the switch for automatic reloading of global library-based VMsprivate boolean
setReplacementPermission
(boolean arg) sets the permission for allowing addMacro() calls to replace existing VM'sprivate void
setTemplateLocalInline
(boolean b) sets permission to have VMs local in scope to their declaring template note that this is really taken care of in the VMManager class, but we need it here for gating purposes in addVM eventually, I will slide this all into the manager, maybe.
-
Field Details
-
rsvc
runtime services for this instance -
log
private org.slf4j.Logger logthe log for this instance -
vmManager
VMManager: deal with namespace management and actually keeps all the VM definitions -
replaceAllowed
private boolean replaceAlloweddetermines if replacement of global VMs are allowed controlled by VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL -
addNewAllowed
private boolean addNewAllowedcontrols if new VMs can be added. Set by VM_PERM_ALLOW_INLINE Note the assumption that only through inline defs can this happen. additions through autoloaded VMs is allowed -
templateLocal
private boolean templateLocalsets if template-local namespace in used -
autoReloadLibrary
private boolean autoReloadLibrarydetermines if the libraries are auto-loaded when they change -
macroLibVec
vector of the library names -
libModMap
map of the library Template objects used for reload determination
-
-
Constructor Details
-
VelocimacroFactory
C'tor for the VelociMacro factory.- Parameters:
rsvc
- Reference to a runtime services object.
-
-
Method Details
-
initVelocimacro
public void initVelocimacro()initialize the factory - setup all permissions load all global libraries. -
addVelocimacro
public boolean addVelocimacro(String name, Node macroBody, List<Macro.MacroArg> macroArgs, Template definingTemplate) Adds a macro to the factory.- Parameters:
name
- Name of the Macro to add.macroBody
- root node of the parsed macro ASTmacroArgs
- Array of macro arguments, containing the #macro() arguments and default values. the 0th is the name.definingTemplate
- template containing the macro definition- Returns:
- true if Macro was registered successfully.
- Since:
- 1.6
-
canAddVelocimacro
determines if a given macro/namespace (name, source) combo is allowed to be added- Parameters:
name
- Name of VM to adddefiningTemplate
- template containing the source of the macro- Returns:
- true if it is allowed to be added, false otherwise
-
isVelocimacro
Tells the world if a given directive string is a Velocimacro- Parameters:
vm
- Name of the Macro.template
- Source template from which the macro should be loaded.- Returns:
- True if the given name is a macro.
-
getVelocimacro
actual factory: creates a Directive that will behave correctly wrt getting the framework to dig out the correct # of args- Parameters:
vmName
- Name of the Macro.renderingTemplate
- destination templatesourceTemplate
- Source template from which the macro should be loaded.- Returns:
- A directive representing the Macro.
-
setTemplateLocalInline
private void setTemplateLocalInline(boolean b) sets permission to have VMs local in scope to their declaring template note that this is really taken care of in the VMManager class, but we need it here for gating purposes in addVM eventually, I will slide this all into the manager, maybe. -
getTemplateLocalInline
private boolean getTemplateLocalInline() -
setAddMacroPermission
private boolean setAddMacroPermission(boolean addNewAllowed) sets the permission to add new macros -
setReplacementPermission
private boolean setReplacementPermission(boolean arg) sets the permission for allowing addMacro() calls to replace existing VM's -
setAutoload
private void setAutoload(boolean b) set the switch for automatic reloading of global library-based VMs -
getAutoload
private boolean getAutoload()get the switch for automatic reloading of global library-based VMs
-