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.rhq.plugins.www.snmp.SNMPClient.java

private void initOids() {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    ClassLoader classLoader = (contextClassLoader != null) ? contextClassLoader
            : this.getClass().getClassLoader();
    InputStream stream = classLoader.getResourceAsStream(OIDS_PROPERTIES_RESOURCE_PATH);
    if (stream == null) {
        throw new IllegalStateException(
                "Resource '" + OIDS_PROPERTIES_RESOURCE_PATH + "' not found by " + classLoader);
    }/*from   w ww . j  av a  2 s  .c om*/
    Properties props = new Properties();
    try {
        try {
            props.load(stream);
        } finally {
            stream.close();
        }
    } catch (Exception e) {
        throw new IllegalStateException("Failed to parse oids.properties file from plugin classloader.", e);
    }

    Enumeration<?> propNames = props.propertyNames();
    while (propNames.hasMoreElements()) {
        String propName = (String) propNames.nextElement();
        OIDS.setProperty(propName, props.getProperty(propName).trim());
    }
}

From source file:org.cagrid.installer.Installer.java

public void initialize() {

    try {/*ww w.j  a  v a  2s  . c  o  m*/
        // Show the splash screen
        splashScreenInit();

        incrementProgress();

        Map<String, String> defaultState = new HashMap<String, String>();

        incrementProgress();

        // Load default properties
        Properties downloadedProps = DownloadPropertiesUtils.getDownloadedProps();
        incrementProgress();

        Enumeration e = downloadedProps.propertyNames();
        while (e.hasMoreElements()) {
            String propName = (String) e.nextElement();
            defaultState.put(propName, downloadedProps.getProperty(propName));
        }
        incrementProgress();

        // get proxy properties
        Properties proxyProps = InstallerUtils.getProxyProperties();
        Map<String, String> map = new HashMap<String, String>((Map) proxyProps);
        defaultState.putAll(map);

        // Set up temp dir
        String installerDir = InstallerUtils.buildInstallerDirPath(defaultState.get(Constants.CAGRID_VERSION));
        logger.info("installer dir: " + installerDir);
        String tempDir = installerDir + "/tmp";
        defaultState.put(Constants.TEMP_DIR_PATH, tempDir);
        File tempDirFile = new File(tempDir);
        if (tempDirFile.exists()) {
            tempDirFile.delete();
        }
        logger.info("Creating temporary directory '" + tempDir + "'");
        try {
            tempDirFile.mkdirs();
        } catch (Exception ex) {
            String msg = "Error creating temporary directory '" + tempDir + "': " + ex.getMessage();
            logger.error(msg, ex);
            throw new RuntimeException(msg, ex);
        }
        incrementProgress();

        // Check for presence of cagrid.installer.properties file
        String cagridInstallerFileName = System.getProperty(Constants.CAGRID_INSTALLER_PROPERTIES);
        if (cagridInstallerFileName != null) {
            logger.info("Custom installer properties file specified: '" + cagridInstallerFileName + "'");
        } else {
            cagridInstallerFileName = installerDir + "/" + Constants.CAGRID_INSTALLER_PROPERTIES;
            logger.info("Using default properties file: '" + cagridInstallerFileName + "'");
        }
        defaultState.put(Constants.CAGRID_INSTALLER_PROPERTIES, cagridInstallerFileName);
        File cagridInstallerFile = new File(cagridInstallerFileName);
        incrementProgress();

        // If cagrid.installer.properties found, load properties.
        logger.info("Looking for '" + cagridInstallerFileName + "'");
        if (cagridInstallerFile.exists()) {
            try {
                logger.info("Loading '" + cagridInstallerFileName + "'");
                Properties props = new Properties();
                props.load(new FileInputStream(cagridInstallerFile));

                // Downloaded properties have precedence
                Enumeration e2 = props.propertyNames();
                while (e2.hasMoreElements()) {
                    String propName = (String) e2.nextElement();
                    if (!defaultState.containsKey(propName)) {
                        defaultState.put(propName, props.getProperty(propName));
                    }
                }
            } catch (Exception ex) {
                String msg = "Could not load '" + cagridInstallerFileName + "': " + ex.getMessage();
                logger.error(msg, ex);
                throw new RuntimeException(msg, ex);
            }
        } else {
            logger.info("Did not find '" + cagridInstallerFileName + "'");
        }

        incrementProgress();

        InstallerUtils.assertCorrectJavaVersion(defaultState);

        initSteps(defaultState);

        while (this.initProgress < TOTAL_INIT_STEPS) {
            incrementProgress();
            try {
                Thread.sleep(10);
            } catch (Exception ex) {

            }
        }

    } catch (Exception ex) {
        InstallerUtils.handleException("Error initializing: " + ex.getMessage(), ex);
    } finally {
        splashScreenDestruct();
    }
}

From source file:org.apereo.portal.spring.security.preauth.PortalPreAuthenticatedProcessingFilter.java

private void retrieveCredentialAndPrincipalTokensFromPropertiesFile() {
    try {//from  w  w w .  ja  v  a2s  . co m
        String key;
        // We retrieve the tokens representing the credential and principal
        // parameters from the security properties file.
        Properties props = ResourceLoader.getResourceAsProperties(getClass(),
                "/properties/security.properties");
        Enumeration<?> propNames = props.propertyNames();
        while (propNames.hasMoreElements()) {
            String propName = (String) propNames.nextElement();
            String propValue = props.getProperty(propName);
            if (propName.startsWith("credentialToken.")) {
                key = propName.substring(16);
                this.credentialTokens.put(key, propValue);
            }
            if (propName.startsWith("principalToken.")) {
                key = propName.substring(15);
                this.principalTokens.put(key, propValue);
            }
        }
    } catch (PortalException pe) {
        logger.error("LoginServlet::static ", pe);
    } catch (IOException ioe) {
        logger.error("LoginServlet::static ", ioe);
    }
}

From source file:org.sonatype.nexus.rt.prefs.FilePreferences.java

@Override
protected void syncSpi() throws BackingStoreException {
    if (isRemoved()) {
        return;//from  www .  j  a  va  2 s. com
    }

    final File file = FilePreferencesFactory.getPreferencesFile();

    if (!file.exists()) {
        return;
    }

    synchronized (file) {
        Properties p = new Properties();
        try {
            final FileInputStream in = new FileInputStream(file);
            try {
                p.load(in);
            } finally {
                IOUtils.closeQuietly(in);
            }

            StringBuilder sb = new StringBuilder();
            getPath(sb);
            String path = sb.toString();

            final Enumeration<?> pnen = p.propertyNames();
            while (pnen.hasMoreElements()) {
                String propKey = (String) pnen.nextElement();
                if (propKey.startsWith(path)) {
                    String subKey = propKey.substring(path.length());
                    // Only load immediate descendants
                    if (subKey.indexOf('.') == -1) {
                        root.put(subKey, p.getProperty(propKey));
                    }
                }
            }
        } catch (IOException e) {
            throw new BackingStoreException(e);
        }
    }
}

From source file:org.dspace.handle.MultiRemoteDSpaceRepositoryHandlePlugin.java

/**
 * HandleStorage interface method - not implemented.
 *///from   w  w w .jav a2 s  . c om
public void init(StreamTable st) throws Exception {
    // Not implemented
    if (log.isInfoEnabled()) {
        log.info("Called init");
    }

    // initalize our prefix map
    this.prefixes = new HashMap<String, String>();

    // try to find our configuration
    Properties properties = loadProperties(CONFIG_FILE_NAME);

    // find urls of all configured dspace instances
    for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
        String propertyName = (String) e.nextElement();
        if (propertyName.startsWith(this.PROPERTY_KEY)) {
            // load the prefixes of this instance
            loadPrefixes(properties.getProperty(propertyName));
        }
    }

    // did we found any prefixes?
    if (this.prefixes.isEmpty()) {
        throw new HandleException(HandleException.INTERNAL_ERROR,
                "Unable to find configuration or to reach any DSpace instance.");
    }

    if (log.isInfoEnabled()) {
        for (Iterator<String> it = this.prefixes.keySet().iterator(); it.hasNext();) {
            String prefix = it.next();
            log.info("Loaded Prefix " + prefix + " from " + this.prefixes.get(prefix));
        }
    }
}

From source file:org.plukh.fluffymeow.config.S3Properties.java

public synchronized void load(String deploymentId, String applicationName, InputStream in) throws IOException {
    if (in != null) {
        try {//from   w  ww. j av a  2s.  c o m
            log.debug("Trying to load properties from provided input stream");
            super.load(in);
            if (log.isDebugEnabled())
                log.debug("Loaded " + size() + " total properties");
            return;
        } catch (IOException e) {
            log.debug("Failed to load properties from provided input stream", e);
        }
    }

    log.debug("Proceeding with S3 download");

    log.trace("Downloading default properties");
    Properties defaultProperties = downloadFromS3(bucket, DEFAULT_PROPERTIES, null);

    log.trace("Downloading deployment-default properties");
    Properties deplDefaultProperties = downloadFromS3(bucket, deploymentId + "/" + DEFAULT_PROPERTIES,
            defaultProperties);

    log.trace("Downloading application-specific properties");
    Properties appProperties = downloadFromS3(bucket,
            deploymentId + "/" + applicationName + "/" + applicationName + ".properties",
            deplDefaultProperties);

    log.trace("Downloading version-specific properties");

    Properties versionProperties = downloadFromS3(bucket, deploymentId + "/" + applicationName + "/"
            + applicationName + "-" + versionInfoProvider.getVersion() + ".properties", appProperties);

    //Validate properties (at least one specific property file should be found!)
    if (appProperties.isEmpty() && versionProperties.isEmpty())
        throw new ConfigException("No specific configuration files found!");

    clear();
    Enumeration<?> names = versionProperties.propertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        this.setProperty(name, versionProperties.getProperty(name));
    }

    if (log.isDebugEnabled())
        log.debug("Loaded " + size() + " total properties");
}

From source file:com.liferay.portal.dao.jdbc.DataSourceFactoryImpl.java

protected DataSource initDataSourceC3PO(Properties properties) throws Exception {

    ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();

    String identityToken = PwdGenerator.getPassword(PwdGenerator.KEY2, 8);

    comboPooledDataSource.setIdentityToken(identityToken);

    Enumeration<String> enu = (Enumeration<String>) properties.propertyNames();

    while (enu.hasMoreElements()) {
        String key = enu.nextElement();
        String value = properties.getProperty(key);

        // Map org.apache.commons.dbcp.BasicDataSource to C3PO

        if (key.equalsIgnoreCase("driverClassName")) {
            key = "driverClass";
        } else if (key.equalsIgnoreCase("url")) {
            key = "jdbcUrl";
        } else if (key.equalsIgnoreCase("username")) {
            key = "user";
        }//from w w  w  . j  av a2  s. c o m

        // Ignore Liferay properties

        if (isPropertyLiferay(key)) {
            continue;
        }

        // Ignore DBCP properties

        if (isPropertyDBCP(key)) {
            continue;
        }

        // Ignore Primrose properties

        if (isPropertyPrimrose(key)) {
            continue;
        }

        // Ignore Tomcat

        if (isPropertyTomcat(key)) {
            continue;
        }

        try {
            BeanUtil.setProperty(comboPooledDataSource, key, value);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Property " + key + " is not a valid C3PO property");
            }
        }
    }

    return comboPooledDataSource;
}

From source file:org.jfrog.build.extractor.release.PropertiesTransformer.java

/**
 * {@inheritDoc}//w w  w  .  j av a2  s  . c  o m
 *
 * @return True in case the properties file was modified during the transformation. False otherwise.
 */
public Boolean transform() throws IOException, InterruptedException {
    if (!propertiesFile.exists()) {
        throw new IllegalArgumentException(
                "Couldn't find properties file: " + propertiesFile.getAbsolutePath());
    }
    Properties properties = new Properties();
    EolDetectingInputStream eolDetectingInputStream = null;
    try {
        eolDetectingInputStream = new EolDetectingInputStream(new FileInputStream(propertiesFile));
        properties.load(eolDetectingInputStream);
    } finally {
        IOUtils.closeQuietly(eolDetectingInputStream);
    }
    String eol = eolDetectingInputStream.getEol();
    boolean hasEol = !"".equals(eol);

    StringBuilder resultBuilder = new StringBuilder();
    boolean modified = false;
    Enumeration<?> propertyNames = properties.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String propertyName = (String) propertyNames.nextElement();
        String propertyValue = properties.getProperty(propertyName);

        StringBuilder lineBuilder = new StringBuilder(propertyName).append("=");

        String newPropertyValue = versionsByName.get(propertyName);
        if ((newPropertyValue != null) && !newPropertyValue.equals(propertyValue)) {
            if (!modified) {
                modified = true;
            }
            lineBuilder.append(newPropertyValue);
        } else {
            lineBuilder.append(propertyValue);
        }
        resultBuilder.append(lineBuilder.toString());
        if (hasEol) {
            resultBuilder.append(eol);
        }
    }

    if (modified) {
        propertiesFile.delete();
        String toWrite = resultBuilder.toString();
        Files.write(toWrite, propertiesFile, Charsets.UTF_8);
    }

    return modified;
}

From source file:com.liangc.hq.base.web.ConfiguratorListener.java

/**
 * Load the application properties file (found at
 * <code>/WEB-INF/classes/hq.properties</code>) and configure
 * the web application. All properties in the file are exposed as
 * servlet context attributes.// w w  w.j a  v  a2  s .co  m
 *
 */
public void loadConfig(ServletContext ctx) {
    Properties props = null;
    try {
        props = loadProperties(ctx, Constants.PROPS_FILE_NAME);
    } catch (Exception e) {
        error("unable to load application properties file [" + Constants.PROPS_FILE_NAME + "]", e);
        return;
    }

    if (props == null) {
        debug("application properties file [" + Constants.PROPS_FILE_NAME + "] does not exist");
        return;
    }

    Enumeration names = props.propertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.startsWith(Constants.SYSTEM_VARIABLE_PATH)) {
            System.setProperty(name, props.getProperty(name));
        } else {
            ctx.setAttribute(name, props.getProperty(name));
        }
    }

    debug("loaded application configuration [" + Constants.PROPS_FILE_NAME + "]");
}

From source file:org.apache.hadoop.hive.metastore.MetaStoreClient.java

public void createTable(String tableName, Properties schema)
        throws MetaException, UnknownTableException, TException {

    TException firstException = null;/*www  .  ja  v a  2s.c o  m*/
    String dbName = "default";
    HashMap<String, String> hm = new HashMap<String, String>();
    for (Enumeration<?> e = schema.propertyNames(); e.hasMoreElements();) {
        String key = (String) e.nextElement();
        String val = schema.getProperty(key);
        hm.put(key, val);
    }
    for (URI store : this.metastoreUris) {
        try {
            this.open(store);
            try {
                client.create_table(dbName, tableName, hm);
            } catch (UnknownDBException e) {
                throw new UnknownTableException();
            }
            close();
            return;
        } catch (TException e) {
            System.err.println("get_tables got exception: " + e);
            if (firstException == null) {
                firstException = e;
            }
        }
        // note - do not catchMetaException or UnkownTableException as we want those to propagate up w/o retrying backup stores.
    }
    if (firstException != null) {
        throw firstException;
    }
}