List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.eclipse.smarthome.model.core.internal.folder.FolderObserver.java
@SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { // make sure to clear the caches first lastFileNames.clear();// ww w . j av a2 s .co m lastCheckedMap.clear(); folderFileExtMap.clear(); folderRefreshMap.clear(); Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String foldername = (String) keys.nextElement(); if (foldername.equals("service.pid")) continue; String[] values = ((String) config.get(foldername)).split(","); try { Integer refreshValue = Integer.valueOf(values[0]); String[] fileExts = (String[]) ArrayUtils.remove(values, 0); File folder = getFolder(foldername); if (folder.exists() && folder.isDirectory()) { folderFileExtMap.put(foldername, fileExts); if (refreshValue > 0) { folderRefreshMap.put(foldername, refreshValue); if (!this.isAlive()) { // seems we have the first folder to observe, so let's start the thread this.start(); } else { // make sure that we notify the sleeping thread and directly refresh the folders synchronized (FolderObserver.this) { notify(); checkFolder(foldername); } } } else { // deactivate the refresh for this folder folderRefreshMap.remove(foldername); checkFolder(foldername); } } else { logger.warn( "Directory '{}' does not exist in '{}'. Please check your configuration settings!", foldername, ConfigDispatcher.getConfigFolder()); } // now update the refresh information for the thread Integer[] refreshValues = folderRefreshMap.values().toArray(new Integer[0]); if (refreshValues.length > 0) { gcdRefresh = MathUtils.gcd(refreshValues); lcmRefresh = MathUtils.lcm(refreshValues); } refreshCount = 0; } catch (NumberFormatException e) { logger.warn("Invalid value '{}' for configuration '{}'. Integer value expected!", values[0], ModelCoreConstants.SERVICE_PID + ":" + foldername); } } } }
From source file:org.openhab.binding.fritzbox.internal.FritzboxBinding.java
/** * {@inheritDoc}// w ww . j a va2 s. co m */ @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { String ip = (String) config.get("ip"); if (StringUtils.isNotBlank(ip)) { if (!ip.equals(FritzboxBinding.ip)) { // only do something if the ip has changed FritzboxBinding.ip = ip; conditionalDeActivate(); // schedule a daily reconnection as sometimes the FritzBox // stops sending data // and thus blocks the monitor thread try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); JobKey jobKey = jobKey("Reconnect", "FritzBox"); TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox"); if (sched.checkExists(jobKey)) { logger.debug("Daily reconnection job already exists"); } else { CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronSchedule); JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build(); CronTrigger trigger = newTrigger().withIdentity(triggerKey) .withSchedule(scheduleBuilder).build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled a daily reconnection to FritzBox on {}:{}", ip, MONITOR_PORT); } } catch (SchedulerException e) { logger.warn("Could not create daily reconnection job", e); } } } String password = (String) config.get("password"); if (StringUtils.isNotBlank(password)) { FritzboxBinding.password = password; } String username = (String) config.get("user"); if (StringUtils.isNotBlank(username)) { FritzboxBinding.username = username; } } }
From source file:org.opencastproject.distribution.youtube.YoutubeDistributionService.java
/** * {@inheritDoc}//from ww w . j a v a 2 s. c o m * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ @Override public synchronized void updated(Dictionary properties) throws ConfigurationException { logger.info("Update method from managed service"); String username = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.username")); String password = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.password")); String clientid = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.clientid")); String developerkey = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.developerkey")); String category = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.category")); String keywords = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.keywords")); String privacy = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.private")); String isChunked = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.chunked")); defaultPlaylist = StringUtils .trimToNull((String) properties.get("org.opencastproject.distribution.youtube.default.playlist")); // Setup configuration from properties if (StringUtils.isBlank(clientid)) throw new IllegalArgumentException("Youtube clientid must be specified"); if (StringUtils.isBlank(developerkey)) throw new IllegalArgumentException("Youtube developerkey must be specified"); if (StringUtils.isBlank(username)) throw new IllegalArgumentException("Youtube username must be specified"); if (StringUtils.isBlank(password)) throw new IllegalArgumentException("Youtube password must be specified"); if (StringUtils.isBlank(category)) throw new IllegalArgumentException("Youtube category must be specified"); if (StringUtils.isBlank(keywords)) throw new IllegalArgumentException("Youtube keywords must be specified"); if (StringUtils.isBlank(privacy)) throw new IllegalArgumentException("Youtube privacy must be specified"); String uploadUrl = VIDEO_ENTRY_URL.replaceAll("\\{username\\}", username); config.setClientId(clientid); config.setDeveloperKey(developerkey); config.setUserId(username); config.setUploadUrl(uploadUrl); config.setPassword(password); config.setKeywords(keywords); config.setCategory(category); config.setVideoPrivate(Boolean.getBoolean(privacy)); if (StringUtils.isNotBlank(isChunked)) isDefaultChunked = Boolean.getBoolean(isChunked); }
From source file:org.openhab.binding.zigbee.internal.ZigbeeActiveBinding.java
/** * {@inheritDoc}/*from ww w. j av a 2 s . c o m*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config == null) return; System.out.println("ZIGBEEEEEEEEEEEEEEEEEEEE:" + config.toString()); // Check the serial port configuration value. // This value is mandatory. if (StringUtils.isNotBlank((String) config.get("port"))) { port = (String) config.get("port"); logger.info("Update config, port = {}", port); } if (StringUtils.isNotBlank((String) config.get("ip"))) { ipAddress = (String) config.get("ip"); logger.info("Update config, ipAddress = {}", ipAddress); } if (StringUtils.isNotBlank((String) config.get("healtime"))) { try { healtime = Integer.parseInt((String) config.get("healtime")); logger.info("Update config, healtime = {}", healtime); } catch (NumberFormatException e) { healtime = null; logger.error( "Error parsing 'healtime'. This must be a single number to set the hour to perform the heal."); } } if (StringUtils.isNotBlank((String) config.get("refreshInterval"))) { try { refreshInterval = Integer.parseInt((String) config.get("refreshInterval")); logger.info("Update config, refreshInterval = {}", refreshInterval); } catch (NumberFormatException e) { refreshInterval = 10000; logger.error("Error parsing 'refreshInterval'. This must be a single number time in milliseconds."); } } if (StringUtils.isNotBlank((String) config.get("pollingQueue"))) { try { pollingQueue = Integer.parseInt((String) config.get("pollingQueue")); logger.info("Update config, pollingQueue = {}", pollingQueue); } catch (NumberFormatException e) { pollingQueue = 2; logger.error("Error parsing 'pollingQueue'. This must be a single number time in milliseconds."); } } if (StringUtils.isNotBlank((String) config.get("timeout"))) { try { timeout = Integer.parseInt((String) config.get("timeout")); logger.info("Update config, timeout = {}", timeout); } catch (NumberFormatException e) { timeout = null; logger.error("Error parsing 'timeout'. This must be an Integer."); } } if (StringUtils.isNotBlank((String) config.get("setSUC"))) { try { isSUC = Boolean.parseBoolean((String) config.get("setSUC")); logger.info("Update config, setSUC = {}", isSUC); } catch (NumberFormatException e) { isSUC = false; logger.error("Error parsing 'setSUC'. This must be boolean."); } } // Now that we've read ALL the configuration, initialise the binding. initialise(); }
From source file:org.openhab.binding.denon.internal.DenonBinding.java
/** * {@inheritDoc}/*from ww w . j a v a 2 s . co m*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.debug("Denon binding updated"); if (config == null) { return; } Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (CONFIG_SERVICE_PID.equals(key)) { continue; } String[] parts = key.split("\\."); String value = Objects.toString(config.get(key), null); if (parts.length == 1) { String option = parts[0]; if (CONFIG_REFRESH.equals(option)) { refreshInterval = Integer.valueOf(value); } } else { String instance = parts[0]; DenonConnectionProperties connection = connections.get(instance); if (connection == null) { connection = new DenonConnectionProperties(); connection.setInstance(instance); connections.put(instance, connection); } String option = parts[1].trim(); if (CONFIG_HOST.equals(option)) { connection.setHost(value); } else if (CONFIG_UPDATE_TYPE.equals(option)) { connection.setTelnet(value.equals(CONFIG_UPDATE_TYPE_TELNET)); connection.setHttp(value.equals(CONFIG_UPDATE_TYPE_HTTP)); if (!value.equals(CONFIG_UPDATE_TYPE_TELNET) && !value.equals(CONFIG_UPDATE_TYPE_HTTP)) { logger.warn("Invalid connection type {} for instance {}, using default", value, instance); } } } } boolean isActiveBinding = false; for (Entry<String, DenonConnectionProperties> entry : connections.entrySet()) { DenonConnectionProperties connection = entry.getValue(); if (!StringUtils.isBlank(connection.getHost())) { logger.debug("Denon receiver configured at {}", connection.getHost()); DenonConnector connector = new DenonConnector(connection, new DenonPropertyUpdatedCallback() { @Override public void updated(String instance, String property, State state) { processPropertyUpdated(instance, property, state); } }); connection.setConnector(connector); connector.connect(); if (connection.isHttp()) { isActiveBinding = true; } } else { logger.debug("No host configured for receiver {}", connection.getInstance()); } } setProperlyConfigured(isActiveBinding); }
From source file:org.openhab.binding.plex.internal.PlexBinding.java
/** * @{inheritDoc}/*from www .j a v a 2s . com*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.debug("Plex binding updated"); if (config != null) { PlexConnectionProperties connectionProperties = new PlexConnectionProperties(); Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if ("service.pid".equals(key)) continue; String value = ((String) config.get(key)).trim(); if ("host".equals(key)) connectionProperties.setHost(value); else if ("port".equals(key)) connectionProperties.setPort(Integer.valueOf(value)); else if ("token".equals(key)) connectionProperties.setToken(value); else if ("username".equals(key)) connectionProperties.setUsername(value); else if ("password".equals(key)) connectionProperties.setPassword(value); else if ("refresh".equals(key)) if (StringUtils.isNumeric(value)) refreshInterval = Integer.valueOf(value); else logger.warn("Non-numeric refresh interval {}, using default {}", value, refreshInterval); } logger.debug("Plex config, server at {}:{}", connectionProperties.getHost(), connectionProperties.getPort()); if (!StringUtils.isEmpty(connectionProperties.getHost())) { connect(connectionProperties); setProperlyConfigured(true); } else { logger.warn("No host IP configured for Plex binding"); } } }
From source file:org.openhab.io.dropbox.internal.DropboxService.java
@SuppressWarnings("rawtypes") @Override/*from w w w. java 2s. c o m*/ public void updated(Dictionary config) throws ConfigurationException { if (config == null) { logger.debug("Updated() was called with a null config!"); return; } DropboxSynchronizer synchronizer = getDropboxSynchronizer(); String appKeyString = Objects.toString(config.get("appkey"), null); if (isNotBlank(appKeyString)) { appKey = appKeyString; } String appSecretString = Objects.toString(config.get("appsecret"), null); if (isNotBlank(appSecretString)) { appSecret = appSecretString; } String pat = Objects.toString(config.get("personalAccessToken"), null); if (isNotBlank(pat)) { personalAccessToken = pat; } if (logger.isDebugEnabled()) { StringBuffer message = new StringBuffer(); message.append("Authentication parameters to be used:\r\n"); if (isNotBlank(personalAccessToken)) { message.append(" Personal access token = " + personalAccessToken + "\r\n"); } else { message.append(" appkey = " + appKey + "\r\n"); message.append(" appsecret = " + appSecret + "\r\n"); } logger.debug(message.toString()); } if (isBlank(personalAccessToken) && (isBlank(appKey) || isBlank(appSecret))) { throw new ConfigurationException("dropbox:authentication", "The Dropbox authentication parameters are incorrect! " + "The parameter 'personalAccesstoken' must be set, or both of" + " the parameters 'appkey' and 'appsecret' must be set. Please" + " check your configuration."); } else if (isNotBlank(appKey) && isNotBlank(appSecret)) { appInfo = new DbxAppInfo(appKey, appSecret); } String fakeModeString = Objects.toString(config.get("fakemode"), null); if (isNotBlank(fakeModeString)) { synchronizer.setFakeMode(BooleanUtils.toBoolean(fakeModeString)); } String contentDirString = Objects.toString(config.get("contentdir"), null); synchronizer.setContentDir(contentDirString); String uploadIntervalString = Objects.toString(config.get("uploadInterval"), null); if (isNotBlank(uploadIntervalString)) { uploadInterval = uploadIntervalString; } String downloadIntervalString = Objects.toString(config.get("downloadInterval"), null); if (isNotBlank(downloadIntervalString)) { downloadInterval = downloadIntervalString; } String syncModeString = Objects.toString(config.get("syncmode"), null); if (isNotBlank(syncModeString)) { try { syncMode = DropboxSyncMode.valueOf(syncModeString.toUpperCase()); } catch (IllegalArgumentException iae) { throw new ConfigurationException("dropbox:syncmode", "Unknown SyncMode '" + syncModeString + "'. Valid SyncModes are 'DROPBOX_TO_LOCAL', 'LOCAL_TO_DROPBOX' and 'BIDIRECTIONAL'."); } } String uploadFilterString = Objects.toString(config.get("uploadfilter"), null); if (isNotBlank(uploadFilterString)) { String[] newFilterElements = uploadFilterString.split(","); synchronizer.setUploadFilterElements(Arrays.asList(newFilterElements)); } String downloadFilterString = Objects.toString(config.get("downloadfilter"), null); if (isNotBlank(downloadFilterString)) { String[] newFilterElements = downloadFilterString.split(","); synchronizer.setDownloadFilterElements(Arrays.asList(newFilterElements)); } // we got this far, so we define this synchronizer as properly configured ... isProperlyConfigured = true; logger.debug("Dropbox I/O is properly configured. Activating synchronizer."); activateSynchronizer(); }
From source file:org.openhab.binding.ddwrt.internal.DDWRTBinding.java
/** * {@inheritDoc}//from ww w . j a v a 2s .c o m */ @Override @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { logger.info("Update DD-WRT Binding configuration ..."); if (config == null) { return; } else { if (config.isEmpty()) { throw new RuntimeException("No properties in openhab.cfg set!"); } String ip = (String) config.get("ip"); if (StringUtils.isNotBlank(ip)) { if (!ip.equals(DDWRTBinding.ip)) { // only do something if the ip has changed DDWRTBinding.ip = ip; String port = (String) config.get("port"); if (!StringUtils.isNotBlank(port)) { port = "23"; } DDWRTBinding.port = port; conditionalDeActivate(); } } String username = (String) config.get("username"); if (StringUtils.isNotBlank(username)) { DDWRTBinding.username = username; } String password = (String) config.get("password"); if (StringUtils.isNotBlank(password)) { DDWRTBinding.password = password; } String interface_24 = (String) config.get("interface_24"); if (StringUtils.isNotBlank(interface_24)) { DDWRTBinding.interface_24 = interface_24; } String interface_50 = (String) config.get("interface_50"); if (StringUtils.isNotBlank(interface_50)) { DDWRTBinding.interface_50 = interface_50; } String interface_guest = (String) config.get("interface_guest"); if (StringUtils.isNotBlank(interface_guest)) { DDWRTBinding.interface_guest = interface_guest; } } }
From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java
private void copyIfDefined(String id, Dictionary<String, Object> source, Dictionary<String, Object> destination) { final Object value = source.get(id); if (value != null) { destination.put(id, value);// ww w . j a va 2s . c o m } }
From source file:org.openhab.binding.zwave.internal.ZWaveActiveBinding.java
/** * {@inheritDoc}/* www . j av a2 s . c o m*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config == null) { logger.info("ZWave 'updated' with null config"); return; } // Check the serial port configuration value. // This value is mandatory. if (StringUtils.isNotBlank((String) config.get("port"))) { port = (String) config.get("port"); logger.info("Update config, port = {}", port); } if (StringUtils.isNotBlank((String) config.get("healtime"))) { try { healtime = Integer.parseInt((String) config.get("healtime")); logger.info("Update config, healtime = {}", healtime); } catch (NumberFormatException e) { healtime = null; logger.error( "Error parsing 'healtime'. This must be a single number to set the hour to perform the heal."); } } if (StringUtils.isNotBlank((String) config.get("refreshInterval"))) { try { refreshInterval = Integer.parseInt((String) config.get("refreshInterval")); logger.info("Update config, refreshInterval = {}", refreshInterval); } catch (NumberFormatException e) { refreshInterval = 10000; logger.error("Error parsing 'refreshInterval'. This must be a single number time in milliseconds."); } } if (StringUtils.isNotBlank((String) config.get("pollingQueue"))) { try { pollingQueue = Integer.parseInt((String) config.get("pollingQueue")); logger.info("Update config, pollingQueue = {}", pollingQueue); } catch (NumberFormatException e) { pollingQueue = 2; logger.error("Error parsing 'pollingQueue'. This must be a single number time in milliseconds."); } } if (StringUtils.isNotBlank((String) config.get("aliveCheckPeriod"))) { try { aliveCheckPeriod = Integer.parseInt((String) config.get("aliveCheckPeriod")); logger.info("Update config, aliveCheckPeriod = {}", aliveCheckPeriod); } catch (NumberFormatException e) { aliveCheckPeriod = null; logger.error("Error parsing 'aliveCheckPeriod'. This must be an Integer."); } } if (StringUtils.isNotBlank((String) config.get("timeout"))) { try { timeout = Integer.parseInt((String) config.get("timeout")); logger.info("Update config, timeout = {}", timeout); } catch (NumberFormatException e) { timeout = null; logger.error("Error parsing 'timeout'. This must be an Integer."); } } if (StringUtils.isNotBlank((String) config.get("setSUC"))) { try { isSUC = Boolean.parseBoolean((String) config.get("setSUC")); logger.info("Update config, setSUC = {}", isSUC); } catch (NumberFormatException e) { isSUC = false; logger.error("Error parsing 'setSUC'. This must be boolean."); } } if (StringUtils.isNotBlank((String) config.get("softReset"))) { try { softReset = Boolean.parseBoolean((String) config.get("softReset")); logger.info("Update config, softReset = {}", softReset); } catch (NumberFormatException e) { softReset = false; logger.error("Error parsing 'softReset'. This must be boolean."); } } if (StringUtils.isNotBlank((String) config.get("masterController"))) { try { masterController = Boolean.parseBoolean((String) config.get("masterController")); logger.info("Update config, masterController = {}", masterController); } catch (NumberFormatException e) { masterController = true; logger.error("Error parsing 'masterController'. This must be boolean."); } } // Now that we've read ALL the configuration, initialise the binding. initialise(); }