Package org.apache.velocity.runtime
Class VelocimacroManager
- java.lang.Object
-
- org.apache.velocity.runtime.VelocimacroManager
-
public class VelocimacroManager extends java.lang.Object
Manages VMs in namespaces. Currently, two namespace modes are supported:- flat - all allowable VMs are in the global namespace
- local - inline VMs are added to it's own template namespace
- Version:
- $Id: VelocimacroManager.java 992115 2010-09-02 21:00:10Z nbubna $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
VelocimacroManager.MacroEntry
wrapper class for holding VM information
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
GLOBAL_NAMESPACE
private java.util.Map
globalNamespace
reference to global namespace hashprivate boolean
inlineLocalMode
private boolean
inlineReplacesGlobal
private java.util.Set
libraries
set of names of library tempates/namespacesprivate java.util.Map
namespaceHash
Hash of namespace hashes.private boolean
namespacesOn
private boolean
registerFromLib
private RuntimeServices
rsvc
-
Constructor Summary
Constructors Constructor Description VelocimacroManager(RuntimeServices rsvc)
Adds the global namespace to the hash.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.Map
addNamespace(java.lang.String namespace)
adds a namespace to the namespacesboolean
addVM(java.lang.String vmName, Node macroBody, java.lang.String[] argArray, java.lang.String namespace, boolean canReplaceGlobalMacro)
Adds a VM definition to the cache.boolean
dumpNamespace(java.lang.String namespace)
Removes the VMs and the namespace from the manager.VelocimacroProxy
get(java.lang.String vmName, java.lang.String namespace)
Gets a VelocimacroProxy object by the name / source template duple.VelocimacroProxy
get(java.lang.String vmName, java.lang.String namespace, java.lang.String renderingTemplate)
Gets a VelocimacroProxy object by the name / source template duple.java.lang.String
getLibraryName(java.lang.String vmName, java.lang.String namespace)
Return the library name for a given macro.private java.util.Map
getNamespace(java.lang.String namespace, boolean addIfNew)
returns the hash for the specified namespace, and if it doesn't exist will create a new one and add it to the namespacesvoid
setInlineReplacesGlobal(boolean is)
void
setNamespaceUsage(boolean namespaceOn)
public switch to let external user of manager to control namespace usage indep of properties.void
setRegisterFromLib(boolean registerFromLib)
Should macros registered from Libraries be marked special?void
setTemplateLocalInlineVM(boolean inlineLocalMode)
Should macros from the same template be inlined?private boolean
usingNamespaces(java.lang.String namespace)
determines if currently using namespaces.
-
-
-
Field Detail
-
GLOBAL_NAMESPACE
private static java.lang.String GLOBAL_NAMESPACE
-
registerFromLib
private boolean registerFromLib
-
namespaceHash
private final java.util.Map namespaceHash
Hash of namespace hashes.
-
globalNamespace
private final java.util.Map globalNamespace
reference to global namespace hash
-
libraries
private final java.util.Set libraries
set of names of library tempates/namespaces
-
rsvc
private RuntimeServices rsvc
-
namespacesOn
private boolean namespacesOn
-
inlineLocalMode
private boolean inlineLocalMode
-
inlineReplacesGlobal
private boolean inlineReplacesGlobal
-
-
Constructor Detail
-
VelocimacroManager
VelocimacroManager(RuntimeServices rsvc)
Adds the global namespace to the hash.
-
-
Method Detail
-
addVM
public boolean addVM(java.lang.String vmName, Node macroBody, java.lang.String[] argArray, java.lang.String namespace, boolean canReplaceGlobalMacro)
Adds a VM definition to the cache. Called by VelocimacroFactory.addVelociMacro (after parsing and discovery in Macro directive)- Parameters:
vmName
- Name of the new VelociMacro.macroBody
- String representation of the macro body.argArray
- Array of macro parameters, first parameter is the macro name.namespace
- The namespace/template from which this macro has been loaded.- Returns:
- Whether everything went okay.
-
get
public VelocimacroProxy get(java.lang.String vmName, java.lang.String namespace)
Gets a VelocimacroProxy object by the name / source template duple.- Parameters:
vmName
- Name of the VelocityMacro to look up.namespace
- Namespace in which to look up the macro.- Returns:
- A proxy representing the Macro.
-
get
public VelocimacroProxy get(java.lang.String vmName, java.lang.String namespace, java.lang.String renderingTemplate)
Gets a VelocimacroProxy object by the name / source template duple.- Parameters:
vmName
- Name of the VelocityMacro to look up.namespace
- Namespace in which to look up the macro.renderingTemplate
- Name of the template we are currently rendering.- Returns:
- A proxy representing the Macro.
- Since:
- 1.6
-
dumpNamespace
public boolean dumpNamespace(java.lang.String namespace)
Removes the VMs and the namespace from the manager. Used when a template is reloaded to avoid losing memory.- Parameters:
namespace
- namespace to dump- Returns:
- boolean representing success
-
setNamespaceUsage
public void setNamespaceUsage(boolean namespaceOn)
public switch to let external user of manager to control namespace usage indep of properties. That way, for example, at startup the library files are loaded into global namespace- Parameters:
namespaceOn
- True if namespaces should be used.
-
setRegisterFromLib
public void setRegisterFromLib(boolean registerFromLib)
Should macros registered from Libraries be marked special?- Parameters:
registerFromLib
- True if macros from Libs should be marked.
-
setTemplateLocalInlineVM
public void setTemplateLocalInlineVM(boolean inlineLocalMode)
Should macros from the same template be inlined?- Parameters:
inlineLocalMode
- True if macros should be inlined on the same template.
-
getNamespace
private java.util.Map getNamespace(java.lang.String namespace, boolean addIfNew)
returns the hash for the specified namespace, and if it doesn't exist will create a new one and add it to the namespaces- Parameters:
namespace
- name of the namespace :)addIfNew
- flag to add a new namespace if it doesn't exist- Returns:
- namespace Map of VMs or null if doesn't exist
-
addNamespace
private java.util.Map addNamespace(java.lang.String namespace)
adds a namespace to the namespaces- Parameters:
namespace
- name of namespace to add- Returns:
- Hash added to namespaces, ready for use
-
usingNamespaces
private boolean usingNamespaces(java.lang.String namespace)
determines if currently using namespaces.- Parameters:
namespace
- currently ignored- Returns:
- true if using namespaces, false if not
-
getLibraryName
public java.lang.String getLibraryName(java.lang.String vmName, java.lang.String namespace)
Return the library name for a given macro.- Parameters:
vmName
- Name of the Macro to look up.namespace
- Namespace to look the macro up.- Returns:
- The name of the library which registered this macro in a namespace.
-
setInlineReplacesGlobal
public void setInlineReplacesGlobal(boolean is)
- Since:
- 1.6
-
-