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

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

Introduction

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

Prototype

public Iterator getKeys() 

Source Link

Document

Get the list of the keys contained in the configuration repository.

Usage

From source file:adalid.commons.properties.PropertiesHandler.java

public static void printExtendedProperties(ExtendedProperties extendedProperties) {
    ArrayList<String> list = new ArrayList<>();
    for (Iterator i = extendedProperties.getKeys(); i.hasNext();) {
        list.add((String) i.next());
    }//from ww  w .  j ava 2  s  .  c  o m
    String[] names = new String[list.size()];
    list.toArray(names);
    Arrays.sort(names);
    String[] values;
    for (String name : names) {
        values = extendedProperties.getStringArray(name);
        logger.trace(name + " = "
                + (StringUtils.containsIgnoreCase(name, "password") ? "***" : getArrayString(values)));
    }
}

From source file:adalid.commons.properties.PropertiesHandler.java

private static void log(ExtendedProperties properties, Level level) {
    Object next;/* w w w .  j  a va 2s. co m*/
    Set<String> names = new TreeSet<>();
    Iterator iterator = properties.getKeys();
    if (iterator != null) {
        while (iterator.hasNext()) {
            next = iterator.next();
            if (next instanceof String) {
                names.add((String) next);
            }
        }
    }
    String value;
    for (String name : names) {
        value = properties.getString(name);
        logger.log(level, name + " = " + (StringUtils.containsIgnoreCase(name, "password") ? "***" : value));
    }
}

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

/**
 * Override method DefaultHibernateFactory in supper class
 *
 * @see org.apache.avalon.framework.activity.Initializable#initialize()
 */// ww  w .ja  v a  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  .j a va2 s.c  o 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.unit.di.server.ConnectionProperties.java

/**
 * Returns a list of connection names configured in the properties object.
 *//*from w  ww  .  j  a  v  a2 s  .  com*/
private List<String> extractNames(ExtendedProperties props) {
    Iterator<?> it = props.getKeys();
    List<String> list = new ArrayList<String>();

    while (it.hasNext()) {
        String key = (String) it.next();

        int dotInd = key.indexOf('.');
        if (dotInd <= 0 || dotInd >= key.length()) {
            continue;
        }

        String name = key.substring(0, dotInd);
        if (!list.contains(name)) {
            list.add(name);
        }
    }

    return list;
}

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

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

/**
 * Set the context properties that will be
 * fed into the initial context be the/*from   w w  w . j a  v  a  2s .c  om*/
 * 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);
        }
    }
}

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

/**
 * Runs the test./*from   ww w . j a  v  a2 s .c  om*/
 */
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.apache.velocity.tools.config.PropertiesFactoryConfiguration.java

protected void readProperties(ExtendedProperties configProps, Configuration config) {
    ExtendedProperties properties = configProps.subset("property");
    if (properties != null) {
        for (Iterator i = properties.getKeys(); i.hasNext();) {
            String name = (String) i.next();
            String value = properties.getString(name);

            ExtendedProperties propProps = properties.subset(name);
            if (propProps.size() == 1) {
                // then set this as a 'simple' property
                config.setProperty(name, value);
            } else {
                // add it as a convertable property
                Property property = new Property();
                property.setName(name);//from   ww w .j  av a  2 s. c  o m
                property.setValue(value);

                // set the type/converter properties
                setProperties(propProps, property);
            }
        }
    }
}

From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java

protected void readTools(ExtendedProperties tools, ToolboxConfiguration toolbox) {
    for (Iterator i = tools.getKeys(); i.hasNext();) {
        String key = (String) i.next();
        // if it contains a period, it can't be a context key; 
        // it must be a tool property. ignore it for now.
        if (key.indexOf('.') >= 0) {
            continue;
        }//from  ww w . j  a  v  a2  s.  c  om

        String classname = tools.getString(key);
        ToolConfiguration tool = new ToolConfiguration();
        tool.setClassname(classname);
        tool.setKey(key);
        toolbox.addTool(tool);

        // get tool properties prefixed by 'property'
        ExtendedProperties toolProps = tools.subset(key);
        readProperties(toolProps, tool);

        // ok, get tool properties that aren't prefixed by 'property'
        for (Iterator j = toolProps.getKeys(); j.hasNext();) {
            String name = (String) j.next();
            if (!name.equals(tool.getKey())) {
                tool.setProperty(name, toolProps.getString(name));
            }
        }

        // get special props explicitly
        String restrictTo = toolProps.getString("restrictTo");
        tool.setRestrictTo(restrictTo);
    }
}