Package org.apache.velocity.runtime
Class VelocimacroFactory
- java.lang.Object
-
- org.apache.velocity.runtime.VelocimacroFactory
-
public class VelocimacroFactory extends java.lang.Object
VelocimacroFactory.java manages the set of VMs in a running Velocity engine.- Version:
- $Id: VelocimacroFactory.java 894953 2009-12-31 22:48:19Z nbubna $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
VelocimacroFactory.Twonk
small container class to hold the tuple of a template and modification time.
-
Field Summary
Fields Modifier and Type Field Description private boolean
addNewAllowed
controls if new VMs can be added.private boolean
autoReloadLibrary
determines if the libraries are auto-loaded when they changeprivate java.util.Map
libModMap
map of the library Template objects used for reload determinationprivate LogDisplayWrapper
log
the log for this instanceprivate java.util.List
macroLibVec
vector of the library namesprivate boolean
replaceAllowed
determines if replacement of global VMs are allowed controlled by VM_PERM_ALLOW_INLINE_REPLACE_GLOBALprivate RuntimeServices
rsvc
runtime services for this instanceprivate boolean
templateLocal
sets if template-local namespace in usedprivate VelocimacroManager
vmManager
VMManager : deal with namespace management and actually keeps all the VM definitions
-
Constructor Summary
Constructors Constructor Description VelocimacroFactory(RuntimeServices rsvc)
C'tor for the VelociMacro factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addVelocimacro(java.lang.String name, java.lang.String macroBody, java.lang.String[] argArray, java.lang.String sourceTemplate)
Adds a macro to the factory.boolean
addVelocimacro(java.lang.String name, Node macroBody, java.lang.String[] argArray, java.lang.String sourceTemplate)
Adds a macro to the factory.private boolean
canAddVelocimacro(java.lang.String name, java.lang.String sourceTemplate)
determines if a given macro/namespace (name, source) combo is allowed to be addedboolean
dumpVMNamespace(java.lang.String namespace)
tells the vmManager to dump the specified namespaceprivate boolean
getAutoload()
get the switch for automatic reloading of global library-based VMsprivate boolean
getTemplateLocalInline()
Directive
getVelocimacro(java.lang.String vmName, java.lang.String sourceTemplate)
actual factory : creates a Directive that will behave correctly wrt getting the framework to dig out the correct # of argsDirective
getVelocimacro(java.lang.String vmName, java.lang.String sourceTemplate, java.lang.String renderingTemplate)
void
initVelocimacro()
initialize the factory - setup all permissions load all global libraries.boolean
isVelocimacro(java.lang.String vm, java.lang.String sourceTemplate)
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 Detail
-
rsvc
private final RuntimeServices rsvc
runtime services for this instance
-
log
private final LogDisplayWrapper log
the log for this instance
-
vmManager
private VelocimacroManager vmManager
VMManager : deal with namespace management and actually keeps all the VM definitions
-
replaceAllowed
private boolean replaceAllowed
determines if replacement of global VMs are allowed controlled by VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL
-
addNewAllowed
private boolean addNewAllowed
controls 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 templateLocal
sets if template-local namespace in used
-
autoReloadLibrary
private boolean autoReloadLibrary
determines if the libraries are auto-loaded when they change
-
macroLibVec
private java.util.List macroLibVec
vector of the library names
-
libModMap
private java.util.Map libModMap
map of the library Template objects used for reload determination
-
-
Constructor Detail
-
VelocimacroFactory
public VelocimacroFactory(RuntimeServices rsvc)
C'tor for the VelociMacro factory.- Parameters:
rsvc
- Reference to a runtime services object.
-
-
Method Detail
-
initVelocimacro
public void initVelocimacro()
initialize the factory - setup all permissions load all global libraries.
-
addVelocimacro
public boolean addVelocimacro(java.lang.String name, java.lang.String macroBody, java.lang.String[] argArray, java.lang.String sourceTemplate)
Adds a macro to the factory. addVelocimacro(String, Node, String[] argArray, String) should be used internally instead of this.- Parameters:
name
- Name of the Macro to add.macroBody
- String representation of the macro.argArray
- Macro arguments. First element is the macro name.sourceTemplate
- Source template from which the macro gets registered.- Returns:
- true if Macro was registered successfully.
-
addVelocimacro
public boolean addVelocimacro(java.lang.String name, Node macroBody, java.lang.String[] argArray, java.lang.String sourceTemplate)
Adds a macro to the factory.- Parameters:
name
- Name of the Macro to add.macroBody
- root node of the parsed macro ASTargArray
- Name of the macro arguments. First element is the macro name.sourceTemplate
- Source template from which the macro gets registered.- Returns:
- true if Macro was registered successfully.
- Since:
- 1.6
-
canAddVelocimacro
private boolean canAddVelocimacro(java.lang.String name, java.lang.String sourceTemplate)
determines if a given macro/namespace (name, source) combo is allowed to be added- Parameters:
name
- Name of VM to addsourceTemplate
- Source template that contains the defintion of the VM- Returns:
- true if it is allowed to be added, false otherwise
-
isVelocimacro
public boolean isVelocimacro(java.lang.String vm, java.lang.String sourceTemplate)
Tells the world if a given directive string is a Velocimacro- Parameters:
vm
- Name of the Macro.sourceTemplate
- Source template from which the macro should be loaded.- Returns:
- True if the given name is a macro.
-
getVelocimacro
public Directive getVelocimacro(java.lang.String vmName, java.lang.String sourceTemplate)
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.sourceTemplate
- Source template from which the macro should be loaded.- Returns:
- A directive representing the Macro.
-
getVelocimacro
public Directive getVelocimacro(java.lang.String vmName, java.lang.String sourceTemplate, java.lang.String renderingTemplate)
- Since:
- 1.6
-
dumpVMNamespace
public boolean dumpVMNamespace(java.lang.String namespace)
tells the vmManager to dump the specified namespace- Parameters:
namespace
- Namespace to dump.- Returns:
- True if namespace has been dumped successfully.
-
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
-
-