protected void configure()

in velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java [393:462]


    protected void configure(final JeeConfig config, final ToolboxFactory factory)
    {
        FactoryConfiguration factoryConfig = new FactoryConfiguration("VelocityView.configure(config,factory)");

        String loadDefaults = config.findInitParameter(LOAD_DEFAULTS_KEY);
        if (loadDefaults == null || "false".equalsIgnoreCase(loadDefaults))
        {
            // let the user know that the defaults were suppressed
            getLog().debug("Default tools not loaded.");
        }
        else
        {
            // add all available default tools
            getLog().trace("Loading default tools configuration...");
            // give a chance for subclasses to define their own default tools
            factoryConfig.addConfiguration(getDefaultToolsConfiguration());
        }

        // check for application-wide user config in the context init params
        String appToolsPath = servletContext.getInitParameter(TOOLS_KEY);
        if (appToolsPath != null)
        {
            FactoryConfiguration appToolsConfig = getConfiguration(appToolsPath, true);
            factoryConfig.addConfiguration(appToolsConfig);
            getLog().debug("Loaded configuration from: {}", appToolsPath);
        }

        // check for a custom location for servlet-wide user props
        String servletToolsPath = config.getInitParameter(TOOLS_KEY);
        if (servletToolsPath != null)
        {
            FactoryConfiguration servletToolsConfig = getConfiguration(servletToolsPath, true);
            factoryConfig.addConfiguration(servletToolsConfig);
            getLog().debug("Loaded configuration from: {}", servletToolsPath);
        }

        if (appToolsPath == null && servletToolsPath == null)
        {
            // check for user configuration at the conventional location,
            // and be silent if they're missing
            FactoryConfiguration standardLocationConfiguration = getConfiguration(USER_TOOLS_PATH, false);
            if (standardLocationConfiguration != null)
            {
                factoryConfig.addConfiguration(standardLocationConfiguration);
                getLog().debug("Loaded configuration from: {}", USER_TOOLS_PATH);
            }
        }

        // check for "injected" configuration in application attributes
        FactoryConfiguration injected = ServletUtils.getConfiguration(servletContext);
        if (injected != null)
        {
            factoryConfig.addConfiguration(injected);
            getLog().debug("Added configuration instance in servletContext attributes as '{}'", TOOLS_KEY);
        }

        // see if we should only keep valid tools, data, and properties
        String cleanConfig = config.findInitParameter(CLEAN_CONFIGURATION_KEY);
        if ("true".equals(cleanConfig))
        {
            // remove invalid tools, data, and properties from the configuration
            ConfigurationCleaner cleaner = new ConfigurationCleaner();
            cleaner.setLog(getLog());
            cleaner.clean(factoryConfig);
        }

        // apply this configuration to the specified factory
        getLog().debug("Configuring factory with: {}", factoryConfig);
        configure(factoryConfig);
    }