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

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

Introduction

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

Prototype

public String getString(String key) 

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.cyclopsgroup.tornado.hibernate.impl.DefaultHibernateService.java

/**
 * Override method DefaultHibernateFactory in supper class
 *
 * @see org.apache.avalon.framework.activity.Initializable#initialize()
 *//*from w  ww . ja  va 2 s  . c  om*/
public void initialize() throws Exception {
    Enumeration enu = getClass().getClassLoader()
            .getResources("META-INF/cyclopsgroup/hibernate-entities.properties");
    ExtendedProperties props = new ExtendedProperties();
    while (enu.hasMoreElements()) {
        URL resource = (URL) enu.nextElement();
        props.load(resource.openStream());
    }

    for (Iterator i = hibernateProperties.keySet().iterator(); i.hasNext();) {
        String name = (String) i.next();

        org.hibernate.cfg.Configuration c = new org.hibernate.cfg.Configuration();
        Properties p = (Properties) hibernateProperties.get(name);
        c.setProperties(p);
        for (Iterator j = props.getKeys(); j.hasNext();) {
            String key = (String) j.next();
            String value = (String) props.getString(key);

            if (StringUtils.equals(value, name)) {
                try {
                    Class entityClass = Class.forName(key);
                    c.addClass(entityClass);
                    entityClasses.put(value, entityClass);
                } catch (Exception e) {
                    getLogger().warn("Entity " + key + " is not loaded", e);
                }
            }
        }
        hibernateConfigurations.put(name, c);
        SessionFactory sessionFactory = c.buildSessionFactory();
        sessionFactories.put(name, sessionFactory);
    }
}

From source file:bboss.org.apache.velocity.texen.ant.TexenTask.java

/**
 * Set the context properties that will be
 * fed into the initial context be the/*from  ww  w .ja v  a  2  s.  co m*/
 * generating process starts.
 * @param file
 */
public void setContextProperties(String file) {
    String[] sources = StringUtils.split(file, ",");
    contextProperties = new ExtendedProperties();

    // Always try to get the context properties resource
    // from a file first. Templates may be taken from a JAR
    // file but the context properties resource may be a
    // resource in the filesystem. If this fails than attempt
    // to get the context properties resource from the
    // classpath.
    for (int i = 0; i < sources.length; i++) {
        ExtendedProperties source = new ExtendedProperties();

        try {
            // resolve relative path from basedir and leave
            // absolute path untouched.
            File fullPath = project.resolveFile(sources[i]);
            log("Using contextProperties file: " + fullPath);
            source.load(new FileInputStream(fullPath));
        } catch (IOException e) {
            ClassLoader classLoader = this.getClass().getClassLoader();

            try {
                InputStream inputStream = classLoader.getResourceAsStream(sources[i]);

                if (inputStream == null) {
                    throw new BuildException("Context properties file " + sources[i]
                            + " could not be found in the file system or on the classpath!");
                } else {
                    source.load(inputStream);
                }
            } catch (IOException ioe) {
                source = null;
            }
        }

        if (source != null) {
            for (Iterator j = source.getKeys(); j.hasNext();) {
                String name = (String) j.next();
                String value = StringUtils.nullTrim(source.getString(name));
                contextProperties.setProperty(name, value);
            }
        }
    }
}

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

public void upgrade() {
    try {/*from w ww .j  ava  2  s.  c  om*/

        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 www .ja  va2  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) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (BackingStoreException e) {
        // do nothing
    }
}

From source file:org.apache.cayenne.unit.di.server.ConnectionProperties.java

/**
 * Creates a DataSourceInfo object from a set of properties.
 *///from ww w.  ja  v  a2s  . c om
private DataSourceInfo buildDataSourceInfo(ExtendedProperties props) {
    DataSourceInfo dsi = new DataSourceInfo();

    String adapter = props.getString(ADAPTER_KEY);

    // try legacy adapter key
    if (adapter == null) {
        adapter = props.getString(ADAPTER20_KEY);
    }

    dsi.setAdapterClassName(adapter);
    dsi.setUserName(props.getString(USER_NAME_KEY));
    dsi.setPassword(props.getString(PASSWORD_KEY));
    dsi.setDataSourceUrl(props.getString(URL_KEY));
    dsi.setJdbcDriver(props.getString(DRIVER_KEY));
    dsi.setMinConnections(MIN_CONNECTIONS);
    dsi.setMaxConnections(MAX_CONNECTIONS);

    return dsi;
}

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

public void init(ExtendedProperties configuration) {
    dataSourceName = configuration.getString("resource.datasource");
    tableName = configuration.getString("resource.table");
    keyColumn = configuration.getString("resource.keycolumn");
    templateColumn = configuration.getString("resource.templatecolumn");
    timestampColumn = configuration.getString("resource.timestampcolumn");

    Runtime.info("Resources Loaded From: " + dataSourceName + "/" + tableName);
    Runtime.info(/*ww  w .  j a  v a  2s  . co m*/
            "Resource Loader using columns: " + keyColumn + ", " + templateColumn + " and " + timestampColumn);
    Runtime.info("Resource Loader Initalized.");
}

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

/**
 * This initialization is used by all resource
 * loaders and must be called to set up common
 * properties shared by all resource loaders
 *//*from   w  w  w.j  a  va2s .co  m*/
public void commonInit(RuntimeServices rs, ExtendedProperties configuration) {
    this.rsvc = rs;

    /*
     *  these two properties are not required for all loaders.
     *  For example, for ClasspathLoader, what would cache mean? 
     *  so adding default values which I think are the safest
     *
     *  don't cache, and modCheckInterval irrelevant...
     */

    isCachingOn = configuration.getBoolean("cache", false);
    modificationCheckInterval = configuration.getLong("modificationCheckInterval", 0);

    /*
     * this is a must!
     */

    className = configuration.getString("class");
}

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

/**
 * Initialize the ResourceManager./*from w  w  w  . ja  v  a2  s  . co  m*/
 */
public void initialize(RuntimeServices rs) throws Exception {
    rsvc = rs;

    rsvc.info("Default ResourceManager initializing. (" + this.getClass() + ")");

    ResourceLoader resourceLoader;

    assembleResourceLoaderInitializers();

    for (int i = 0; i < sourceInitializerList.size(); i++) {
        ExtendedProperties configuration = (ExtendedProperties) sourceInitializerList.get(i);
        String loaderClass = configuration.getString("class");

        if (loaderClass == null) {
            rsvc.error("Unable to find '" + configuration.getString(RESOURCE_LOADER_IDENTIFIER)
                    + ".resource.loader.class' specification in configuation."
                    + " This is a critical value.  Please adjust configuration.");
            continue;
        }

        resourceLoader = ResourceLoaderFactory.getLoader(rsvc, loaderClass);
        resourceLoader.commonInit(rsvc, configuration);
        resourceLoader.init(configuration);
        resourceLoaders.add(resourceLoader);

    }

    /*
     * now see if this is overridden by configuration
     */

    logWhenFound = rsvc.getBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true);

    /*
     *  now, is a global cache specified?
     */

    String claz = rsvc.getString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS);

    Object o = null;

    if (claz != null && claz.length() > 0) {
        try {
            o = Class.forName(claz).newInstance();
        } catch (ClassNotFoundException cnfe) {
            String err = "The specified class for ResourceCache (" + claz
                    + ") does not exist (or is not accessible to the current classlaoder).";
            rsvc.error(err);

            o = null;
        }

        if (!(o instanceof ResourceCache)) {
            String err = "The specified class for ResourceCache (" + claz
                    + ") does not implement org.apache.runtime.resource.ResourceCache."
                    + " ResourceManager. Using default ResourceCache implementation.";

            rsvc.error(err);

            o = null;
        }
    }

    /*
     *  if we didn't get through that, just use the default.
     */

    if (o == null)
        o = new ResourceCacheImpl();

    globalCache = (ResourceCache) o;

    globalCache.initialize(rsvc);

    rsvc.info("Default ResourceManager initialization complete.");

}

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

/**
 * Runs the test.//from  w  ww.j a v  a  2s  . c om
 */
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.flex.forks.velocity.texen.ant.TexenTask.java

/**
 * Set the context properties that will be
 * fed into the initial context be the//  w w w.  j  a  va  2  s  .  c  o  m
 * generating process starts.
 */
public void setContextProperties(String file) {
    String[] sources = StringUtils.split(file, ",");
    contextProperties = new ExtendedProperties();

    // Always try to get the context properties resource
    // from a file first. Templates may be taken from a JAR
    // file but the context properties resource may be a 
    // resource in the filesystem. If this fails than attempt
    // to get the context properties resource from the
    // classpath.
    for (int i = 0; i < sources.length; i++) {
        ExtendedProperties source = new ExtendedProperties();

        try {
            // resolve relative path from basedir and leave
            // absolute path untouched.
            File fullPath = project.resolveFile(sources[i]);
            log("Using contextProperties file: " + fullPath);
            source.load(new FileInputStream(fullPath));
        } catch (Exception e) {
            ClassLoader classLoader = this.getClass().getClassLoader();

            try {
                InputStream inputStream = classLoader.getResourceAsStream(sources[i]);

                if (inputStream == null) {
                    throw new BuildException("Context properties file " + sources[i]
                            + " could not be found in the file system or on the classpath!");
                } else {
                    source.load(inputStream);
                }
            } catch (IOException ioe) {
                source = null;
            }
        }

        Iterator j = source.getKeys();

        while (j.hasNext()) {
            String name = (String) j.next();
            String value = source.getString(name);
            contextProperties.setProperty(name, value);
        }
    }
}