Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

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

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:org.bungeni.ext.integration.bungeniportal.BungeniAppConnector.java

private boolean oauthNewAccessToken() throws FileNotFoundException, IOException {
    Properties props = OAuthProperties.getInstance().getProperties();
    String sRefreshToken = (String) props.get("refresh_token");
    String sRefreshTokenUrl = this.urlBase + this.loginInfo.getCredentials().renewAccessTokenUri(sRefreshToken);
    WebResponse wr = this.getUrl(sRefreshTokenUrl, false);
    if (wr.statusCode == 200
            && "application/json".equals(wr.response.getEntity().getContentType().getValue())) {
        HashMap<String, String> refreshTokens = parseJSonStream(wr.getResponseBody());
        try {/*w w  w  .  j a v a  2s.c om*/
            this.writeOauthProperties(refreshTokens);
            return true;
        } catch (Exception ex) {
            log.error("Error while writing oauth properties !", ex);
            return false;
        }
    }
    return false;
}

From source file:ca.hec.commons.utils.MergePropertiesUtils.java

/**
 * Print the newprops./*from  w w w. j  a va 2  s .co m*/
 * Properties that are 'used' already are commented out.
 * 
 * NOTE: The idea is that we want to write out the properties in exactly the same order, for future comparison purposes.
 * 
 * @param newProps
 * @param remainingNewProps New properties that are left, i.e. remaining ones.
 */

private static void printNewProps(File updatedValuesOldPropertiesFile, Properties newProps,
        Properties originalProps) {
    /**
     * Read new props line by line.
     * For each line, extract the prop key
     *   if it is not in the remaining, then it is used. So we write the line, but commented out
     *   otherwise, write the line as is.
     */

    System.out.println(
            "#########################################################################################");
    System.out.println(
            "####################### Personalizations  from 2.9.1-source-modif #######################");

    try {
        // Open the file that contains Sakai 2.8.1 modif personalizations
        FileInputStream fstream = new FileInputStream(updatedValuesOldPropertiesFile);
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        // Read File Line By Line
        while ((strLine = br.readLine()) != null) {

            KeyValue keyValue = extractKeyValue(strLine);

            //if the line does not have the pattern key = value, we skip it 
            if (keyValue == null) {
                continue;
            }

            String key = keyValue.key;

            boolean isNotUsedInNewVersion = (newProps.get(key) == null);
            boolean isNotUsedInOldVersion = (originalProps.get(key) == null);

            // Write out line only if property is a personalized property:it is not used in new version and was not used in old version
            if (isNotUsedInNewVersion && isNotUsedInOldVersion) {
                System.out.println(strLine);
            }
        }
        // Close the input stream
        in.close();

    } catch (Exception e) {// Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
}

From source file:org.gvnix.service.roo.addon.addon.ws.importt.WSImportOperationsImpl.java

/**
 * Compares the values of two Property instances
 * // w  w w  . j av  a 2s  .  c  o  m
 * @param one
 * @param other
 * @return
 */
private boolean propertiesEquals(Properties one, Properties other) {
    if (one.size() != other.size()) {
        return false;
    }
    Set<Entry<Object, Object>> entrySet = one.entrySet();
    Object otherValue;
    for (Entry<Object, Object> entry : entrySet) {
        otherValue = other.get(entry.getKey());
        if (otherValue == null) {
            if (entry.getValue() != null) {
                return false;
            }
        } else if (!otherValue.equals(entry.getValue())) {
            return false;
        }
    }
    return true;
}

From source file:net.sf.ehcache.hibernate.EhCacheProvider.java

/**
 * Callback to perform any necessary initialization of the underlying cache implementation
 * during SessionFactory construction./*from  w w  w  . j  ava 2 s.  co  m*/
 * <p/>
 *
 * @param properties current configuration settings.
 */
public final void start(Properties properties) throws CacheException {
    if (manager != null) {
        LOG.warn("Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() "
                + " between repeated calls to buildSessionFactory. Using previously created EhCacheProvider."
                + " If this behaviour is required, consider using SingletonEhCacheProvider.");
        return;
    }
    try {
        String configurationResourceName = null;
        if (properties != null) {
            configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
        }
        if (configurationResourceName == null || configurationResourceName.length() == 0) {
            manager = new CacheManager();
        } else {
            URL url = loadResource(configurationResourceName);
            manager = new CacheManager(url);
        }
    } catch (net.sf.ehcache.CacheException e) {
        if (e.getMessage()
                .startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of "
                        + "CacheManager using the diskStorePath")) {
            throw new CacheException(
                    "Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() "
                            + " between repeated calls to buildSessionFactory. Consider using SingletonEhCacheProvider. Error from "
                            + " ehcache was: " + e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:com.cisco.oss.foundation.logging.FoundationLogger.java

private static void setupJULSupport(URL resource) {
    boolean julSupportEnabled = Boolean.valueOf(log4jConfigProps
            .getProperty(FoundationLoggerConstants.Foundation_JUL_SUPPORT_ENABLED.toString(), "false"));
    if (julSupportEnabled) {
        String appenderRef = log4jConfigProps
                .getProperty(FoundationLoggerConstants.Foundation_JUL_APPENDER_REF.toString());

        if (StringUtils.isBlank(appenderRef)) {

            Enumeration allAppenders = Logger.getRootLogger().getAllAppenders();

            while (allAppenders.hasMoreElements()) {

                Appender appender = (Appender) allAppenders.nextElement();

                if (appender instanceof FileAppender) {
                    appenderRef = appender.getName();
                    getLogger(FoundationLogger.class)
                            .info("*** Using '" + appenderRef + "' as the Java util logging appender ref ***");
                    System.err.println(
                            "*** Using '" + appenderRef + "' as the Java util logging appender ref ***");
                    break;
                }/*from   w  ww .ja v a 2  s.  c o m*/
            }
        }

        if (StringUtils.isBlank(appenderRef)) {
            throw new IllegalArgumentException(
                    "Java util support was enabled but couldn't find a matching appender under the '"
                            + FoundationLoggerConstants.Foundation_JUL_APPENDER_REF.toString() + "' key.");
        }

        Handler handler = null;

        Appender appender = Logger.getRootLogger().getAppender(appenderRef);
        if (appender == null) {

            Enumeration allAppenders = Logger.getRootLogger().getAllAppenders();

            while (allAppenders.hasMoreElements()) {

                Appender tempAppender = (Appender) allAppenders.nextElement();

                if (tempAppender instanceof AsyncAppender) {

                    AsyncAppender asyncAppender = (AsyncAppender) tempAppender;
                    Enumeration asyncAppenderAllAppenders = asyncAppender.getAllAppenders();

                    while (asyncAppenderAllAppenders.hasMoreElements()) {

                        Appender asyncTempAppender = (Appender) asyncAppenderAllAppenders.nextElement();

                        if (appenderRef.equals(asyncTempAppender.getName())) {
                            appender = asyncTempAppender;
                            break;
                        }
                    }
                    if (appender != null) {
                        break;
                    }
                }
            }
        }

        if (appender instanceof FileAppender) {
            try {
                handler = new FileHandler(((FileAppender) appender).getFile());
            } catch (IOException e) {
                throw new IllegalArgumentException(
                        "IOException encountered when trying to setup jul logging: " + e, e);
            }
        } else if (appender instanceof ConsoleAppender) {
            handler = new ConsoleHandler();
        } else {
            getLogger(FoundationLogger.class)
                    .error("got a reference to an unsupported appender: " + appenderRef);
        }

        if (handler != null) {

            //                System.setProperty("java.util.logging.config.file",resource.getPath());

            java.util.logging.LogManager.getLogManager().reset();
            try {
                java.util.logging.LogManager.getLogManager().readConfiguration(resource.openStream());
            } catch (IOException e) {
                throw new IllegalArgumentException(
                        "IOException encountered when trying to read log4j properties file: " + e, e);
            }

            handler.setLevel(java.util.logging.Level.FINEST);
            handler.setFormatter(new FoundationLogFormatter());

            java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("");
            rootLogger.addHandler(handler);
            rootLogger.setLevel(java.util.logging.Level.SEVERE);

            Properties julLoggerSubset = getPropertiesSubset("jul.logger");
            if (!julLoggerSubset.isEmpty()) {
                Set<Object> keySet = julLoggerSubset.keySet();
                for (Object key : keySet) {
                    java.util.logging.Logger logger = java.util.logging.Logger.getLogger((String) key);
                    logger.setLevel(java.util.logging.Level.parse((String) julLoggerSubset.get(key)));
                }
            }
        }

    }
}

From source file:edu.utah.further.core.data.service.ConfigurableBasicDataSource.java

/**
 * Set a new value for the properties property.
 * // w  w  w  .  j  a  v a 2 s.c o m
 * @param properties
 *            the properties to set
 */
public void setProperties(final Properties properties) {
    // Set the data sources' properties according the properties object;
    // basically, we are following the Adapter Pattern.
    dataSource.setUrl((String) properties.get(PROPERTIES.URL));
    dataSource.setDriverClassName((String) properties.get(PROPERTIES.DRIVER));
    dataSource.setUsername((String) properties.get(PROPERTIES.USER));
    dataSource.setPassword((String) properties.get(PROPERTIES.PASSWORD));
}

From source file:io.hops.metadata.ndb.ClusterjConnector.java

@Override
public void setConfiguration(Properties conf) throws StorageException {
    if (isInitialized) {
        LOG.warn("SessionFactory is already initialized");
        return;//  w  w  w.  jav a 2  s.c om
    }
    LOG.info("Database connect string: " + conf.get(Constants.PROPERTY_CLUSTER_CONNECTSTRING));
    LOG.info("Database name: " + conf.get(Constants.PROPERTY_CLUSTER_DATABASE));
    LOG.info("Max Transactions: " + conf.get(Constants.PROPERTY_CLUSTER_MAX_TRANSACTIONS));

    int initialPoolSize = Integer.parseInt((String) conf.get("io.hops.session.pool.size"));
    int reuseCount = Integer.parseInt((String) conf.get("io.hops.session.reuse.count"));
    dbSessionProvider = new DBSessionProvider(conf, reuseCount, initialPoolSize);

    isInitialized = true;
}

From source file:kenh.xscript.database.elements.Datasource.java

public void process(@Attribute(ATTRIBUTE_VARIABLE) String var) throws UnsupportedScriptException {
    var = StringUtils.trimToEmpty(var);

    if (StringUtils.isBlank(var)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this, "Variable name is empty.");
        throw ex;
    }/*from   w w  w. j a  v a 2  s .  c  o m*/

    Properties properties = new Properties();

    this.invokeChildren();
    Vector<Element> children = this.getChildren();

    for (Element child : children) {
        if (child instanceof Param) {
            Param c = (Param) child;
            String name = c.getName();
            Object value = Param.getParsedValue(c);
            if (c.isLink()) {
                String linkName = c.getLinkName();
                if (!properties.containsKey(linkName))
                    new UnsupportedScriptException(this,
                            "Could not find the parameter to link. [" + name + ", " + linkName + "]");
                value = properties.get(linkName);
            }

            properties.put(name, value);
        }
    }

    try {
        DataSource datasource = BasicDataSourceFactory.createDataSource(properties);
        this.saveVariable(var, datasource, null);

    } catch (Exception e) {
        throw new UnsupportedScriptException(this, e);
    }
}

From source file:com.vmware.vfabric.hyperic.plugin.vfws.PWSServerDetector.java

private List<ServerResource> getServers(List<String> ptqlQueries) {
    List<ServerResource> servers = new ArrayList<ServerResource>();
    // Flag to track success
    Boolean success = false;/*from w w  w  .  j  a v a 2 s .  c  o m*/
    for (final Iterator<String> it = ptqlQueries.iterator(); it.hasNext();) {
        String ptql = (String) it.next();
        final long[] pids = getPids(ptql);
        if (null != pids && pids.length > 0) {
            for (int i = 0; i < pids.length; i++) {
                Long pid = pids[i];
                String installPath = getInstallPath(pid);
                if (null == installPath) {
                    _log.debug("Found pid " + pid + ", but couldn't identify installpath");
                    continue;
                }
                URL bmxUrl = findBmxUrl(installPath, HTTPD_CONF);
                if (bmxUrl == null) {
                    _log.debug("Parsing " + installPath + HTTPD_CONF + " failed to find "
                            + "usable Listen directive.");
                    continue;
                }
                URL bmxQueryUrl = getBmxQueryUrl(bmxUrl, QUERY_BMX + SERVER_STATUS);
                BmxQuery query = new BmxQuery(bmxQueryUrl);
                BmxResult result = query.getResult();
                try {
                    result.parseToProperties();
                    success = true;
                } catch (IOException e) {
                    _log.debug("Unable to parse results", e);
                    continue;
                }
                Properties serverStatus = result.getProperties();
                ServerResource server = createServerResource(installPath);
                ConfigResponse cprop = new ConfigResponse();
                String version = getVersion((String) serverStatus.get("ServerVersion"));
                if (!version.equals(getTypeInfo().getVersion())) {
                    // Version not matched
                    continue;
                }
                cprop.setValue("version", version);
                cprop.setValue("ServerVersion", (String) serverStatus.get("ServerVersion"));
                server.setCustomProperties(cprop);
                ConfigResponse productConfig = new ConfigResponse();
                productConfig.setValue("process.query", getProcessQuery(ptql, installPath));
                productConfig.setValue("protocol", bmxUrl.getProtocol());
                productConfig.setValue("port", bmxUrl.getPort());
                productConfig.setValue("hostname", bmxUrl.getHost());
                productConfig.setValue("path", bmxUrl.getPath() + QUERY_BMX + SERVER_STATUS);
                setProductConfig(server, productConfig);
                // sets a default Measurement Config property with no values
                setMeasurementConfig(server, new ConfigResponse());
                ConfigResponse controlConfig = getControlConfig(installPath);
                String instanceName = getInstanceName(installPath);
                setControlConfig(server, controlConfig);
                server.setName(getPlatformName() + " " + getServerName(RESOURCE_TYPE) + " " + version + " "
                        + instanceName);
                server.setDescription(getServerDescription(server.getInstallPath()));
                servers.add(server);
            }
            if (!success) {
                // this is not error.
                _log.debug(
                        "[getServers] Found potential PWS process however was unable to determine URL of mod_bmx");
                _log.debug(
                        "[getServers] Make sure -d is specified on command line and that proxying or redirecting isn't including /bmx");
            }
        }
    }
    return servers;
}