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(String file) throws IOException 

Source Link

Document

Creates and loads the extended properties from the specified file.

Usage

From source file:org.apache.flex.forks.velocity.test.CommonsExtPropTestCase.java

/**
 * Runs the test.//from   w  w w  .ja va2  s . c o m
 */
public void runTest() {
    try {
        assureResultsDirectoryExists(RESULTS_DIR);

        ExtendedProperties c = new ExtendedProperties(TEST_CONFIG);

        FileWriter result = new FileWriter(getFileName(RESULTS_DIR, "output", "res"));

        message(result, "Testing order of keys ...");
        showIterator(result, c.getKeys());

        message(result, "Testing retrieval of CSV values ...");
        showVector(result, c.getVector("resource.loader"));

        message(result, "Testing subset(prefix).getKeys() ...");
        ExtendedProperties subset = c.subset("file.resource.loader");
        showIterator(result, subset.getKeys());

        message(result, "Testing getVector(prefix) ...");
        showVector(result, subset.getVector("path"));

        message(result, "Testing getString(key) ...");
        result.write(c.getString("config.string.value"));
        result.write("\n\n");

        message(result, "Testing getBoolean(key) ...");
        result.write(new Boolean(c.getBoolean("config.boolean.value")).toString());
        result.write("\n\n");

        message(result, "Testing getByte(key) ...");
        result.write(new Byte(c.getByte("config.byte.value")).toString());
        result.write("\n\n");

        message(result, "Testing getShort(key) ...");
        result.write(new Short(c.getShort("config.short.value")).toString());
        result.write("\n\n");

        message(result, "Testing getInt(key) ...");
        result.write(new Integer(c.getInt("config.int.value")).toString());
        result.write("\n\n");

        message(result, "Testing getLong(key) ...");
        result.write(new Long(c.getLong("config.long.value")).toString());
        result.write("\n\n");

        message(result, "Testing getFloat(key) ...");
        result.write(new Float(c.getFloat("config.float.value")).toString());
        result.write("\n\n");

        message(result, "Testing getDouble(key) ...");
        result.write(new Double(c.getDouble("config.double.value")).toString());
        result.write("\n\n");

        message(result, "Testing escaped-comma scalar...");
        result.write(c.getString("escape.comma1"));
        result.write("\n\n");

        message(result, "Testing escaped-comma vector...");
        showVector(result, c.getVector("escape.comma2"));
        result.write("\n\n");

        result.flush();
        result.close();

        if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp")) {
            fail("Output incorrect.");
        }
    } catch (Exception e) {
        System.err.println("Cannot setup CommonsExtPropTestCase!");
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:org.apache.velocity.test.CommonsExtPropTestCase.java

/**
 * Runs the test./* w w  w  .ja  v a2s .  co m*/
 */
public void testExtendedProperties() throws Exception {
    assureResultsDirectoryExists(RESULTS_DIR);

    ExtendedProperties c = new ExtendedProperties(TEST_CONFIG);

    FileWriter result = new FileWriter(getFileName(RESULTS_DIR, "output", "res"));

    message(result, "Testing order of keys ...");
    showIterator(result, c.getKeys());

    message(result, "Testing retrieval of CSV values ...");
    showVector(result, c.getVector("resource.loader"));

    message(result, "Testing subset(prefix).getKeys() ...");
    ExtendedProperties subset = c.subset("file.resource.loader");
    showIterator(result, subset.getKeys());

    message(result, "Testing getVector(prefix) ...");
    showVector(result, subset.getVector("path"));

    message(result, "Testing getString(key) ...");
    result.write(c.getString("config.string.value"));
    result.write("\n\n");

    message(result, "Testing getBoolean(key) ...");
    result.write(new Boolean(c.getBoolean("config.boolean.value")).toString());
    result.write("\n\n");

    message(result, "Testing getByte(key) ...");
    result.write(new Byte(c.getByte("config.byte.value")).toString());
    result.write("\n\n");

    message(result, "Testing getShort(key) ...");
    result.write(new Short(c.getShort("config.short.value")).toString());
    result.write("\n\n");

    message(result, "Testing getInt(key) ...");
    result.write(new Integer(c.getInt("config.int.value")).toString());
    result.write("\n\n");

    message(result, "Testing getLong(key) ...");
    result.write(new Long(c.getLong("config.long.value")).toString());
    result.write("\n\n");

    message(result, "Testing getFloat(key) ...");
    result.write(new Float(c.getFloat("config.float.value")).toString());
    result.write("\n\n");

    message(result, "Testing getDouble(key) ...");
    result.write(new Double(c.getDouble("config.double.value")).toString());
    result.write("\n\n");

    message(result, "Testing escaped-comma scalar...");
    result.write(c.getString("escape.comma1"));
    result.write("\n\n");

    message(result, "Testing escaped-comma vector...");
    showVector(result, c.getVector("escape.comma2"));
    result.write("\n\n");

    result.flush();
    result.close();

    if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp")) {
        fail("Output incorrect.");
    }
}

From source file:org.dspace.app.xmlui.aspect.discovery.json.JSONSolrSearcher.java

@Override
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
        throws ProcessingException, SAXException, IOException {
    //Retrieve all the given parameters
    Request request = ObjectModelHelper.getRequest(objectModel);
    this.response = ObjectModelHelper.getResponse(objectModel);

    query = request.getParameter(CommonParams.Q);
    if (query == null) {
        query = "*:*";
    }//from  w w  w  . j  av a 2  s.  c  o  m

    //Retrieve all our filter queries
    filterQueries = request.getParameterValues(CommonParams.FQ);

    //Retrieve our facet fields
    facetFields = request.getParameterValues(FacetParams.FACET_FIELD);

    //Retrieve our facet limit (if any)
    if (request.getParameter(FacetParams.FACET_LIMIT) != null) {
        try {
            facetLimit = Integer.parseInt(request.getParameter(FacetParams.FACET_LIMIT));
        } catch (Exception e) {
            //Should an invalid value be supplied use -1
            facetLimit = -1;
        }
    } else {
        facetLimit = -1;
    }

    //Retrieve our sorting value
    facetSort = request.getParameter(FacetParams.FACET_SORT);
    //Make sure we have a valid sorting value
    if (!FacetParams.FACET_SORT_INDEX.equals(facetSort) && !FacetParams.FACET_SORT_COUNT.equals(facetSort)) {
        facetSort = null;
    }

    //Retrieve our facet min count
    facetMinCount = 1;
    try {
        facetMinCount = Integer.parseInt(request.getParameter(FacetParams.FACET_MINCOUNT));
    } catch (Exception e) {
        facetMinCount = 1;
    }
    jsonWrf = request.getParameter("json.wrf");

    //Retrieve our discovery solr path
    ExtendedProperties props = null;
    //Method that will retrieve all the possible configs we have

    props = ExtendedProperties.convertProperties(ConfigurationManager.getProperties());

    InputStream is = null;
    try {
        File config = new File(props.getProperty("dspace.dir") + "/config/dspace-solr-search.cfg");
        if (config.exists()) {
            props.combine(new ExtendedProperties(config.getAbsolutePath()));
        } else {
            is = SolrServiceImpl.class.getResourceAsStream("dspace-solr-search.cfg");
            ExtendedProperties defaults = new ExtendedProperties();
            defaults.load(is);
            props.combine(defaults);
        }
    } catch (Exception e) {
        log.error("Error while retrieving solr url", e);
        e.printStackTrace();
    } finally {
        if (is != null) {
            is.close();
        }
    }

    if (props.getProperty("solr.search.server") != null) {
        this.solrServerUrl = props.getProperty("solr.search.server").toString();
    }

}

From source file:org.objectstyle.cayenne.conf.ConnectionProperties.java

/**
 * Loads connection properties from $HOME/.cayenne/connection.properties.
 *//*from  www .  j av a  2  s  .  com*/
protected static ConnectionProperties loadDefaultProperties() {
    File f = CayenneUserDir.getInstance().resolveFile(PROPERTIES_FILE);

    try {
        if (f.exists()) {
            return new ConnectionProperties(new ExtendedProperties(f.getAbsolutePath()));
        } else {
            // lets touch this file so that users would get a clue of what it is
            createSamplePropertiesFile(f);
        }
    } catch (IOException e) {
        logObj.warn("Error loading connection properties. Ignoring..", e);
    }

    return new ConnectionProperties(new ExtendedProperties());
}

From source file:org.opencms.configuration.TestParameterConfiguration.java

/**
 * Test reading the parameter configuration.<p>
 * /*from  w w  w .  java 2 s  . c  o  m*/
 * @throws Exception
 */
public void testReadParameterConfiguration() throws Exception {

    String testPropPath = "org/opencms/configuration/opencms-test.properties";
    URL url = this.getClass().getClassLoader().getResource(testPropPath);
    File file = new File(url.getPath());
    System.out.println("URL: " + url);
    System.out.println("File: " + file);
    // make sure the test properties file is found
    assertTrue("Test property file '" + file.getAbsolutePath() + "' not found", file.exists());

    CmsParameterConfiguration cmsProp = new CmsParameterConfiguration(file.getAbsolutePath());
    assertEquals("C:\\dev\\workspace\\opencms-core\\test\\data", cmsProp.get("test.path.one"));

    // test some of the more advanced features
    assertEquals(4, cmsProp.getList("test.list").size());
    assertEquals(3, cmsProp.getList("test.otherlist").size());
    assertEquals("comma, escaped with \\ backslash", cmsProp.get("test.escaping"));
    assertEquals("this is a long long long long long long line!", cmsProp.get("test.multiline"));

    // test compatibility with Collection Extended Properties
    ExtendedProperties extProp = new ExtendedProperties(file.getAbsolutePath());
    assertEquals(extProp.size(), cmsProp.size());
    for (String key : cmsProp.keySet()) {
        Object value = cmsProp.getObject(key);
        assertTrue("Key '" + key + "' not found in CmsConfiguration", extProp.containsKey(key));
        assertTrue("Objects for '" + key + "' not equal", value.equals(extProp.getProperty(key)));
    }
}