Example usage for java.util Properties propertyNames

List of usage examples for java.util Properties propertyNames

Introduction

In this page you can find the example usage for java.util Properties propertyNames.

Prototype

public Enumeration<?> propertyNames() 

Source Link

Document

Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:org.nuxeo.runtime.datasource.BasicManagedDataSourceFactory.java

/**
 * Creates and configures a {@link BasicManagedDataSource} instance based on
 * the given properties.//from  www  .j  a  v  a 2  s.  c o  m
 *
 * @param properties the datasource configuration properties
 * @throws Exception if an error occurs creating the data source
 */
public static DataSource createDataSource(Properties properties) throws Exception {
    BasicManagedDataSource dataSource = new BasicManagedDataSource();

    String value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT);
    if (value != null) {
        dataSource.setDefaultAutoCommit(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_DEFAULTREADONLY);
    if (value != null) {
        dataSource.setDefaultReadOnly(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_DEFAULTTRANSACTIONISOLATION);
    if (value != null) {
        int level = UNKNOWN_TRANSACTIONISOLATION;
        if ("NONE".equalsIgnoreCase(value)) {
            level = Connection.TRANSACTION_NONE;
        } else if ("READ_COMMITTED".equalsIgnoreCase(value)) {
            level = Connection.TRANSACTION_READ_COMMITTED;
        } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) {
            level = Connection.TRANSACTION_READ_UNCOMMITTED;
        } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) {
            level = Connection.TRANSACTION_REPEATABLE_READ;
        } else if ("SERIALIZABLE".equalsIgnoreCase(value)) {
            level = Connection.TRANSACTION_SERIALIZABLE;
        } else {
            try {
                level = Integer.parseInt(value);
            } catch (NumberFormatException e) {
                System.err.println("Could not parse defaultTransactionIsolation: " + value);
                System.err.println("WARNING: defaultTransactionIsolation not set");
                System.err.println("using default value of database driver");
                level = UNKNOWN_TRANSACTIONISOLATION;
            }
        }
        dataSource.setDefaultTransactionIsolation(level);
    }

    value = properties.getProperty(PROP_DEFAULTCATALOG);
    if (value != null) {
        dataSource.setDefaultCatalog(value);
    }

    value = properties.getProperty(PROP_DRIVERCLASSNAME);
    if (value != null) {
        dataSource.setDriverClassName(value);
    }

    value = properties.getProperty(PROP_MAXACTIVE);
    if (value != null) {
        dataSource.setMaxActive(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MAXIDLE);
    if (value != null) {
        dataSource.setMaxIdle(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MINIDLE);
    if (value != null) {
        dataSource.setMinIdle(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_INITIALSIZE);
    if (value != null) {
        dataSource.setInitialSize(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MAXWAIT);
    if (value != null) {
        dataSource.setMaxWait(Long.parseLong(value));
    }

    value = properties.getProperty(PROP_TESTONBORROW);
    if (value != null) {
        dataSource.setTestOnBorrow(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_TESTONRETURN);
    if (value != null) {
        dataSource.setTestOnReturn(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_TIMEBETWEENEVICTIONRUNSMILLIS);
    if (value != null) {
        dataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(value));
    }

    value = properties.getProperty(PROP_NUMTESTSPEREVICTIONRUN);
    if (value != null) {
        dataSource.setNumTestsPerEvictionRun(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MINEVICTABLEIDLETIMEMILLIS);
    if (value != null) {
        dataSource.setMinEvictableIdleTimeMillis(Long.parseLong(value));
    }

    value = properties.getProperty(PROP_TESTWHILEIDLE);
    if (value != null) {
        dataSource.setTestWhileIdle(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_PASSWORD);
    if (value != null) {
        dataSource.setPassword(value);
    }

    value = properties.getProperty(PROP_URL);
    if (value != null) {
        dataSource.setUrl(value);
    }

    value = properties.getProperty(PROP_USERNAME);
    if (value != null) {
        dataSource.setUsername(value);
    }

    value = properties.getProperty(PROP_VALIDATIONQUERY);
    if (value != null) {
        dataSource.setValidationQuery(value);
    }

    value = properties.getProperty(PROP_VALIDATIONQUERY_TIMEOUT);
    if (value != null) {
        dataSource.setValidationQueryTimeout(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED);
    if (value != null) {
        dataSource.setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_REMOVEABANDONED);
    if (value != null) {
        dataSource.setRemoveAbandoned(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_REMOVEABANDONEDTIMEOUT);
    if (value != null) {
        dataSource.setRemoveAbandonedTimeout(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_LOGABANDONED);
    if (value != null) {
        dataSource.setLogAbandoned(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_POOLPREPAREDSTATEMENTS);
    if (value != null) {
        dataSource.setPoolPreparedStatements(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_MAXOPENPREPAREDSTATEMENTS);
    if (value != null) {
        dataSource.setMaxOpenPreparedStatements(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_INITCONNECTIONSQLS);
    if (value != null) {
        StringTokenizer tokenizer = new StringTokenizer(value, ";");
        dataSource.setConnectionInitSqls(Collections.list(tokenizer));
    }

    value = properties.getProperty(PROP_CONNECTIONPROPERTIES);
    if (value != null) {
        Properties p = getProperties(value);
        Enumeration<?> e = p.propertyNames();
        while (e.hasMoreElements()) {
            String propertyName = (String) e.nextElement();
            dataSource.addConnectionProperty(propertyName, p.getProperty(propertyName));
        }
    }

    // Managed: initialize XADataSource

    value = properties.getProperty(PROP_XADATASOURCE);
    if (value != null) {
        Class<?> xaDataSourceClass;
        try {
            xaDataSourceClass = Class.forName(value);
        } catch (Throwable t) {
            throw (SQLException) new SQLException("Cannot load XA data source class '" + value + "'")
                    .initCause(t);
        }
        XADataSource xaDataSource;
        try {
            xaDataSource = (XADataSource) xaDataSourceClass.newInstance();
        } catch (Throwable t) {
            throw (SQLException) new SQLException("Cannot create XA data source of class '" + value + "'")
                    .initCause(t);
        }
        dataSource.setXaDataSourceInstance(xaDataSource);
    }

    // DBCP-215
    // Trick to make sure that initialSize connections are created
    if (dataSource.getInitialSize() > 0) {
        dataSource.getLogWriter();
    }

    // Return the configured DataSource instance
    return dataSource;
}

From source file:org.moe.designer.fileTemplates.IXMLFileTemplateUtil.java

public static String[] calculateAttributes(String templateContent, Properties properties,
        boolean includeDummies, Project project) throws ParseException {
    Set<String> propertiesNames = new HashSet<String>();
    for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
        propertiesNames.add((String) e.nextElement());
    }//from   w w w  .  jav  a  2  s.c om
    return calculateAttributes(templateContent, propertiesNames, includeDummies, project);
}

From source file:org.moe.designer.fileTemplates.IXMLFileTemplateUtil.java

public static String mergeTemplate(Properties attributes, String content, boolean useSystemLineSeparators)
        throws IOException {
    VelocityContext context = createVelocityContext();
    Enumeration<?> names = attributes.propertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        context.put(name, attributes.getProperty(name));
    }//from w w w.  j  a v a2s  .co m
    return mergeTemplate(content, context, useSystemLineSeparators);
}

From source file:org.apache.cxf.transport.jms.JMSOldConfigHolder.java

public static Properties getInitialContextEnv(AddressType addrType) {
    Properties env = new Properties();
    java.util.ListIterator listIter = addrType.getJMSNamingProperty().listIterator();
    while (listIter.hasNext()) {
        JMSNamingPropertyType propertyPair = (JMSNamingPropertyType) listIter.next();
        if (null != propertyPair.getValue()) {
            env.setProperty(propertyPair.getName(), propertyPair.getValue());
        }//w w  w .  j  a v a  2s .c o m
    }
    if (LOG.isLoggable(Level.FINE)) {
        Enumeration props = env.propertyNames();
        while (props.hasMoreElements()) {
            String name = (String) props.nextElement();
            String value = env.getProperty(name);
            LOG.log(Level.FINE, "Context property: " + name + " | " + value);
        }
    }
    return env;
}

From source file:it.geosolutions.unredd.StatsTests.java

private static Map<String, File> loadTestParams() {

    Properties defaultProperties = new Properties();
    defaultProperties.put(DATA, DEFAULT_DATA);
    defaultProperties.put(CLASSIFICATOR_PREFIX + "1", DEFAULT_CLASSIFICATOR);
    File propFile = loadFileFromResources(PROP_FILE);
    InputStream inStream = null;//from   w w w  .  j a  v  a  2  s .  c  o  m
    Properties prop = null;
    try {
        inStream = new FileInputStream(propFile);
        prop = new Properties(defaultProperties);
        prop.load(inStream);
    } catch (Exception e) {
        fail("Fail when loading layer path file...");
    }
    // Transform the file names into File objects
    Map<String, File> map = new HashMap<String, File>();
    Enumeration kEnumeration = prop.propertyNames();
    while (kEnumeration.hasMoreElements()) {
        String key = (String) kEnumeration.nextElement();
        if (prop.getProperty(key).startsWith("test-data")) {
            map.put(key, loadFileFromResources(prop.getProperty(key)));
        } else {
            map.put(key, new File(prop.getProperty(key)));
        }
    }
    return map;
}

From source file:com.egt.core.util.VelocityEngineer.java

private static Properties getProperties(String propsFilename) throws Exception {
    Bitacora.trace(VelocityEngineer.class, "getProperties", propsFilename);
    Properties p = new Properties();
    try (FileInputStream inStream = new FileInputStream(propsFilename)) {
        p.load(inStream);/*from w  w  w . jav a 2  s. c o m*/
    }
    String comma = System.getProperties().getProperty("path.separator");
    String slash = System.getProperties().getProperty("file.separator");
    String VFRLP = "$" + EAC.VELOCITY_FILE_RESOURCE_LOADER_PATH;
    String vfrlp = EA.getString(EAC.VELOCITY_FILE_RESOURCE_LOADER_PATH);
    vfrlp = vfrlp.replace(comma, ", ");
    vfrlp = vfrlp.replace(slash, "/");
    String key;
    String value;
    for (Enumeration e = p.propertyNames(); e.hasMoreElements();) {
        key = (String) e.nextElement();
        value = p.getProperty(key);
        if (StringUtils.isNotBlank(value) && value.contains(VFRLP)) {
            value = value.replace(VFRLP, vfrlp);
            p.setProperty(key, value);
        }
        Bitacora.trace(key + "=" + value);
    }
    return p;
}

From source file:sorcer.core.SorcerEnv.java

/**
 * Overwrites defined properties in sorcer.env (sorcer.home,
 * provider.webster.interface, provider.webster.port) with those defined as
 * JVM system properties.//from www. j a  v  a  2s . c  o  m
 * 
 * @param properties
 * @throws ConfigurationException
 */
private static void update(Properties properties) throws ConfigurationException {
    Enumeration<?> e = properties.propertyNames();
    String key, value, evalue = null;
    String pattern = "${" + "localhost" + "}";
    //      String userDirPattern = "${user.home}";
    // first substitute for this localhost
    while (e.hasMoreElements()) {
        key = (String) e.nextElement();
        value = properties.getProperty(key);
        if (value.equals(pattern)) {
            try {
                value = getHostAddress();
            } catch (UnknownHostException ex) {
                ex.printStackTrace();
            }
            properties.put(key, value);
        }
        /*      if (value.equals(userDirPattern)) {
                 value = System.getProperty("user.home");            
                 properties.put(key, value);
              }*/
    }
    // now substitute other entries accordingly 
    e = properties.propertyNames();
    while (e.hasMoreElements()) {
        key = (String) e.nextElement();
        value = properties.getProperty(key);
        evalue = expandStringProperties(value, true);
        // try SORCER env properties
        if (evalue == null)
            evalue = expandStringProperties(value, false);
        if (evalue != null)
            properties.put(key, evalue);
        if (value.equals(pattern)) {
            try {
                evalue = getHostAddress();
            } catch (UnknownHostException e1) {
                e1.printStackTrace();
            }
            properties.put(key, evalue);
        }
    }
}

From source file:org.wso2.carbon.identity.event.internal.EventUtils.java

/**
 * @param prefix                 Prefix of the property key
 * @param propertiesWithFullKeys Set of properties which needs to be converted to single word key properties
 * @return Set of properties which has keys containing single word.
 */// w  ww.j a  va  2  s  . co m
public static Properties buildSingleWordKeyProperties(String prefix, Properties propertiesWithFullKeys) {

    // Stop proceeding if required arguments are not present
    if (StringUtils.isEmpty(prefix) || propertiesWithFullKeys == null) {
        throw new IllegalArgumentException(
                "Prefix and properties should not be null to get  properties with " + "single word keys.");
    }

    propertiesWithFullKeys = EventUtils.getPropertiesWithPrefix(prefix, propertiesWithFullKeys);
    Properties properties = new Properties();
    Enumeration propertyNames = propertiesWithFullKeys.propertyNames();

    while (propertyNames.hasMoreElements()) {
        String key = (String) propertyNames.nextElement();
        String newKey = key.substring(key.lastIndexOf(".") + 1, key.length());
        if (!newKey.trim().isEmpty()) {
            // Remove from original properties to hold property schema. ie need to get the set of properties which
            // remains after consuming all required specific properties
            properties.put(newKey, propertiesWithFullKeys.remove(key));
        }
    }
    return properties;
}

From source file:ORG.oclc.os.SRW.SRWServletInfo.java

private static void buildDbList(Properties properties, Vector<DbEntry> dbVector,
        Hashtable<String, String> dbnames, String path, String remote) {
    Enumeration enumer = properties.propertyNames();
    String fileName, dbHome, dbName, description, hidden = null, t;
    while (enumer.hasMoreElements()) {
        t = (String) enumer.nextElement();
        if (t.startsWith("db.") && t.endsWith(".class")) {
            dbName = t.substring(3, t.length() - 6);
            if (remote == null)
                hidden = properties.getProperty("db." + dbName + ".hidden");
            description = properties.getProperty("db." + dbName + ".description");
            if (description == null && remote == null) { // see if it is in the database props
                dbHome = properties.getProperty("db." + dbName + ".home");
                fileName = properties.getProperty("propsfilePath")
                        + properties.getProperty("db." + dbName + ".configuration");
                if (fileName != null)
                    try {
                        InputStream is = Utilities.openInputStream(fileName, dbHome, srwHome);
                        Properties dbProperties = new Properties();
                        dbProperties.load(is);
                        is.close();/* w  w  w.  j a va  2s.c  o  m*/
                        description = dbProperties.getProperty("databaseInfo.description");
                    } catch (FileNotFoundException e) {
                        if (remote == null)
                            log.error(e);
                    } catch (Exception e) {
                        if (remote == null)
                            log.error(e, e);
                    }
            }
            if (remote != null || hidden == null || !hidden.equalsIgnoreCase("true")) {
                dbVector.add(new DbEntry(dbName, remote, path, description));
                dbnames.put(dbName, dbName);
            }
        } else if (remote == null && t.startsWith("remote.") && t.endsWith(".configuration")) {
            remote = t.substring(7, t.length() - 14);
            try {
                fileName = properties.getProperty(t);
                String remotePath = properties.getProperty("remote." + remote + ".path");
                InputStream is = new URL(properties.getProperty(t)).openStream();
                Properties srwProperties = new Properties();
                srwProperties.load(is);
                is.close();
                buildDbList(srwProperties, dbVector, dbnames, remotePath, remote);
            } catch (IOException e) {
                log.error(e);
            }
            remote = null;
        }
    }
}

From source file:org.wso2.carbon.identity.event.IdentityEventUtils.java

/**
 * @param prefix                 Prefix of the property key
 * @param propertiesWithFullKeys Set of properties which needs to be converted to single word key properties
 * @return Set of properties which has keys containing single word.
 *//*from  ww  w.ja  v a  2  s. c  o m*/
public static Properties buildSingleWordKeyProperties(String prefix, Properties propertiesWithFullKeys) {

    // Stop proceeding if required arguments are not present
    if (StringUtils.isEmpty(prefix) || propertiesWithFullKeys == null) {
        throw new IllegalArgumentException(
                "Prefix and properties should not be null to get  properties with " + "single word keys.");
    }

    propertiesWithFullKeys = IdentityEventUtils.getPropertiesWithPrefix(prefix, propertiesWithFullKeys);
    Properties properties = new Properties();
    Enumeration propertyNames = propertiesWithFullKeys.propertyNames();

    while (propertyNames.hasMoreElements()) {
        String key = (String) propertyNames.nextElement();
        String newKey = key.substring(key.lastIndexOf(".") + 1, key.length());
        if (!newKey.trim().isEmpty()) {
            // Remove from original properties to hold property schema. ie need to get the set of properties which
            // remains after consuming all required specific properties
            properties.put(newKey, propertiesWithFullKeys.remove(key));
        }
    }
    return properties;
}