* {@code org.apache.velocity.tools.cleanConfiguration} init-param to true in
* either your servlet or servletContext init-params.
*/
protected void configure(final ServletConfig config, final ToolboxFactory factory)
{
FactoryConfiguration factoryConfig = new FactoryConfiguration();
boolean hasOldToolbox = false;
if (this.deprecationSupportMode)
{
FactoryConfiguration oldToolbox = getDeprecatedConfig(config);
if (oldToolbox != null)
{
hasOldToolbox = true;
factoryConfig.addConfiguration(oldToolbox);
}
}
// only load the default tools if they have explicitly said to
// or if they are not using an old toolbox and have said nothing
String loadDefaults = findInitParameter(LOAD_DEFAULTS_KEY, config);
if ((!hasOldToolbox && loadDefaults == null) ||
"true".equalsIgnoreCase(loadDefaults))
{
// add all available default tools
getLog().trace("Loading default tools configuration...");
factoryConfig.addConfiguration(ConfigurationUtils.getDefaultTools());
}
else
{
// let the user know that the defaults were suppressed
getLog().debug("Default tools configuration has been suppressed"
+ (hasOldToolbox ?
" to avoid conflicts with older application's context and toolbox definition."
: "."));
}
// this gets the auto loaded config from the classpath
// this doesn't include defaults since they're handled already
// and it could theoretically pick up an auto-loaded config from the
// filesystem, but that is highly unlikely to happen in a webapp env
FactoryConfiguration autoLoaded = ConfigurationUtils.getAutoLoaded(false);
factoryConfig.addConfiguration(autoLoaded);
// check for application-wide user config in the context init params
String appToolsPath = servletContext.getInitParameter(TOOLS_KEY);
setConfig(factoryConfig, appToolsPath, true);