Class 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
    Thanks to Jose Alberto Fernandez for some ideas incorporated here.
    Version:
    $Id$
    • Field Detail

      • registerFromLib

        private boolean registerFromLib
      • globalNamespace

        private final java.util.Map<java.lang.String,​VelocimacroManager.MacroEntry> globalNamespace
        reference to global namespace hash
      • libraries

        private final java.util.Map<java.lang.String,​Template> libraries
        set of names of library templates/namespaces
      • 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.util.List<Macro.MacroArg> macroArgs,
                             Template definingTemplate,
                             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.
        macroArgs - Array of macro arguments, containing the #macro() arguments and default values. the 0th is the name.
        definingTemplate - The template from which this macro has been loaded.
        canReplaceGlobalMacro - whether this macro can replace a global macro
        Returns:
        Whether everything went okay.
      • get

        public VelocimacroProxy get​(java.lang.String vmName,
                                    Template renderingTemplate,
                                    Template template)
        Gets a VelocimacroProxy object by the name / source template duple.
        Parameters:
        vmName - Name of the VelocityMacro to look up.
        renderingTemplate - Template we are currently rendering.
        template - Source Template.
        Returns:
        A proxy representing the Macro.
      • 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.
      • usingNamespaces

        private boolean usingNamespaces()
        determines if currently using namespaces.
        Returns:
        true if using namespaces, false if not
      • getLibraryName

        public java.lang.String getLibraryName​(java.lang.String vmName,
                                               Template template)
        Return the library name for a given macro.
        Parameters:
        vmName - Name of the Macro to look up.
        template - Template
        Returns:
        The name of the library which registered this macro in a namespace.
      • setInlineReplacesGlobal

        public void setInlineReplacesGlobal​(boolean is)
        Parameters:
        is -
        Since:
        1.6