Example usage for java.util Dictionary get

List of usage examples for java.util Dictionary get

Introduction

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

Prototype

public abstract V get(Object key);

Source Link

Document

Returns the value to which the key is mapped in this dictionary.

Usage

From source file:org.millr.slick.impl.services.OsgiServiceImpl.java

public boolean getBooleanProperty(final String pid, final String property, final boolean defaultValue) {
    try {//from  w w w.  ja  v a  2  s  .c o m
        Configuration conf = configAdmin.getConfiguration(pid);

        @SuppressWarnings("unchecked")
        Dictionary<String, Object> props = conf.getProperties();

        if (props != null) {
            return PropertiesUtil.toBoolean(props.get(property), defaultValue);
        }
    } catch (IOException e) {
        LOGGER.error("Could not get property", e);
    }

    return defaultValue;
}

From source file:org.openhab.binding.mqttitude.internal.MqttitudeBinding.java

private String getOptionalProperty(Dictionary<String, ?> properties, String name, String defaultValue) {
    if (properties == null)
        return defaultValue;

    String value = (String) properties.get(name);

    if (StringUtils.isBlank(value))
        return defaultValue;

    return value.trim();
}

From source file:ch.entwine.weblounge.contentrepository.impl.ContentRepositoryServiceFactory.java

/**
 * {@inheritDoc}//from ww w  . ja va  2 s .c o  m
 * 
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 */
public void updated(Dictionary properties) throws ConfigurationException {
    String repositoryType = (String) properties.get(OPT_TYPE);
    if (StringUtils.isBlank(repositoryType))
        repositoryType = DEFAULT_REPOSITORY_TYPE;
    if (!StringUtils.trimToEmpty(this.repositoryType).equals(repositoryType)) {
        logger.info("Default content repository implementation is {}", repositoryType);
        this.repositoryType = repositoryType;
    }
}

From source file:org.apache.sling.auth.xing.login.impl.XingLoginAuthenticationHandler.java

protected void configure(final ComponentContext context) {
    final Dictionary properties = context.getProperties();
    consumerKey = PropertiesUtil.toString(properties.get(CONSUMER_KEY_PARAMETER), "").trim();
    userCookie = PropertiesUtil.toString(properties.get(USER_COOKIE_PARAMETER), DEFAULT_USER_COOKIE).trim();
    userIdCookie = PropertiesUtil.toString(properties.get(USERID_COOKIE_PARAMETER), DEFAULT_USERID_COOKIE)
            .trim();//from  w  w  w . j a  v a 2s.co  m
    maxCookieSize = PropertiesUtil.toInteger(properties.get(MAX_COOKIE_SIZE_PARAMETER),
            DEFAULT_MAX_COOKIE_SIZE);
    loginPath = PropertiesUtil.toString(properties.get(LOGIN_PATH_PARAMETER), "").trim();
    logoutPath = PropertiesUtil.toString(properties.get(LOGOUT_PATH_PARAMETER), "").trim();

    if (StringUtils.isEmpty(consumerKey)) {
        logger.warn("configured consumer key is empty");
        xingCookie = "";
    } else {
        xingCookie = XingLogin.XING_COOKIE_PREFIX.concat(consumerKey);
    }

    if (loginPageRegistration != null) {
        loginPageRegistration.unregister();
    }

    if (StringUtils.isEmpty(loginPath)) {
        logger.warn("configured login path is empty");
    } else {
        final Dictionary<String, Object> loginPathProperties = new Hashtable<String, Object>();
        final String[] authRequirements = new String[] { "-".concat(loginPath) };
        loginPathProperties.put(AuthConstants.AUTH_REQUIREMENTS, authRequirements);
        loginPageRegistration = context.getBundleContext().registerService(Object.class.getName(), new Object(),
                loginPathProperties);
    }

    if (StringUtils.isEmpty(logoutPath)) {
        logger.warn("configured logout path is empty");
    }

    logger.info("configured with consumer key '{}', cookie name '{}', login path '{}' and logout path '{}'",
            consumerKey, xingCookie, loginPath, logoutPath);
}

From source file:org.openhab.binding.networkupstools.internal.NetworkUpsToolsBinding.java

/**
 * @{inheritDoc}/*  w  ww.ja  v  a2 s .  co m*/
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        Map<String, NutConfig> newUpses = new HashMap<String, NutConfig>();

        Enumeration<String> keys = config.keys();

        while (keys.hasMoreElements()) {
            String key = keys.nextElement();

            if ("refresh".equals(key) || "service.pid".equals(key)) {
                continue;
            }

            String[] parts = key.split("\\.");
            String name = parts[0];
            String prop = parts[1];
            String value = (String) config.get(key);

            NutConfig nutConfig = newUpses.get(name);
            if (nutConfig == null) {
                nutConfig = new NutConfig();
                newUpses.put(name, nutConfig);
            }

            if ("device".equalsIgnoreCase(prop)) {
                nutConfig.device = value;
            } else if ("host".equalsIgnoreCase(prop)) {
                nutConfig.host = value;
            } else if ("login".equalsIgnoreCase(prop)) {
                nutConfig.login = value;
            } else if ("pass".equalsIgnoreCase(prop)) {
                nutConfig.pass = value;
            } else if ("port".equalsIgnoreCase(prop)) {
                nutConfig.port = Integer.parseInt(value);
            }
        }

        upses = newUpses;

        setProperlyConfigured(true);
    }
}

From source file:org.millr.slick.impl.services.OsgiServiceImpl.java

public Long getLongProperty(final String pid, final String property, final Long defaultValue) {
    long placeholder = -1L;
    long defaultTemp = defaultValue != null ? defaultValue : placeholder;

    try {/*from ww w  . j  av  a2  s. c o  m*/
        Configuration conf = configAdmin.getConfiguration(pid);

        @SuppressWarnings("unchecked")
        Dictionary<String, Object> props = conf.getProperties();

        if (props != null) {
            long result = PropertiesUtil.toLong(props.get(property), defaultTemp);

            return result == placeholder ? null : result;
        }
    } catch (IOException e) {
        LOGGER.error("Could not get property", e);
    }

    return defaultValue;
}

From source file:org.openhab.action.nma.internal.NotifyMyAndroidActionService.java

/**
 * @{inheritDoc/*ww  w.ja  v  a 2 s.co m*/
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Updating config");
    if (config != null) {
        logger.debug("Received new config");

        NotifyMyAndroid.developerKey = (String) config.get(PARAM_KEY_DEV_API_KEY);

        String appName = (String) config.get(PARAM_KEY_APP_NAME);
        if (!StringUtils.isEmpty(appName)) {
            NotifyMyAndroid.appName = appName;
        }

        String timeOut = (String) config.get(PARAM_KEY_TIMEOUT);
        if (!StringUtils.isEmpty(timeOut)) {
            try {
                NotifyMyAndroid.timeout = Integer.parseInt((String) config.get(PARAM_KEY_TIMEOUT));
            } catch (NumberFormatException e) {
                logger.warn("Can't parse the timeout value, falling back to default value");
            }
        }

        NotifyMyAndroid.apiKey = (String) config.get(PARAM_KEY_API_KEY);

        String defaultPriority = (String) config.get(PARAM_KEY_DEFAULT_PRIORITY);
        if (!StringUtils.isEmpty(defaultPriority)) {
            try {
                NotifyMyAndroid.defaultPriotiy = Integer
                        .parseInt((String) config.get(PARAM_KEY_DEFAULT_PRIORITY));
            } catch (NumberFormatException e) {
                logger.warn("Can't parse the default priority value, falling back to default value");
            }
        }

        NotifyMyAndroid.defaultUrl = (String) config.get(PARAM_KEY_DEFAULT_URL);
    } else {
        // We don't need necessarily any config
        logger.debug("Dictionary was NULL, didn't read any configuration");
    }

    isProperlyConfigured = true;
}

From source file:org.openhab.binding.ihc.internal.IhcConnection.java

@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    logger.debug("Configuration updated, config {}", config != null ? true : false);

    if (config != null) {
        ip = (String) config.get("ip");
        username = (String) config.get("username");
        password = (String) config.get("password");
        timeout = Integer.parseInt((String) config.get("timeout"));
        projectFile = (String) config.get("projectFile");

        // there is a valid IHC-configuration, so connect to the IHC
        // controller
        try {/*ww w.j av  a2s .c o m*/
            connect();
            isProperlyConfigured = true;
        } catch (Exception e) {
            logger.error("Connection to IHC / ELKO LS controller failed.", e);
            ihc = null;
        }

    }

}

From source file:org.opencastproject.capture.impl.XProperties.java

/**
 * Merges the properties from p into this properties object
 * /*  w  w  w  .jav a2 s .c  om*/
 * @param p
 *          The {@code Dictionary} you wish to add to this object
 */
public void merge(Dictionary<String, String> p) {
    Enumeration<String> keys = p.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        this.put(key, p.get(key));
    }
}

From source file:org.openhab.action.twitter.internal.TwitterActionService.java

/**
 * @{inheritDoc}//from w  w w. java2 s .c o  m
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {

        String appKeyString = (String) config.get("key");
        if (isNotBlank(appKeyString)) {
            consumerKey = appKeyString;
        }

        String appSecretString = (String) config.get("secret");
        if (isNotBlank(appSecretString)) {
            consumerSecret = appSecretString;
        }

        if (isBlank(consumerKey) || isBlank(consumerSecret)) {
            throw new ConfigurationException("twitter",
                    "The parameters 'key' or 'secret' are missing! Please refer to your 'openhab.cfg'");
        }

        String enabledString = (String) config.get("enabled");
        if (StringUtils.isNotBlank(enabledString)) {
            Twitter.isEnabled = Boolean.parseBoolean(enabledString);
        }

        isProperlyConfigured = true;
        start();
    }
}