org.apache.velocity.runtime
Class VelocimacroManager

java.lang.Object
  extended by org.apache.velocity.runtime.VelocimacroManager

public class VelocimacroManager
extends Object

Manages VMs in namespaces. Currently, two namespace modes are supported:

Thanks to Jose Alberto Fernandez for some ideas incorporated here.

Version:
$Id: VelocimacroManager.java 698376 2008-09-23 22:15:49Z nbubna $
Author:
Geir Magnusson Jr., Jose Alberto Fernandez

Method Summary
 boolean addVM(String vmName, Node macroBody, String[] argArray, String namespace, boolean canReplaceGlobalMacro)
          Adds a VM definition to the cache.
 boolean dumpNamespace(String namespace)
          Removes the VMs and the namespace from the manager.
 VelocimacroProxy get(String vmName, String namespace)
          Gets a VelocimacroProxy object by the name / source template duple.
 VelocimacroProxy get(String vmName, String namespace, String renderingTemplate)
          Gets a VelocimacroProxy object by the name / source template duple.
 String getLibraryName(String vmName, String namespace)
          Return the library name for a given macro.
 void 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?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addVM

public boolean addVM(String vmName,
                     Node macroBody,
                     String[] argArray,
                     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(String vmName,
                            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(String vmName,
                            String namespace,
                            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(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.

getLibraryName

public String getLibraryName(String vmName,
                             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


Copyright © 2000-2008 The Apache Software Foundation. All Rights Reserved.