* {@code org.apache.velocity.tools.cleanConfiguration} init-param to true in
* either your servlet or servletContext init-params.
*/
protected void configure(final JeeConfig config, final ToolboxFactory factory)
{
FactoryConfiguration factoryConfig = new FactoryConfiguration("VelocityView.configure(config,factory)");
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 = config.findInitParameter(LOAD_DEFAULTS_KEY);
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
debug("Default tools configuration has been suppressed%s",
(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);
// check for user configuration at the conventional location,
// and be silent if they're missing
setConfig(factoryConfig, USER_TOOLS_PATH, false);
// check for a custom location for servlet-wide user props
String servletToolsPath = config.getInitParameter(TOOLS_KEY);
setConfig(factoryConfig, servletToolsPath, true);
// check for "injected" configuration in application attributes
FactoryConfiguration injected = ServletUtils.getConfiguration(servletContext);
if (injected != null)
{
debug("Adding configuration instance in servletContext attributes as '%s'", TOOLS_KEY);
factoryConfig.addConfiguration(injected);
}