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:org.apache.manifoldcf.core.i18n.Messages.java

/** Create and initialize a velocity engine instance, given a class.
*//*from  w ww. j a  v a2s.  co  m*/
public static VelocityEngine createVelocityEngine(Class classInstance) throws ManifoldCFException {
    VelocityEngine engine = new VelocityEngine();
    // Now configure it
    org.apache.commons.collections.ExtendedProperties configuration = new org.apache.commons.collections.ExtendedProperties();
    // This is the property that describes the id's of the resource loaders.
    configuration.setProperty(VelocityEngine.RESOURCE_LOADER, "mcf");
    // This is the property which describes the resource loader itself
    configuration.setProperty("mcf." + VelocityEngine.RESOURCE_LOADER + ".instance",
            new MCFVelocityResourceLoader(classInstance));
    engine.setExtendedProperties(configuration);
    engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
            "org.apache.velocity.runtime.log.Log4JLogChute");
    engine.setProperty("runtime.log.logsystem.log4j.logger", "velocity");
    return engine;
}

From source file: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.
 *//*from   w  ww .j av 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) {
            Logger.debug(this,
                    "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.velocity.tools.view.VelocityView.java

protected void configure(final JeeConfig config, final VelocityEngine velocity) {
    // first get the default properties, and bail if we don't find them
    ExtendedProperties defaultProperties = getProperties(DEFAULT_PROPERTIES_PATH, true);
    // if using Velocity engine prior to 1.6.x, remove WebappUberspector
    // (this hack will disappear once tools require Velocity 1.6.x+)
    try {// w ww .j  ava2  s. co  m
        Class.forName("org.apache.velocity.tools.view.WebappUberspector");
    } catch (Throwable t) {
        // remove WebappUberspector from the list of introspectors
        List introspectors = defaultProperties.getList(VelocityEngine.UBERSPECT_CLASSNAME);
        introspectors.remove("org.apache.velocity.tools.view.WebappUberspector");
        defaultProperties.setProperty(VelocityEngine.UBERSPECT_CLASSNAME, introspectors);
    }
    velocity.setExtendedProperties(defaultProperties);

    // check for application-wide user props in the context init params
    String appPropsPath = servletContext.getInitParameter(PROPERTIES_KEY);
    setProps(velocity, appPropsPath, true);

    // check for servlet-wide user props in the config init params at the
    // conventional location, and be silent if they're missing
    setProps(velocity, USER_PROPERTIES_PATH, false);

    // check for a custom location for servlet-wide user props
    String servletPropsPath = config.getInitParameter(PROPERTIES_KEY);
    setProps(velocity, servletPropsPath, true);
}

From source file:org.carrot2.util.attribute.metadata.VelocityInitializer.java

/**
 * Initialize Velocity engine instance, disables logging, sets bundle-relative
 * resource loader./*from  w  w w .  j  ava 2  s.  co m*/
 */
public static RuntimeInstance createInstance(final Messager msg) {
    try {
        final ExtendedProperties p = new ExtendedProperties();
        p.setProperty(RuntimeConstants.SET_NULL_ALLOWED, "true");
        p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());

        p.setProperty("resource.loader", "apt");
        p.setProperty("apt.resource.loader.instance",
                new ClassRelativeResourceLoader(msg, VelocityInitializer.class));

        final RuntimeInstance velocity = new RuntimeInstance();
        velocity.setConfiguration(p);
        return velocity;
    } catch (Exception e) {
        throw new RuntimeException("Velocity initialization failed.", e);
    }
}

From source file:org.carrot2.workbench.velocity.VelocityInitializer.java

/**
 * Initialize Velocity engine instance, disables logging,
 * sets bundle-relative resource loader.
 *//*from   w w w  .  j  a  v  a  2  s  . c  o m*/
public static RuntimeInstance createInstance(String bundleID, String templatePrefix) {
    try {
        final ExtendedProperties p = new ExtendedProperties();
        p.setProperty("resource.loader", "bundle");
        p.setProperty("bundle.resource.loader.instance", new BundleResourceLoader(bundleID, templatePrefix));
        p.setProperty(RuntimeConstants.SET_NULL_ALLOWED, "true");

        // Disable separate Velocity logging.
        p.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName());

        final RuntimeInstance velocity = new RuntimeInstance();
        velocity.setConfiguration(p);
        return velocity;
    } catch (Exception e) {
        throw new RuntimeException("Velocity initialization failed.", e);
    }
}

From source file:org.jpublish.view.velocity.VelocityViewRenderer.java

/**
 * Initialize the ViewRenderer./*  www . ja v a 2s .co m*/
 *
 * @throws Exception Any Exception
 */

public void init() throws Exception {
    log.debug("init()");

    // it may be necessary to put caching support here, in which case
    // the cache parameters should be specified in the view config.

    ExtendedProperties eprops = new ExtendedProperties();
    eprops.putAll(velocityProperties);
    eprops.addProperty(RuntimeConstants.RESOURCE_LOADER, "jpublish");

    eprops.setProperty("jpublish.resource.loader.description", "JPublish internal resource loader.");
    eprops.setProperty("jpublish.resource.loader.class", "org.jpublish.view.velocity.JPublishResourceLoader");
    eprops.setProperty("jpublish.resource.loader.siteContext", siteContext);

    if (resourceCacheEnabled) {
        eprops.setProperty("jpublish.resource.loader.cache", "true");
        eprops.setProperty("jpublish.resource.loader.modificationCheckInterval",
                Integer.toString(getResourceCacheInterval()));
    }

    // Apply properties to VelocityEngine.
    velocityEngine.setExtendedProperties(eprops);
    try {
        velocityEngine.init();
        velocityEngine.setApplicationAttribute(ServletContext.class.getName(), siteContext.getServletContext());
    } catch (IOException ex) {
        throw ex;
    } catch (VelocityException ex) {
        throw ex;
    } catch (RuntimeException ex) {
        throw ex;
    } 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:org.kalypso.metadoc.ui.ConfigurationWizardPage.java

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 *//*from   w w  w .  ja  v  a  2s . co m*/
@Override
public void createControl(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    for (int i = 0; i < m_editableKeys.length; i++) {
        final String key = m_editableKeys[i];

        final Label label = new Label(composite, SWT.LEAD);
        label.setText(m_labels[i]);

        final Text text = new Text(composite, SWT.LEAD);
        text.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
        text.setText(m_config.getString(key, "")); //$NON-NLS-1$

        final ExtendedProperties config = m_config;
        text.addModifyListener(new ModifyListener() {
            @Override
            public void modifyText(final ModifyEvent e) {
                config.setProperty(key, text.getText());
            }
        });
    }

    setControl(composite);
}

From source file:org.openflexo.velocity.FlexoVelocity.java

/**
 * @throws Exception//from www. j a  v a2 s  .  c o m
 * 
 */
public synchronized static void init() throws Exception {
    if (!isInitialized) {
        // 1. We load properties with the Java object because it loads property files correctly unlike ExtendedProperties (which does
        // not handle properly "\ " as value " ")
        Properties p = new Properties();
        p.load(new FileInputStream(new FileResource("Config/velocity.properties")));
        for (Entry<Object, Object> e : p.entrySet()) {
            String value = e.getValue().toString();
            if (value.indexOf("${") > -1) {
                for (Entry<Object, Object> sp : System.getProperties().entrySet()) {
                    value = value.replace("${" + sp.getKey() + "}", sp.getValue().toString());
                }
                p.setProperty(e.getKey().toString(), value);
            }

        }
        // 2. We convert properties to extended properties (this conversion only handles values of type String (i.e., a VelocityLogger
        // cannot be set directly in the Properties, see 3.)
        ExtendedProperties ep = ExtendedProperties.convertProperties(p);
        VelocityLogger vl = new VelocityLogger();
        // 3. We set our logger so that it does not try to use its own
        ep.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, vl);
        // 4. We force our configuration to be loaded
        RuntimeSingleton.getRuntimeServices().setConfiguration(ep);
        // 5. We initialize properly Velocity passing no properties at all!
        Velocity.init();
        isInitialized = true;
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Velocity Engine started");
        }
    }
}

From source file:org.sakaiproject.vm.VelocityServlet.java

/**
 * Called by the VelocityServlet init(). We want to set a set of properties so that templates will be found in the webapp root. This makes this easier to work with as an example, so a new user doesn't have to worry about config issues when first
 * figuring things out/*from  ww w  .  ja v a  2s.  co m*/
 */
protected ExtendedProperties loadConfiguration(ServletConfig config) throws IOException, FileNotFoundException {
    // This is to support old config property.
    String configPath = config.getInitParameter("properties");
    ExtendedProperties p;
    if (configPath != null && configPath.length() > 0) {
        p = new ExtendedProperties();
        if (!configPath.startsWith("/")) {
            configPath = "/" + configPath;
        }
        p.load(getServletContext().getResourceAsStream(configPath));
    } else {
        // load the properties as configured in the servlet init params
        p = super.loadConfiguration(config);
    }

    /*
     * first, we set the template path for the FileResourceLoader to the root of the webapp. This probably won't work under in a WAR under WebLogic, but should under tomcat :)
     */

    String path = config.getServletContext().getRealPath("/");

    if (path == null) {
        getVelocityEngine().getLog().debug(" VelocityServlet.loadConfiguration() : unable to "
                + "get the current webapp root.  Using '/'. Please fix.");
        path = "/";
    }

    p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);

    /**
     * and the same for the log file
     */
    p.setProperty("runtime.log", path + p.getProperty("runtime.log"));

    return p;
}