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

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

Introduction

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

Prototype

public ExtendedProperties() 

Source Link

Document

Creates an empty extended properties object.

Usage

From source file:org.opencms.util.CmsPropertyUtils.java

/**
 * Loads an extended property file and performs unescaping of "," and "=" entries.<p> 
 * //from  w  w w  .  j a va2  s  .c  om
 * @param stream the input stream to read the properties from
 * 
 * @return the initialized extended properties
 * 
 * @throws IOException in case of IO errors 
 */
public static ExtendedProperties loadProperties(InputStream stream) throws IOException {

    ExtendedProperties properties = new ExtendedProperties();
    properties.load(stream);

    unescapeProperties(properties);

    return properties;
}

From source file:org.opencms.util.CmsPropertyUtils.java

/**
 * Loads an extended property file and performs unescaping of "," and "=" entries.<p> 
 * /* w ww.  j  a v  a  2s.co  m*/
 * @param file the file to read the properties from
 * 
 * @return the initialized extended properties
 * 
 * @throws IOException in case of IO errors 
 */
public static ExtendedProperties loadProperties(String file) throws IOException {

    FileInputStream input = null;
    ExtendedProperties properties = null;

    try {
        input = new FileInputStream(new File(file));
        properties = new ExtendedProperties();
        properties.load(input);
        input.close();
    } catch (IOException e) {
        try {
            if (input != null) {
                input.close();
            }
        } catch (Exception ex) {
            // nothing we can do
        }
        throw e;
    }

    unescapeProperties(properties);

    return properties;
}

From source file:org.sakaiproject.kernel.proxy.ProxyClientServiceImpl.java

/**
 * Create resources used by this component.
 * /*from   ww  w . j a  v a 2 s.  c o m*/
 * @param ctx
 * @throws Exception
 */
public void activate(ComponentContext ctx) throws Exception {
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger(this.getClass()));

    velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, JCR_RESOURCE_LOADER);
    velocityEngine.setProperty(JCR_RESOURCE_LOADER_CLASS, JcrResourceLoader.class.getName());
    ExtendedProperties configuration = new ExtendedProperties();
    configuration.addProperty(JCR_RESOURCE_LOADER_PATH + ProxyNodeSource.JCR_RESOURCE_LOADER_RESOURCE_SOURCE,
            this);
    velocityEngine.setExtendedProperties(configuration);
    velocityEngine.init();

    httpClientConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    // could set a whole load of connection properties
    httpClientConnectionManager.setParams(params);

    httpClient = new HttpClient(httpClientConnectionManager);
}

From source file:org.sakaiproject.nakamura.proxy.ProxyClientServiceImpl.java

/**
 * Create resources used by this component.
 *
 * @param ctx//from  w  ww. j a v a 2 s. c om
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected void activate(ComponentContext ctx) throws Exception {
    if (ctx != null) {
        Dictionary<String, Object> props = ctx.getProperties();
        configProperties = new HashMap<String, Object>();
        for (Enumeration<String> e = props.keys(); e.hasMoreElements();) {
            String k = e.nextElement();
            configProperties.put(k, props.get(k));
        }
        String[] safePostProcessorNames = (String[]) configProperties.get(SAFE_POSTPROCESSORS);
        if (safePostProcessorNames == null) {
            safeOpenProcessors.add("rss");
            safeOpenProcessors.add("trustedLoginTokenProxyPostProcessor");
        } else {
            for (String pp : safePostProcessorNames) {
                safeOpenProcessors.add(pp);
            }
        }
    } else {
        configProperties = new HashMap<String, Object>();
    }
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger(this.getClass()));

    velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, JCR_RESOURCE_LOADER);
    velocityEngine.setProperty(JCR_RESOURCE_LOADER_CLASS, JcrResourceLoader.class.getName());
    ExtendedProperties configuration = new ExtendedProperties();
    configuration.addProperty(JCR_RESOURCE_LOADER_PATH + ProxyNodeSource.JCR_RESOURCE_LOADER_RESOURCE_SOURCE,
            this);
    velocityEngine.setExtendedProperties(configuration);
    velocityEngine.init();

    httpClientConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    // could set a whole load of connection properties
    httpClientConnectionManager.setParams(params);

    httpClient = new HttpClient(httpClientConnectionManager);

    // allow communications via a proxy server if command line
    // java parameters http.proxyHost,http.proxyPort,http.proxyUser,
    // http.proxyPassword have been provided.
    externalAuthenticatingProxy = false;
    String proxyHost = System.getProperty("http.proxyHost", "");
    int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort", "80"));
    if (!proxyHost.equals("")) {
        // allow communications via a non-authenticating proxy
        httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);

        String proxyUser = System.getProperty("http.proxyUser", "");
        String proxyPassword = System.getProperty("http.proxyPassword", "");
        if (!proxyUser.equals("")) {
            // allow communications via an authenticating proxy
            Credentials credentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
            AuthScope authScope = new AuthScope(proxyHost, proxyPort);
            httpClient.getState().setProxyCredentials(authScope, credentials);
            externalAuthenticatingProxy = true;
        }
    }
}

From source file:org.sakaiproject.nakamura.templates.velocity.VelocityTemplateService.java

protected void activate(ComponentContext ctx) throws Exception {
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger(this.getClass()));

    velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "jcr");
    velocityEngine.setProperty("jcr.resource.loader.class", JcrResourceLoader.class.getName());
    ExtendedProperties configuration = new ExtendedProperties();
    configuration.addProperty("jcr.resource.loader.resourceSource", this);
    velocityEngine.setExtendedProperties(configuration);
    velocityEngine.init();/*from  ww  w . jav a2 s  .co m*/
}

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 w w  w  . j  av  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;
}

From source file:paremus.PSFDeployRunWarMojo.java

public PSFDeployRunWarMojo() {
    final ExtendedProperties extendedProperties = new ExtendedProperties();
    try {/*  www .  j a  v a2  s . c o m*/
        extendedProperties.load(AbstractPSFMojo.class.getResourceAsStream("/psf-velocity.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    velocity = new VelocityEngine();
    velocity.setExtendedProperties(extendedProperties);
    velocity.init();
}