Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java
===================================================================
--- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java	(revision 4691)
+++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/render/XWikiVelocityRenderer.java	(working copy)
@@ -39,10 +39,12 @@
 import org.apache.velocity.runtime.RuntimeSingleton;
 import org.apache.velocity.runtime.parser.ParseException;
 import org.apache.velocity.runtime.parser.node.SimpleNode;
+import org.apache.velocity.tools.view.ToolboxManager;
 
 import java.io.*;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -113,6 +115,16 @@
 
         vcontext.put("formatter", new VelocityFormatter(vcontext));
 
+        // Put the tools in context
+        ToolboxManager manager = (ToolboxManager)RuntimeSingleton.getApplicationAttribute(ToolboxManager.class.getName());
+        if (manager != null) {
+            Map tools = manager.getToolbox(vcontext);
+            for (Iterator it = tools.keySet().iterator(); it.hasNext(); ) {
+                String key = (String)it.next();
+                vcontext.put(key, tools.get(key));
+            }
+        }
+
         // We put the com.xpn.xwiki.api.XWiki object into the context and not the
         // com.xpn.xwiki.XWiki one which is for internal use only. In this manner we control what
         // the user can access.
Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/web/InitializationServletContextListener.java
===================================================================
--- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/web/InitializationServletContextListener.java	(revision 4691)
+++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/web/InitializationServletContextListener.java	(working copy)
@@ -19,29 +19,51 @@
  */
 package com.xpn.xwiki.web;
 
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.commons.collections.ExtendedProperties;
 import org.apache.velocity.app.Velocity;
-import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.tools.view.ToolboxManager;
+import org.apache.velocity.tools.view.XMLToolboxManager;
 
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContext;
-
 /**
  * XWiki's initialization. This is where we set up everything that should be initialized prior to
  * XWiki servicing requests. For example this is where we initialize Velocity.
- *
+ * 
  * @version $Id: $
  */
 public class InitializationServletContextListener implements ServletContextListener
 {
     /**
+     * Key used to access the toolbox configuration file path from the Servlet or webapp init
+     * parameters ("org.apache.velocity.toolbox").
+     */
+    protected static final String TOOLBOX_KEY = "org.apache.velocity.toolbox";
+
+    /**
+     * Key used to access the velocity configuration file path from the Servlet or webapp init
+     * parameters ("org.apache.velocity.properties").
+     */
+    protected static final String VELOCITY_PROPERTIES_KEY = "org.apache.velocity.properties";
+
+    /**
+     * Default toolbox configuration file path. If no alternate value for this is specified, the
+     * servlet will look here.
+     */
+    protected static final String DEFAULT_TOOLBOX_PATH = "/WEB-INF/toolbox.xml";
+
+    /**
      * {@inheritDoc}
+     * 
      * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
      */
     public void contextInitialized(ServletContextEvent event)
     {
         try {
             initializeVelocity(event.getServletContext());
+            initializeVelocityTools(event.getServletContext());
         } catch (Exception e) {
             throw new RuntimeException("Failed to initialize XWiki", e);
         }
@@ -49,7 +71,8 @@
 
     /**
      * {@inheritDoc}
-     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)  
+     * 
+     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
      */
     public void contextDestroyed(ServletContextEvent event)
     {
@@ -63,7 +86,7 @@
         // initialize the singleton here.
         // TODO: Once we have moved to a component approach, move to the VelocityEngine approach
         // which is cleaner and recommended.
-        
+
         // Start by loading default Velocity properties. This is required so that the Velocity
         // Webapp Loader is configured. This allows specifying paths relative to the webapp dir
         // in our velocity.properties file.
@@ -79,12 +102,30 @@
         Velocity.setApplicationAttribute(ServletContext.class.getName(), servletContext);
 
         // Get our custom Velocity configuration file location from context-param defined in web.xml
-        String velocityPropertiesFile =
-            servletContext.getInitParameter("org.apache.velocity.properties");
+        String velocityPropertiesFile = servletContext.getInitParameter(VELOCITY_PROPERTIES_KEY);
         ExtendedProperties customProperties = new ExtendedProperties();
         customProperties.load(servletContext.getResourceAsStream(velocityPropertiesFile));
         Velocity.setExtendedProperties(customProperties);
 
         Velocity.init();
     }
+
+    private void initializeVelocityTools(ServletContext servletContext) throws Exception
+    {
+        XMLToolboxManager toolboxManager;
+
+        // Check the servlet config and context for a toolbox configuration-file location parameter
+        String toolboxConfigFile = servletContext.getInitParameter(TOOLBOX_KEY);
+        if (toolboxConfigFile == null) {
+            // Look in the default location
+            toolboxConfigFile = DEFAULT_TOOLBOX_PATH;
+        }
+
+        // Try to get a manager for this toolbox file
+        toolboxManager = new XMLToolboxManager();
+        toolboxManager.load(servletContext.getResourceAsStream(toolboxConfigFile));
+
+        // Put the manager in the global velocity-engine context
+        Velocity.setApplicationAttribute(ToolboxManager.class.getName(), toolboxManager);
+    }
 }
