Package org.apache.velocity.tools.config

Examples of org.apache.velocity.tools.config.FactoryConfiguration


        }
    }

    public void autoConfigure(boolean includeDefaults)
    {
        FactoryConfiguration config =
            ConfigurationUtils.getAutoLoaded(includeDefaults);

        // look for any specified via system property
        FactoryConfiguration sys = ConfigurationUtils.findFromSystemProperty();
        if (sys != null)
        {
            config.addConfiguration(sys);
        }
        configure(config);
View Full Code Here


        this.factory.configure(config);
    }

    public void configure(String path)
    {
        FactoryConfiguration config = findConfig(path);
        if (config != null)
        {
            configure(config);
        }
        else
View Full Code Here

    public void autoConfigure(boolean includeDefaults)
    {
        super.autoConfigure(includeDefaults);

        // check for a configuration in application attributes
        FactoryConfiguration injected = ServletUtils.getConfiguration(servletContext);
        if (injected != null)
        {
            configure(injected);
        }
    }
View Full Code Here

     * {@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);
        }
View Full Code Here

     * (the deprecated default location) and tries to load it if found.
     */
    @Deprecated
    protected FactoryConfiguration getDeprecatedConfig(JeeConfig config)
    {
        FactoryConfiguration toolbox = null;

        // look for specified path under the deprecated toolbox key
        String oldPath = config.findInitParameter(DEPRECATED_TOOLS_KEY);
        if (oldPath != null)
        {
View Full Code Here

        }

        // this will throw an exception if require is true and there
        // is no tool config at the path.  if require is false, this
        // will return null when there's no tool config at the path
        FactoryConfiguration config = getConfiguration(path, require);
        if (config == null)
        {
            return false;
        }
View Full Code Here

        if (getLog().isTraceEnabled())
        {
            getLog().trace("Searching for configuration at: "+path);
        }

        FactoryConfiguration config = null;
        try
        {
            config = ServletUtils.getConfiguration(path,
                                                   this.servletContext,
                                                   this.deprecationSupportMode);
View Full Code Here

    public static FactoryConfiguration getConfiguration(ServletContext application)
    {
        Object obj = application.getAttribute(CONFIGURATION_KEY);
        if (obj instanceof FactoryConfiguration)
        {
            FactoryConfiguration injected = (FactoryConfiguration)obj;
            // make note of where we found this
            String source = injected.getSource();
            String addnote = " from ServletContext.getAttribute("+CONFIGURATION_KEY+")";
            if (!source.endsWith(addnote))
            {
                injected.setSource(source+addnote);
            }
            return injected;
        }
        return null;
    }
View Full Code Here

     * {@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);
        }
View Full Code Here

     * (the deprecated default location) and tries to load it if found.
     */
    @Deprecated
    protected FactoryConfiguration getDeprecatedConfig(JeeConfig config)
    {
        FactoryConfiguration toolbox = null;

        // look for specified path under the deprecated toolbox key
        String oldPath = config.findInitParameter(DEPRECATED_TOOLS_KEY);
        if (oldPath != null)
        {
View Full Code Here

TOP

Related Classes of org.apache.velocity.tools.config.FactoryConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.