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:com.izforge.izpack.installer.console.ConsoleInstaller.java

/**
 * Creates a new action to perform installation from a properties file.
 *
 * @param path    the property file path
 * @param console the console//  w  ww.ja va2s.  c o  m
 * @return a new {@link PropertyInstallAction}
 * @throws IOException for any I/O error
 */
private ConsoleAction createInstallFromSystemPropertiesMergeAction(String path, Console console)
        throws IOException {
    FileInputStream in = new FileInputStream(path);
    try {
        Properties properties = new Properties();
        properties.load(in);
        Properties systemProperties = System.getProperties();
        Enumeration<?> e = systemProperties.propertyNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String newValue = systemProperties.getProperty(key);
            String oldValue = (String) properties.setProperty(key, newValue);
            if (oldValue != null) {
                console.println(
                        "Warning: Property " + key + " overwritten: '" + oldValue + "' --> '" + newValue + "'");
            }
        }
        return new PropertyInstallAction(installData, uninstallDataWriter, properties);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:PropertiesHelper.java

/**
 * Extracts a specific property key subset from the properties passed.
 * The prefix may be removed from the keys in the resulting dictionary,
 * or it may be kept. In the latter case, exact matches on the prefix
 * will also be copied into the resulting dictionary.
 *
 *
 * @param prefix is the key prefix to filter the properties by.
 * @param keepPrefix if true, the key prefix is kept in the resulting
 * dictionary. As side-effect, a key that matches the prefix exactly
 * will also be copied. If false, the resulting dictionary's keys are
 * shortened by the prefix. An exact prefix match will not be copied,
 * as it would result in an empty string key.
 * @return a property dictionary matching the filter key. May be
 * an empty dictionary, if no prefix matches were found.
 *
 * @see #getProperty( String ) is used to assemble matches
 *//*from   w  w  w.j av a  2 s . c o  m*/
public static Properties matchingSubset(Properties properties, String prefix, boolean keepPrefix) {
    Properties result = new Properties();

    // sanity check
    if (prefix == null || prefix.length() == 0) {
        return result;
    }

    String prefixMatch; // match prefix strings with this
    String prefixSelf; // match self with this
    if (prefix.charAt(prefix.length() - 1) != '.') {
        // prefix does not end in a dot
        prefixSelf = prefix;
        prefixMatch = prefix + '.';
    } else {
        // prefix does end in one dot, remove for exact matches
        prefixSelf = prefix.substring(0, prefix.length() - 1);
        prefixMatch = prefix;
    }
    // POSTCONDITION: prefixMatch and prefixSelf are initialized!

    // now add all matches into the resulting properties.
    // Remark 1: #propertyNames() will contain the System properties!
    // Remark 2: We need to give priority to System properties. This is done
    // automatically by calling this class's getProperty method.
    String key;
    for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
        key = (String) e.nextElement();

        if (keepPrefix) {
            // keep full prefix in result, also copy direct matches
            if (key.startsWith(prefixMatch) || key.equals(prefixSelf)) {
                result.setProperty(key, properties.getProperty(key));
            }
        } else {
            // remove full prefix in result, dont copy direct matches
            if (key.startsWith(prefixMatch)) {
                result.setProperty(key.substring(prefixMatch.length()), properties.getProperty(key));
            }
        }
    }

    // done
    return result;
}

From source file:org.apereo.portal.security.mvc.LogoutController.java

@Override
public void afterPropertiesSet() throws Exception {
    final Map<String, String> rdHash = new HashMap<String, String>(1);

    try {//from  ww w .  ja va2s  .  c  o  m
        // We retrieve the redirect strings for each context
        // from the security properties file.
        String key;
        final Properties props = ResourceLoader.getResourceAsProperties(LogoutController.class,
                "/properties/security.properties");
        final Enumeration propNames = props.propertyNames();
        while (propNames.hasMoreElements()) {
            final String propName = (String) propNames.nextElement();
            final String propValue = props.getProperty(propName);
            if (propName.startsWith("logoutRedirect.")) {
                key = propName.substring(15);
                key = key.startsWith("root.") ? key.substring(5) : key;
                if (log.isDebugEnabled()) {
                    log.debug("Redirect key=" + key + ", value=" + propValue);
                }

                rdHash.put(key, propValue);
            }
        }
    } catch (final PortalException pe) {
        log.error("Failed to load logout redirect URLs", pe);
    } catch (final IOException ioe) {
        log.error("Failed to load logout redirect URLs", ioe);
    }

    this.redirectMap = rdHash;
}

From source file:org.finra.dm.dao.ReloadablePropertySourceTest.java

/**
 * Creates a clone of the specified properties object.
 *
 * @param properties the source properties.
 *
 * @return the cloned properties.//from  w ww.ja v  a 2 s .  c  o m
 */
private Properties cloneProperties(Properties properties) {
    Properties clonedProperties = new Properties();
    for (Enumeration propertyNames = properties.propertyNames(); propertyNames.hasMoreElements();) {
        Object key = propertyNames.nextElement();
        clonedProperties.put(key, properties.get(key));
    }
    return clonedProperties;
}

From source file:org.soaplab.services.cmdline.CmdLineJob.java

/**************************************************************************
 * Create all environment variables from individual parameters
 * (from those who claim ENVAR in their metadata) and from the
 * user inputs (they are in 'inputs'). <p>
 *
 * Return an empty properties (not null) if there are no
 * environment variables to create. <p>
 **************************************************************************/
protected Properties createEnvs() throws SoaplabException {

    Parameter[] parameters = (Parameter[]) sharedAttributes.get(JOB_SHARED_PARAMETERS);
    if (parameters == null)
        return EMPTY_PROPS;

    Properties envProps = new Properties();
    StringBuilder errBuf = new StringBuilder();

    for (Parameter parameter : parameters) {
        try {/* w w  w.ja  v  a2 s . c  o m*/
            Properties props = parameter.createEnv(inputs, this);
            for (Enumeration en = props.propertyNames(); en.hasMoreElements();) {
                String key = (String) en.nextElement();
                envProps.put(key, props.get(key));
            }
        } catch (ParameterException e) {
            errBuf.append(e.getMessage());
            errBuf.append("\n");
        } catch (Exception e) {
            throw new SoaplabException(getServiceName() + ": " + "Unexpected exception. " + e.getMessage(), e);
        }
    }
    if (errBuf.length() > 0)
        throw new SoaplabException(SoaplabConstants.FAULT_NOT_VALID_INPUTS + "\n" + errBuf.toString());
    return envProps;
}

From source file:org.deegree.feature.persistence.cache.BBoxPropertiesCache.java

/**
 * Creates a new {@link BBoxPropertiesCache} instance.
 * //from  w  w  w  .  ja  v a  2s  .  co m
 * @param propsFile
 *            properties file, must not be <code>null</code>
 * @throws IOException
 */
public BBoxPropertiesCache(File propsFile) throws IOException {
    this.propsFile = propsFile;
    if (!propsFile.exists()) {
        LOG.info("File '" + propsFile.getCanonicalPath() + "' does not exist. Will be created as needed.");
        return;
    }
    if (!propsFile.isFile()) {
        LOG.error("File '" + propsFile.getCanonicalPath() + "' does not denote a standard file.");
        return;
    }

    Properties props = new Properties();
    InputStream is = new FileInputStream(propsFile);
    try {
        props.load(is);
    } finally {
        IOUtils.closeQuietly(is);
    }

    Enumeration<?> e = props.propertyNames();
    while (e.hasMoreElements()) {
        String propName = (String) e.nextElement();
        String propValue = props.getProperty(propName);
        Envelope env = decodePropValue(propValue);
        LOG.debug("Envelope for feature type '{}': {}", propName, env);
        ftNameToEnvelope.put(propName, env);
    }
}

From source file:org.wso2.carbon.identity.notification.mgt.NotificationMgtConfigBuilder.java

/**
 * Build and store per module configuration objects
 *//*from  w  ww .ja  va2 s.c om*/
private void build() {
    Properties moduleNames = NotificationManagementUtils
            .getSubProperties(NotificationMgtConstants.Configs.MODULE_NAME, notificationMgtConfigProperties);
    Enumeration propertyNames = moduleNames.propertyNames();
    // Iterate through events and build event objects
    while (propertyNames.hasMoreElements()) {
        String key = (String) propertyNames.nextElement();
        String moduleName = (String) moduleNames.remove(key);
        moduleConfiguration.put(moduleName, buildModuleConfigurations(moduleName));
    }
}

From source file:sorcer.launcher.Launcher.java

/**
 * Create a new set of system properties using the result of getDefaultProperties() as he defaults
 * and the system properties as overrides
 * @return Properties to be used as a system properties of the new sorcer
 *//*from   w ww  .  j av a 2  s  . c  o  m*/
protected Properties getProperties() {
    Properties overrides = new Properties(getDefaultProperties());
    overrides.putAll(System.getProperties());
    if (log.isDebugEnabled())
        for (Object key : i(overrides.propertyNames()))
            log.debug("{} = {}", key, overrides.getProperty((String) key));
    return overrides;
}

From source file:se.cambio.cds.gdl.parser.DADLSerializer.java

private void loadProfile(String name) {
    profile = new HashMap<String, List<String>>();
    try {/*w w  w  .  j  a va  2 s .co m*/
        InputStream input = this.getClass().getClassLoader().getResourceAsStream(name);
        Properties props = new Properties();
        props.load(input);
        Enumeration keys = props.propertyNames();
        StringTokenizer tokens = null;
        List<String> attributes;
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            String line = props.getProperty((String) key);
            log.debug(line);

            tokens = new StringTokenizer(line, ",");
            attributes = new ArrayList<String>();
            while (tokens.hasMoreTokens()) {
                attributes.add(tokens.nextToken());
            }
            profile.put((String) key, attributes);

            log.debug(key.toString() + " with attributes: " + attributes);
        }
        log.debug(profile.size() + " class(es) loaded..");

    } catch (Exception e) {
        log.error("failed to load " + name);
    }
}

From source file:net.ageto.gyrex.persistence.jdbc.pool.internal.commands.ListPools.java

private void printPool(final PoolDefinition pool) throws BackingStoreException {
    printf("Pool %s", pool.getPoolId());
    printf(StringUtils.EMPTY);//from  ww  w . j a v a2  s  .c  om

    final Properties driverProperties = pool.getDriverProperties();
    if (!driverProperties.isEmpty()) {
        printf("Driver Properties:");
        final SortedSet<String> names = new TreeSet<String>();
        final Enumeration<?> propertyNames = driverProperties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            names.add((String) propertyNames.nextElement());
        }
        for (final String key : names) {
            printf("  %35s: %s", key, StringUtils.trimToEmpty(driverProperties.getProperty(key)));
        }
        printf(StringUtils.EMPTY);
    }

    printf("Pool Statistics:");
    final BoneCPDataSource dataSource = (BoneCPDataSource) PoolActivator.getInstance().getRegistry()
            .getDataSource(pool.getPoolId());

    // test connectivity (this also works around a bug in BoneCP which would result in an NPE below)
    try {
        final Connection connection = dataSource.getConnection();
        if (connection instanceof ConnectionHandle) {
            printf("  %35s: %s", "connectionTest",
                    ((ConnectionHandle) connection).isValid(1000) ? "OK" : "NOT OK");
        } else {
            printf("  %35s: %s", "connectionSample", connection.toString());
        }
        connection.close();
    } catch (final SQLException e) {
        printf("  unable to connect to pool: %s", e.getMessage());
    }

    // total number of leased connections
    printf("  %35s: %d", "totalLeased", dataSource.getTotalLeased());
    printf(StringUtils.EMPTY);

    printf("Effective Pool Config:");
    final TreeMap<String, String> poolConfig = readPoolConfig(dataSource);
    for (final Entry<String, String> entry : poolConfig.entrySet()) {
        printf("  %35s: %s", entry.getKey(), entry.getValue());
    }
}