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

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

Introduction

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

Prototype

public Vector getVector(String key) 

Source Link

Document

Get a Vector of strings associated with the given configuration key.

Usage

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

/**
 * @see bboss.org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
 *///from   w  w  w.  ja  v  a2  s. co  m
public void init(ExtendedProperties configuration) {
    if (log.isTraceEnabled()) {
        log.trace("FileResourceLoader : initialization starting.");
    }

    paths.addAll(configuration.getVector("path"));

    // unicode files may have a BOM marker at the start, but Java
    // has problems recognizing the UTF-8 bom. Enabling unicode will
    // recognize all unicode boms.
    unicode = configuration.getBoolean("unicode", false);

    if (log.isDebugEnabled()) {
        log.debug("Do unicode file recognition:  " + unicode);
    }

    if (log.isDebugEnabled()) {
        // trim spaces from all paths
        StringUtils.trimStrings(paths);

        // this section lets tell people what paths we will be using
        int sz = paths.size();
        for (int i = 0; i < sz; i++) {
            log.debug("FileResourceLoader : adding path '" + (String) paths.get(i) + "'");
        }
        log.trace("FileResourceLoader : initialization complete.");
    }
}

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

/**
 * Called by Velocity to initialize the loader
 * @param configuration//from  ww  w .j a  v a2  s  .c  o m
 */
public void init(ExtendedProperties configuration) {
    log.trace("JarResourceLoader : initialization starting.");

    // rest of Velocity engine still use legacy Vector
    // and Hashtable classes. Classes are implicitly
    // synchronized even if we don't need it.
    Vector paths = configuration.getVector("path");
    StringUtils.trimStrings(paths);

    /*
     *  support the old version but deprecate with a log message
     */

    if (paths == null || paths.size() == 0) {
        paths = configuration.getVector("resource.path");
        StringUtils.trimStrings(paths);

        if (paths != null && paths.size() > 0) {
            log.debug("JarResourceLoader : you are using a deprecated configuration"
                    + " property for the JarResourceLoader -> '<name>.resource.loader.resource.path'."
                    + " Please change to the conventional '<name>.resource.loader.path'.");
        }
    }

    if (paths != null) {
        log.debug("JarResourceLoader # of paths : " + paths.size());

        for (int i = 0; i < paths.size(); i++) {
            loadJar((String) paths.get(i));
        }
    }

    log.trace("JarResourceLoader : initialization complete.");
}

From source file:org.apache.cayenne.modeler.preferences.UpgradeCayennePreference.java

public void upgrade() {
    try {/*  w  ww  .ja  v  a 2 s  .c  o  m*/

        if (!Preferences.userRoot().nodeExists(CAYENNE_PREFERENCES_PATH)) {

            File prefsFile = new File(preferencesDirectory(), PREFERENCES_NAME_OLD);
            if (prefsFile.exists()) {
                ExtendedProperties ep = new ExtendedProperties();
                try {
                    ep.load(new FileInputStream(prefsFile));

                    Preferences prefEditor = Preferences.userRoot().node(CAYENNE_PREFERENCES_PATH).node(EDITOR);

                    prefEditor.putBoolean(ModelerPreferences.EDITOR_LOGFILE_ENABLED,
                            ep.getBoolean(EDITOR_LOGFILE_ENABLED_OLD));
                    prefEditor.put(ModelerPreferences.EDITOR_LOGFILE, ep.getString(EDITOR_LOGFILE_OLD));

                    Preferences frefLastProjFiles = prefEditor.node(LAST_PROJ_FILES);

                    Vector arr = ep.getVector(LAST_PROJ_FILES_OLD);

                    while (arr.size() > ModelerPreferences.LAST_PROJ_FILES_SIZE) {
                        arr.remove(arr.size() - 1);
                    }

                    frefLastProjFiles.clear();
                    int size = arr.size();

                    for (int i = 0; i < size; i++) {
                        frefLastProjFiles.put(String.valueOf(i), arr.get(i).toString());
                    }
                } catch (FileNotFoundException e) {
                    LOGGER.error(e);
                } catch (IOException e) {
                    LOGGER.error(e);
                }
            }
        }
    } catch (BackingStoreException e) {
        // do nothing
    }
}

From source file:org.apache.cayenne.pref.UpgradeCayennePreference.java

public void upgrade() {
    try {/*from ww  w.j a  va 2s . co  m*/

        if (!Preferences.userRoot().nodeExists(CAYENNE_PREFERENCES_PATH)) {

            File prefsFile = new File(preferencesDirectory(), PREFERENCES_NAME_OLD);
            if (prefsFile.exists()) {
                ExtendedProperties ep = new ExtendedProperties();
                try {
                    ep.load(new FileInputStream(prefsFile));

                    Preferences prefEditor = Preferences.userRoot().node(CAYENNE_PREFERENCES_PATH).node(EDITOR);

                    prefEditor.putBoolean(ModelerPreferences.EDITOR_LOGFILE_ENABLED,
                            ep.getBoolean(EDITOR_LOGFILE_ENABLED_OLD));
                    prefEditor.put(ModelerPreferences.EDITOR_LOGFILE, ep.getString(EDITOR_LOGFILE_OLD));

                    Preferences frefLastProjFiles = prefEditor.node(LAST_PROJ_FILES);

                    Vector arr = ep.getVector(LAST_PROJ_FILES_OLD);

                    while (arr.size() > ModelerPreferences.LAST_PROJ_FILES_SIZE) {
                        arr.remove(arr.size() - 1);
                    }

                    frefLastProjFiles.clear();
                    int size = arr.size();

                    for (int i = 0; i < size; i++) {
                        frefLastProjFiles.put(String.valueOf(i), arr.get(i).toString());
                    }
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (BackingStoreException e) {
        // do nothing
    }
}

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

public void init(ExtendedProperties configuration) {
    rsvc.info("FileResourceLoader : initialization starting.");

    paths = configuration.getVector("path");

    /*//from  w ww .  j  av  a2  s  . c o  m
     *  lets tell people what paths we will be using
     */

    int sz = paths.size();

    for (int i = 0; i < sz; i++) {
        rsvc.info("FileResourceLoader : adding path '" + (String) paths.get(i) + "'");
    }

    rsvc.info("FileResourceLoader : initialization complete.");
}

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

/**
 * Called by Velocity to initialize the loader
 *///from  w  ww.  j  av  a 2s .  co m
public void init(ExtendedProperties configuration) {
    rsvc.info("JarResourceLoader : initialization starting.");

    Vector paths = configuration.getVector("path");

    /*
     *  support the old version but deprecate with a log message
     */

    if (paths == null || paths.size() == 0) {
        paths = configuration.getVector("resource.path");

        if (paths != null && paths.size() > 0) {
            rsvc.warn("JarResourceLoader : you are using a deprecated configuration"
                    + " property for the JarResourceLoader -> '<name>.resource.loader.resource.path'."
                    + " Please change to the conventional '<name>.resource.loader.path'.");
        }
    }

    rsvc.info("JarResourceLoader # of paths : " + paths.size());

    for (int i = 0; i < paths.size(); i++) {
        loadJar((String) paths.get(i));
    }

    rsvc.info("JarResourceLoader : initialization complete.");
}

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

/**
 * Runs the test.//from   ww  w  .jav a2  s  .  com
 */
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.runtime.resource.loader.FileResourceLoader.java

/**
 * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
 *//*w w w .  j a  v  a2  s .  c om*/
public void init(ExtendedProperties configuration) {
    if (Logger.isDebugEnabled(this.getClass())) {
        Logger.debug(this, "FileResourceLoader : initialization starting.");
    }

    paths.addAll(configuration.getVector("path"));

    // unicode files may have a BOM marker at the start, but Java
    // has problems recognizing the UTF-8 bom. Enabling unicode will
    // recognize all unicode boms.
    unicode = configuration.getBoolean("unicode", false);

    if (Logger.isDebugEnabled(this.getClass())) {
        Logger.debug(this, "Do unicode file recognition:  " + unicode);
    }

    if (Logger.isDebugEnabled(this.getClass())) {
        // trim spaces from all paths
        StringUtils.trimStrings(paths);

        // this section lets tell people what paths we will be using
        int sz = paths.size();
        for (int i = 0; i < sz; i++) {
            Logger.debug(this, "FileResourceLoader : adding path '" + (String) paths.get(i) + "'");
        }
        Logger.debug(this, "FileResourceLoader : initialization complete.");
    }
}

From source file:org.apache.velocity.runtime.resource.loader.JarResourceLoader.java

/**
 * Called by Velocity to initialize the loader
 * @param configuration/*w ww  .  ja va 2s.  c o m*/
 */
public void init(ExtendedProperties configuration) {
    Logger.debug(this, "JarResourceLoader : initialization starting.");

    // rest of Velocity engine still use legacy Vector
    // and Hashtable classes. Classes are implicitly
    // synchronized even if we don't need it.
    Vector paths = configuration.getVector("path");
    StringUtils.trimStrings(paths);

    /*
     *  support the old version but deprecate with a log message
     */

    if (paths == null || paths.size() == 0) {
        paths = configuration.getVector("resource.path");
        StringUtils.trimStrings(paths);

        if (paths != null && paths.size() > 0) {
            Logger.debug(this,
                    "JarResourceLoader : you are using a deprecated configuration"
                            + " property for the JarResourceLoader -> '<name>.resource.loader.resource.path'."
                            + " Please change to the conventional '<name>.resource.loader.path'.");
        }
    }

    if (paths != null) {
        Logger.debug(this, "JarResourceLoader # of paths : " + paths.size());

        for (int i = 0; i < paths.size(); i++) {
            loadJar((String) paths.get(i));
        }
    }

    Logger.debug(this, "JarResourceLoader : initialization complete.");
}

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

/**
 * Runs the test./*from   ww  w  .  j  av a  2 s .com*/
 */
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.");
    }
}