Example usage for org.apache.commons.collections ExtendedProperties setProperty

List of usage examples for org.apache.commons.collections ExtendedProperties setProperty

Introduction

In this page you can find the example usage for org.apache.commons.collections ExtendedProperties setProperty.

Prototype

public void setProperty(String key, Object value) 

Source Link

Document

Set a property, this will replace any previously set values.

Usage

From source file:it.unimi.di.big.mg4j.query.HttpQueryServer.java

/** Sets the given extended properties so that velocity finds its files either
 * by classpath, or by absolute filename, or by relative filename. 
 * //ww  w  .  ja va2  s . com
 * @param p the extended properties of the servlet, obtained <i>via</i>
 * <samp>super.loadConfiguration()</samp>.
 * 
 * @return <code>p</code> the additional items setting a liberal scheme for resource loading.
 */

public static ExtendedProperties setLiberalResourceLoading(final ExtendedProperties p) {
    // TODO: This is ugly. If anybody can find how to set the ServletConfig from Jetty, just let me know.
    if (!p.containsKey("resource.loader")) {
        p.setProperty("resource.loader", "class, current, absolute");
        p.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
        p.setProperty("current.resource.loader.class", FileResourceLoader.class.getName());
        p.setProperty("current.resource.loader.path", System.getProperty("user.dir"));
        p.setProperty("absolute.resource.loader.class", FileResourceLoader.class.getName());
        p.setProperty("absolute.resource.loader.path", "");
        p.setProperty("input.encoding", "utf-8");
        p.setProperty("output.encoding", "utf-8");
        p.setProperty("default.contentType", "text/html; charset=UTF-8");
    }

    return p;
}

From source file:com.alibaba.citrus.service.velocity.SpringResourceLoaderAdapterTests.java

@Before
public void init() throws Exception {
    ExtendedProperties config = new ExtendedProperties();
    RuntimeServices rsvc = new RuntimeInstance();

    config.setProperty("path", "/templates");
    config.setProperty("resource.loader", "");

    rsvc.setConfiguration(config);/*from   ww w .  ja v a 2 s  .co  m*/
    rsvc.setProperty(RUNTIME_LOG_LOGSYSTEM, new Slf4jLogChute(log));
    rsvc.setApplicationAttribute(SpringResourceLoaderAdapter.SPRING_RESOURCE_LOADER_KEY, factory);

    rsvc.init();

    velocityLoader = new SpringResourceLoaderAdapter();
    velocityLoader.commonInit(rsvc, config);
    velocityLoader.init(config);
}

From source file:com.liferay.portal.velocity.VelocityEngineImpl.java

public void init() throws Exception {
    if (_velocityEngine != null) {
        return;//  w  w w .jav  a2 s. c  om
    }

    _velocityEngine = new org.apache.velocity.app.VelocityEngine();

    LiferayResourceLoader.setVelocityResourceListeners(PropsValues.VELOCITY_ENGINE_RESOURCE_LISTENERS);

    ExtendedProperties extendedProperties = new FastExtendedProperties();

    extendedProperties.setProperty(_RESOURCE_LOADER, "string,servlet");

    extendedProperties.setProperty("string." + _RESOURCE_LOADER + ".cache",
            String.valueOf(PropsValues.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE_ENABLED));

    extendedProperties.setProperty("string." + _RESOURCE_LOADER + ".class",
            StringResourceLoader.class.getName());

    extendedProperties.setProperty("string." + _RESOURCE_LOADER + ".repository.class",
            StringResourceRepositoryImpl.class.getName());

    extendedProperties.setProperty("servlet." + _RESOURCE_LOADER + ".cache",
            String.valueOf(PropsValues.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE_ENABLED));

    extendedProperties.setProperty("servlet." + _RESOURCE_LOADER + ".class",
            LiferayResourceLoader.class.getName());

    extendedProperties.setProperty(org.apache.velocity.app.VelocityEngine.RESOURCE_MANAGER_CLASS,
            PropsUtil.get(PropsKeys.VELOCITY_ENGINE_RESOURCE_MANAGER));

    extendedProperties.setProperty(org.apache.velocity.app.VelocityEngine.RESOURCE_MANAGER_CACHE_CLASS,
            PropsUtil.get(PropsKeys.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE));

    extendedProperties.setProperty(org.apache.velocity.app.VelocityEngine.VM_LIBRARY,
            PropsUtil.get(PropsKeys.VELOCITY_ENGINE_VELOCIMACRO_LIBRARY));

    extendedProperties.setProperty(org.apache.velocity.app.VelocityEngine.VM_LIBRARY_AUTORELOAD,
            String.valueOf(!PropsValues.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE_ENABLED));

    extendedProperties.setProperty(org.apache.velocity.app.VelocityEngine.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL,
            String.valueOf(!PropsValues.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE_ENABLED));

    extendedProperties.setProperty(org.apache.velocity.app.VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,
            PropsUtil.get(PropsKeys.VELOCITY_ENGINE_LOGGER));

    extendedProperties.setProperty(
            org.apache.velocity.app.VelocityEngine.RUNTIME_LOG_LOGSYSTEM + ".log4j.category",
            PropsUtil.get(PropsKeys.VELOCITY_ENGINE_LOGGER_CATEGORY));

    _velocityEngine.setExtendedProperties(extendedProperties);

    _velocityEngine.init();

    _restrictedToolsContext = new VelocityContextImpl();

    VelocityVariablesUtil.insertHelperUtilities(_restrictedToolsContext,
            PropsValues.JOURNAL_TEMPLATE_VELOCITY_RESTRICTED_VARIABLES);

    _standardToolsContext = new VelocityContextImpl();

    VelocityVariablesUtil.insertHelperUtilities(_standardToolsContext, null);
}

From source file:com.alibaba.citrus.service.velocity.PreloadedResourceLoaderTests.java

@Before
public void init() throws Exception {
    ExtendedProperties config = new ExtendedProperties();
    RuntimeServices rsvc = new RuntimeInstance();

    config.setProperty("resource.loader", "");
    config.setProperty(PreloadedResourceLoader.PRELOADED_RESOURCES_KEY, preloadingResources());

    rsvc.setConfiguration(config);/*from   w  w  w.  j a v a 2 s  . com*/
    rsvc.setProperty(RUNTIME_LOG_LOGSYSTEM, new Slf4jLogChute(log));

    rsvc.init();

    velocityLoader = new PreloadedResourceLoader();
    velocityLoader.commonInit(rsvc, config);
    velocityLoader.init(config);
}

From source file:com.liferay.portal.template.velocity.internal.VelocityManager.java

@Override
public void init() throws TemplateException {
    if (_velocityEngine != null) {
        return;//from ww  w . j a  va2  s . c  o m
    }

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    Class<?> clazz = getClass();

    currentThread.setContextClassLoader(clazz.getClassLoader());

    try {
        _velocityEngine = new VelocityEngine();

        ExtendedProperties extendedProperties = new FastExtendedProperties();

        extendedProperties.setProperty(VelocityEngine.DIRECTIVE_IF_TOSTRING_NULLCHECK,
                String.valueOf(_velocityEngineConfiguration.directiveIfToStringNullCheck()));

        extendedProperties.setProperty(VelocityEngine.EVENTHANDLER_METHODEXCEPTION,
                LiferayMethodExceptionEventHandler.class.getName());

        extendedProperties.setProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,
                StringUtil.merge(_velocityEngineConfiguration.restrictedClasses()));

        extendedProperties.setProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_PACKAGES,
                StringUtil.merge(_velocityEngineConfiguration.restrictedPackages()));

        extendedProperties.setProperty(RuntimeConstants.PARSER_POOL_CLASS, VelocityParserPool.class.getName());

        extendedProperties.setProperty(VelocityEngine.RESOURCE_LOADER, "liferay");

        extendedProperties.setProperty(StringBundler.concat("liferay.", VelocityEngine.RESOURCE_LOADER, ".",
                VelocityTemplateResourceLoader.class.getName()), templateResourceLoader);

        boolean cacheEnabled = false;

        if (_velocityEngineConfiguration.resourceModificationCheckInterval() != 0) {

            cacheEnabled = true;
        }

        extendedProperties.setProperty("liferay." + VelocityEngine.RESOURCE_LOADER + ".cache",
                String.valueOf(cacheEnabled));

        extendedProperties.setProperty("liferay." + VelocityEngine.RESOURCE_LOADER + ".class",
                LiferayResourceLoader.class.getName());

        extendedProperties.setProperty(
                "liferay." + VelocityEngine.RESOURCE_LOADER + ".resourceModificationCheckInterval",
                _velocityEngineConfiguration.resourceModificationCheckInterval() + "");

        extendedProperties.setProperty(VelocityEngine.RESOURCE_MANAGER_CLASS,
                LiferayResourceManager.class.getName());

        extendedProperties.setProperty(
                "liferay." + VelocityEngine.RESOURCE_MANAGER_CLASS + ".resourceModificationCheckInterval",
                _velocityEngineConfiguration.resourceModificationCheckInterval() + "");

        extendedProperties.setProperty(VelocityTemplateResourceLoader.class.getName(), templateResourceLoader);

        extendedProperties.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,
                _velocityEngineConfiguration.logger());

        extendedProperties.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM + ".log4j.category",
                _velocityEngineConfiguration.loggerCategory());

        extendedProperties.setProperty(RuntimeConstants.UBERSPECT_CLASSNAME, SecureUberspector.class.getName());

        extendedProperties.setProperty(VelocityEngine.VM_LIBRARY,
                StringUtil.merge(_velocityEngineConfiguration.velocimacroLibrary()));

        extendedProperties.setProperty(VelocityEngine.VM_LIBRARY_AUTORELOAD, String.valueOf(!cacheEnabled));

        extendedProperties.setProperty(VelocityEngine.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL,
                String.valueOf(!cacheEnabled));

        _velocityEngine.setExtendedProperties(extendedProperties);

        _velocityEngine.init();
    } catch (Exception e) {
        throw new TemplateException(e);
    } finally {
        currentThread.setContextClassLoader(contextClassLoader);
    }
}

From source file:ca.simplegames.micro.viewers.velocity.VelocityViewRenderer.java

public void init() throws Exception {
    ExtendedProperties eprops = new ExtendedProperties();
    eprops.putAll(velocityProperties);/*from   www . j a  v  a  2  s. c  om*/
    eprops.addProperty(RuntimeConstants.RESOURCE_LOADER, "micro");

    eprops.setProperty("micro.resource.loader.description", "Micro internal resource loader.");
    eprops.setProperty("micro.resource.loader.class",
            "ca.simplegames.micro.viewers.velocity.MicroResourceLoader");
    eprops.setProperty("runtime.log.logsystem.class",
            "ca.simplegames.micro.viewers.velocity.VelocityViewRenderer");
    //eprops.setProperty("micro.resource.loader.repository", repository);

    if (resourceCacheEnabled) {
        eprops.setProperty("micro.resource.loader.cache", site.isProduction() ? "true" : "false");
        eprops.setProperty("micro.resource.loader.modificationCheckInterval",
                Integer.toString(getResourceCacheInterval()));
    }

    // Apply properties to VelocityEngine.
    velocityEngine.setExtendedProperties(eprops);
    try {
        velocityEngine.init();
        velocityEngine.setApplicationAttribute(ServletContext.class.getName(), site.getServletContext());
    } catch (Exception ex) {
        log.error("Why does VelocityEngine throw a generic checked exception, after all?", ex);
        throw new VelocityException(ex.getMessage());
    }
    //log.info("Resource loader: " + velocityEngine.getProperty(VelocityEngine.RESOURCE_LOADER));

}

From source file:com.liferay.portal.template.velocity.internal.VelocityTemplateTest.java

@Before
public void setUp() throws Exception {
    VelocityEngineConfiguration velocityEngineConfiguration = ConfigurableUtil
            .createConfigurable(VelocityEngineConfiguration.class, Collections.emptyMap());

    _templateContextHelper = new MockTemplateContextHelper();

    _velocityEngine = new VelocityEngine();

    boolean cacheEnabled = false;

    ExtendedProperties extendedProperties = new FastExtendedProperties();

    extendedProperties.setProperty(VelocityEngine.DIRECTIVE_IF_TOSTRING_NULLCHECK,
            String.valueOf(velocityEngineConfiguration.directiveIfToStringNullCheck()));
    extendedProperties.setProperty(VelocityEngine.EVENTHANDLER_METHODEXCEPTION,
            LiferayMethodExceptionEventHandler.class.getName());
    extendedProperties.setProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,
            StringUtil.merge(velocityEngineConfiguration.restrictedClasses()));
    extendedProperties.setProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_PACKAGES,
            StringUtil.merge(velocityEngineConfiguration.restrictedPackages()));
    extendedProperties.setProperty(VelocityEngine.RESOURCE_LOADER, "liferay");
    extendedProperties.setProperty("liferay." + VelocityEngine.RESOURCE_LOADER + ".cache",
            String.valueOf(cacheEnabled));
    extendedProperties.setProperty(/*from   w w  w.  j  a v  a  2 s. c  om*/
            "liferay." + VelocityEngine.RESOURCE_LOADER + ".resourceModificationCheckInterval",
            velocityEngineConfiguration.resourceModificationCheckInterval() + "");
    extendedProperties.setProperty("liferay." + VelocityEngine.RESOURCE_LOADER + ".class",
            LiferayResourceLoader.class.getName());
    extendedProperties.setProperty(VelocityEngine.RESOURCE_MANAGER_CLASS,
            LiferayResourceManager.class.getName());
    extendedProperties.setProperty(
            "liferay." + VelocityEngine.RESOURCE_MANAGER_CLASS + ".resourceModificationCheckInterval",
            velocityEngineConfiguration.resourceModificationCheckInterval() + "");
    extendedProperties.setProperty(VelocityTemplateResourceLoader.class.getName(), _templateResourceLoader);
    extendedProperties.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,
            velocityEngineConfiguration.logger());
    extendedProperties.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM + ".log4j.category",
            velocityEngineConfiguration.loggerCategory());
    extendedProperties.setProperty(RuntimeConstants.UBERSPECT_CLASSNAME, SecureUberspector.class.getName());
    extendedProperties.setProperty(VelocityEngine.VM_LIBRARY,
            StringUtil.merge(velocityEngineConfiguration.velocimacroLibrary()));
    extendedProperties.setProperty(VelocityEngine.VM_LIBRARY_AUTORELOAD, String.valueOf(!cacheEnabled));
    extendedProperties.setProperty(VelocityEngine.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL,
            String.valueOf(!cacheEnabled));

    _velocityEngine.setExtendedProperties(extendedProperties);

    _velocityEngine.init();
}

From source file:com.arcbees.plugin.velocity.ResourceManagerImplCustom.java

/**
 * This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader. This
 * Hashtable will be passed in when initializing the the template loader.
 *//* ww w.  j ava  2 s .  c o m*/
private void assembleResourceLoaderInitializers() {
    Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER);
    StringUtils.trimStrings(resourceLoaderNames);

    for (Iterator it = resourceLoaderNames.iterator(); it.hasNext();) {

        /*
         * The loader id might look something like the following:
         *
         * file.resource.loader
         *
         * The loader id is the prefix used for all properties
         * pertaining to a particular loader.
         */
        String loaderName = (String) it.next();
        StringBuffer loaderID = new StringBuffer(loaderName);
        loaderID.append(".").append(RuntimeConstants.RESOURCE_LOADER);

        ExtendedProperties loaderConfiguration = rsvc.getConfiguration().subset(loaderID.toString());

        /*
         *  we can't really count on ExtendedProperties to give us an empty set
         */

        if (loaderConfiguration == null) {
            log.warn("ResourceManager : No configuration information for resource loader named '" + loaderName
                    + "'. Skipping.");

            continue;
        }

        /*
         *  add the loader name token to the initializer if we need it
         *  for reference later. We can't count on the user to fill
         *  in the 'name' field
         */

        loaderConfiguration.setProperty(RESOURCE_LOADER_IDENTIFIER, loaderName);

        /*
         * Add resources to the list of resource loader
         * initializers.
         */
        sourceInitializerList.add(loaderConfiguration);
    }
}

From source file:bboss.org.apache.velocity.runtime.resource.ResourceManagerImpl.java

/**
 * This will produce a List of Hashtables, each hashtable contains the intialization info for a particular resource loader. This
 * Hashtable will be passed in when initializing the the template loader.
 *//*  w w w . j  a v  a 2  s  .  c  o m*/
private void assembleResourceLoaderInitializers() {
    Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER);
    StringUtils.trimStrings(resourceLoaderNames);

    for (Iterator it = resourceLoaderNames.iterator(); it.hasNext();) {

        /*
         * The loader id might look something like the following:
         *
         * file.resource.loader
         *
         * The loader id is the prefix used for all properties
         * pertaining to a particular loader.
         */
        String loaderName = (String) it.next();
        StringBuffer loaderID = new StringBuffer(loaderName);
        loaderID.append(".").append(RuntimeConstants.RESOURCE_LOADER);

        ExtendedProperties loaderConfiguration = rsvc.getConfiguration().subset(loaderID.toString());

        /*
         *  we can't really count on ExtendedProperties to give us an empty set
         */
        if (loaderConfiguration == null) {
            log.debug("ResourceManager : No configuration information found " + "for resource loader named '"
                    + loaderName + "' (id is " + loaderID + "). Skipping it...");
            continue;
        }

        /*
         *  add the loader name token to the initializer if we need it
         *  for reference later. We can't count on the user to fill
         *  in the 'name' field
         */

        loaderConfiguration.setProperty(RESOURCE_LOADER_IDENTIFIER, loaderName);

        /*
         * Add resources to the list of resource loader
         * initializers.
         */
        sourceInitializerList.add(loaderConfiguration);
    }
}

From source file:org.apache.flex.forks.velocity.runtime.resource.ResourceManagerImpl.java

/**
 * This will produce a List of Hashtables, each
 * hashtable contains the intialization info for
 * a particular resource loader. This Hastable
 * will be passed in when initializing the
 * the template loader./*w w w.  j ava2s .c o  m*/
 */
private void assembleResourceLoaderInitializers() {
    if (resourceLoaderInitializersActive) {
        return;
    }

    Vector resourceLoaderNames = rsvc.getConfiguration().getVector(RuntimeConstants.RESOURCE_LOADER);

    for (int i = 0; i < resourceLoaderNames.size(); i++) {
        /*
         * The loader id might look something like the following:
         *
         * file.resource.loader
         *
         * The loader id is the prefix used for all properties
         * pertaining to a particular loader.
         */
        String loaderID = resourceLoaderNames.get(i) + "." + RuntimeConstants.RESOURCE_LOADER;

        ExtendedProperties loaderConfiguration = rsvc.getConfiguration().subset(loaderID);

        /*
         *  we can't really count on ExtendedProperties to give us an empty set
         */

        if (loaderConfiguration == null) {
            rsvc.warn("ResourceManager : No configuration information for resource loader named '"
                    + resourceLoaderNames.get(i) + "'. Skipping.");
            continue;
        }

        /*
         *  add the loader name token to the initializer if we need it
         *  for reference later. We can't count on the user to fill
         *  in the 'name' field
         */

        loaderConfiguration.setProperty(RESOURCE_LOADER_IDENTIFIER, resourceLoaderNames.get(i));

        /*
         * Add resources to the list of resource loader
         * initializers.
         */
        sourceInitializerList.add(loaderConfiguration);
    }

    resourceLoaderInitializersActive = true;
}