Logo Search packages:      
Sourcecode: velocity version File versions  Download package

void org::apache::velocity::runtime::VelocimacroFactory::initVelocimacro (  )  [inline]

initialize the factory - setup all permissions load all global libraries.

Definition at line 109 of file VelocimacroFactory.java.

References getAutoload(), getBlather(), org::apache::velocity::runtime::RuntimeServices::getBoolean(), org::apache::velocity::runtime::RuntimeServices::getProperty(), org::apache::velocity::runtime::RuntimeServices::getTemplate(), org::apache::velocity::runtime::RuntimeLogger::info(), libModMap, logVMMessageInfo(), macroLibVec, org::apache::velocity::runtime::VelocimacroFactory::Twonk::modificationTime, rsvc, setAddMacroPermission(), setAutoload(), setBlather(), org::apache::velocity::runtime::VelocimacroManager::setNamespaceUsage(), org::apache::velocity::runtime::VelocimacroManager::setRegisterFromLib(), setReplacementPermission(), setTemplateLocalInline(), org::apache::velocity::runtime::VelocimacroManager::setTemplateLocalInlineVM(), org::apache::velocity::runtime::VelocimacroFactory::Twonk::template, and vmManager.

    {
        /*
         *  maybe I'm just paranoid...
         */
        synchronized( this )
        {
            /*
             *   allow replacements while we add the libraries, if exist
             */
            setReplacementPermission( true );
            setBlather( true );

            logVMMessageInfo("Velocimacro : initialization starting.");
 
            /*
             *  add all library macros to the global namespace
             */
            
            vmManager.setNamespaceUsage( false );
        
            /*
             *  now, if there is a global or local libraries specified, use them.
             *  All we have to do is get the template. The template will be parsed;
             *  VM's  are added during the parse phase
             */

             Object libfiles = rsvc.getProperty( RuntimeConstants.VM_LIBRARY );
           
             if( libfiles != null)
             {         
                 if (libfiles instanceof Vector)
                 {
                     macroLibVec = (Vector) libfiles;
                 }
                 else if (libfiles instanceof String)
                 { 
                     macroLibVec = new Vector();
                     macroLibVec.addElement( libfiles );
                 }
                 
                 for( int i = 0; i < macroLibVec.size(); i++)
                 {
                     String lib = (String) macroLibVec.elementAt(i);
                 
                     /*
                      * only if it's a non-empty string do we bother
                      */

                     if (lib != null && !lib.equals(""))
                     {
                         /*
                          *  let the VMManager know that the following is coming
                          *  from libraries - need to know for auto-load
                          */

                         vmManager.setRegisterFromLib( true );

                         logVMMessageInfo("Velocimacro : adding VMs from " +
                             "VM library template : " + lib  );

                         try 
                         {
                             Template template = rsvc.getTemplate( lib );

                             /*
                              *  save the template.  This depends on the assumption
                              *  that the Template object won't change - currently
                              *  this is how the Resource manager works
                              */

                             Twonk twonk = new Twonk();
                             twonk.template = template;
                             twonk.modificationTime = template.getLastModified();
                             libModMap.put( lib, twonk );                         
                         } 
                         catch (Exception e)
                         {
                             logVMMessageInfo("Velocimacro : error using  VM " +
                                              "library template " + lib + " : " + e );
                         }

                         logVMMessageInfo("Velocimacro :  VM library template " +
                                 "macro registration complete." );
            
                         vmManager.setRegisterFromLib( false );
                     }
                 }
             }

            /*
             *   now, the permissions
             */
            
            /*
             *  allowinline : anything after this will be an inline macro, I think
             *  there is the question if a #include is an inline, and I think so
             *
             *  default = true
             */
            setAddMacroPermission( true );
                        
            if ( !rsvc.getBoolean(  RuntimeConstants.VM_PERM_ALLOW_INLINE, true) )
            {
                setAddMacroPermission( false );
                
                logVMMessageInfo("Velocimacro : allowInline = false : VMs can not " +
                    "be defined inline in templates");
            }
            else
            {
                logVMMessageInfo("Velocimacro : allowInline = true : VMs can be " +
                    "defined inline in templates");
            }

            /*
             *  allowInlineToReplaceGlobal : allows an inline VM , if allowed at all,
             *  to replace an existing global VM
             *
             *  default = false
             */
            setReplacementPermission( false );
            
            if ( rsvc.getBoolean(  
                 RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, false) )
            {
                setReplacementPermission( true );
                
                logVMMessageInfo("Velocimacro : allowInlineToOverride = true : VMs " +
                    "defined inline may replace previous VM definitions");
            }
            else
            {
                logVMMessageInfo("Velocimacro : allowInlineToOverride = false : VMs " +
                    "defined inline may NOT replace previous VM definitions");
            }

            /*
             * now turn on namespace handling as far as permissions allow in the 
             * manager, and also set it here for gating purposes
             */
            vmManager.setNamespaceUsage( true );

            /*
             *  template-local inline VM mode : default is off
             */
            setTemplateLocalInline( rsvc.getBoolean(
                RuntimeConstants.VM_PERM_INLINE_LOCAL, false) );
        
            if ( getTemplateLocalInline() )
            {
                logVMMessageInfo("Velocimacro : allowInlineLocal = true : VMs " +
                    "defined inline will be local to their defining template only.");
            }
            else
            {
                logVMMessageInfo("Velocimacro : allowInlineLocal = false : VMs " +
                    "defined inline will be  global in scope if allowed.");
            }
 
            vmManager.setTemplateLocalInlineVM( getTemplateLocalInline() );

            /*
             *  general message switch.  default is on
             */
            setBlather( rsvc.getBoolean( RuntimeConstants.VM_MESSAGES_ON, true ));
        
            if (getBlather())
            {
                logVMMessageInfo("Velocimacro : messages on  : VM system " +
                    "will output logging messages");
            }
            else
            {
                logVMMessageInfo("Velocimacro : messages off : VM system will be quiet");
            }

            /*
             *  autoload VM libraries
             */
            setAutoload( rsvc.getBoolean( RuntimeConstants.VM_LIBRARY_AUTORELOAD, false ));
        
            if (getAutoload())
            {
                logVMMessageInfo("Velocimacro : autoload on  : VM system " +
                                 "will automatically reload global library macros");
            }
            else
            {
                logVMMessageInfo("Velocimacro : autoload off  : VM system " +
                                 "will not automatically reload global library macros");
            }

            rsvc.info("Velocimacro : initialization complete.");
        }
    
        return;
    }


Generated by  Doxygen 1.6.0   Back to index