List of usage examples for java.util Dictionary keys
public abstract Enumeration<K> keys();
From source file:org.openhab.binding.ACDBCommon.internal.ACDBBinding.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.debug(getBindingName() + ":calling updated(config)!"); String lowerBindingName = StringUtils.lowerCase(getBindingName()); if (config == null) { throw new ConfigurationException(lowerBindingName + ":url", "The SQL database URL is missing - please configure the " + lowerBindingName + ":url parameter in openhab.cfg"); }/* ww w .j a v a 2s . c o m*/ // read DB Server connection Information DBManager.serverCache = new HashMap<String, ServerInfo>(); Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Matcher matcher = DEVICES_PATTERN.matcher(key); if (!matcher.matches()) { continue; } matcher.reset(); matcher.find(); String serverId = matcher.group(1); ServerInfo server = DBManager.serverCache.get(serverId); if (server == null) { server = new ServerInfo(serverId); DBManager.serverCache.put(serverId, server); logger.debug("Created new DBserver Info " + serverId); } String configKey = matcher.group(2); String value = (String) config.get(key); if ("url".equals(configKey)) { server.setUrl(value); } else if ("user".equals(configKey)) { server.setUser(value); } else if ("password".equals(configKey)) { server.setPassword(value); } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } // read defult DBServer connection information String serverId = "DefultServer"; ServerInfo server = new ServerInfo(serverId); server.setUrl((String) config.get("url")); server.setUser((String) config.get("user")); server.setPassword((String) config.get("password")); DBManager.serverCache.put("DefultServer", server); String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } try { for (Map.Entry<String, ServerInfo> mapI : DBManager.serverCache.entrySet()) { ServerInfo serverI = mapI.getValue(); serverI.setDriverClassName(getDriverClassName()); if (StringUtils.isBlank(serverI.getUrl()) || StringUtils.isBlank(serverI.getUser()) || StringUtils.isBlank(serverI.getPassword())) { logger.warn("more information needed:" + serverI.toString()); continue; } serverI.openConnection(); } } catch (Exception e) { logger.error(getBindingName() + ":failed to connect DB.", e); } setProperlyConfigured(true); logger.debug(getBindingName() + ":updated(config) is called!"); }
From source file:org.opencastproject.capture.impl.ConfigurationManager.java
@SuppressWarnings("unchecked") @Override/*ww w. ja va 2s . c o m*/ public void updated(Dictionary props) throws ConfigurationException { if (props == null) { logger.debug("Null properties in updated!"); return; } logger.debug("Merging new properties into in-memory structure."); // Filter out all of the non-string objects from the incoming dictionary // If we don't do this then serialization of the RecordingImpl in CaptureAgentImpl doesn't work Enumeration<Object> keys = props.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = props.get(key); if (String.class.isInstance(key) && String.class.isInstance(value)) { // Trim the value before we allow it to end up in the properties. properties.put(key, ((String) value).trim()); } } // Attempt to parse the location of the configuration server try { url = new URL(properties.getProperty(CaptureParameters.CAPTURE_CONFIG_REMOTE_ENDPOINT_URL)); } catch (MalformedURLException e) { logger.warn("Malformed URL for {}, disabling polling.", CaptureParameters.CAPTURE_CONFIG_REMOTE_ENDPOINT_URL); } // If there's no URL then throw up an info just to be safe if (url == null) { logger.info("No remote configuration endpoint was found, relying on local config."); } createCoreDirectories(); // Grab the remote config file, dump it to disk and then merge it into the current config Properties server = retrieveConfigFromServer(); if (server != null) { writeConfigFileToDisk(); merge(server, true); } // Shut down the old timer if it exists if (timer != null) { timer.cancel(); } // if reload property specified, query server for update at that interval String reload = getItem(CaptureParameters.CAPTURE_CONFIG_REMOTE_POLLING_INTERVAL); if (url != null && reload != null) { long delay = 0; try { // Times in the config file are in seconds, so don't forget to multiply by 1000 later delay = Long.parseLong(reload); if (delay < 1) { logger.info("Polling time has been set to less than 1 second, polling disabled."); return; } delay = delay * 1000L; timer = new Timer(); timer.schedule(new UpdateConfig(), delay, delay); } catch (NumberFormatException e) { logger.warn("Invalid polling time for parameter {}.", CaptureParameters.CAPTURE_CONFIG_REMOTE_POLLING_INTERVAL); } } /** * This synchronized is required! If a new listener were to add itself to the list of observers such that it missed * getting called in the refreshes and initialization was still false, refresh would not be automatically called * when it registers. This would result in refresh never being called for that listener. **/ synchronized (listeners) { for (ConfigurationManagerListener listener : listeners) { RefreshRunner refreshRunner = new RefreshRunner(listener); Thread thread = new Thread(refreshRunner); thread.start(); } // Set initialized to true so that every listener registered after this point will be updated immediately. initialized = true; } }
From source file:org.openhab.binding.withings.internal.api.WithingsAuthenticator.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { String redirectUrl = (String) config.get("redirectUrl"); if (StringUtils.isNotBlank(redirectUrl)) { this.redirectUrl = redirectUrl; }//from w ww.ja v a 2 s.com String consumerKeyString = (String) config.get("consumerkey"); if (StringUtils.isNotBlank(consumerKeyString)) { this.consumerKey = consumerKeyString; } String consumerSecretString = (String) config.get("consumersecret"); if (StringUtils.isNotBlank(consumerSecretString)) { this.consumerSecret = consumerSecretString; } Enumeration<String> configKeys = config.keys(); while (configKeys.hasMoreElements()) { String configKey = (String) configKeys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("redirectUrl".equals(configKey) || "consumerkey".equals(configKey) || "consumersecret".equals(configKey) || "service.pid".equals(configKey)) { continue; } String accountId; String configKeyTail; if (configKey.contains(".")) { String[] keyElements = configKey.split("\\."); accountId = keyElements[0]; configKeyTail = keyElements[1]; } else { accountId = DEFAULT_ACCOUNT_ID; configKeyTail = configKey; } WithingsAccount account = accountsCache.get(accountId); if (account == null) { account = new WithingsAccount(accountId, consumerKey, consumerSecret); accountsCache.put(accountId, account); } String value = (String) config.get(configKeyTail); if ("userid".equals(configKeyTail)) { account.userId = value; } else if ("token".equals(configKeyTail)) { account.token = value; } else if ("tokensecret".equals(configKeyTail)) { account.tokenSecret = value; } else { throw new ConfigurationException(configKey, "The given configuration key is unknown!"); } } registerAccounts(); } }
From source file:org.openhab.binding.sunnywebbox.internal.SunnyWebBoxBinding.java
/** * @{inheritDoc//from w w w . j ava 2 s .co m */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { // to override the default refresh interval one has to add a // parameter to openhab.cfg like // <bindingName>:refresh=<intervalInMs> String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { logger.debug("refresh is set to " + refreshIntervalString); refreshInterval = Long.parseLong(refreshIntervalString); } // String URLConfig = (String) config.get("URL"); Enumeration<String> configElementsKeys = config.keys(); while (configElementsKeys.hasMoreElements()) { String configElementKey = configElementsKeys.nextElement(); logger.debug("config element: " + configElementKey); if (configElementKey.startsWith("URL")) { URLs.put(configElementKey, (String) config.get(configElementKey)); } } // System.exit(0); // config. // if (StringUtils.isNotBlank(URLConfig)) { // URL = URLConfig; // } // read further config parameters here ... setProperlyConfigured(true); } }
From source file:org.paxle.core.filter.impl.FilterManager.java
/** * @see ManagedService#updated(Dictionary) *///w w w . j ava 2s. c om @SuppressWarnings("unchecked") public synchronized void updated(Dictionary properties) throws ConfigurationException { if (properties == null) return; // getting default filter statis Boolean defaultStatus = (Boolean) properties.get(CM_FILTER_DEFAULT_STATUS); if (defaultStatus != null) this.enableNewFilters = defaultStatus; // getting filter-status settings Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (!key.startsWith(CM_FILTER_ENABLED_FILTERS)) continue; String[] enabledFiltes = (String[]) properties.get(key); if (enabledFiltes != null) { String queueID = key.substring(CM_FILTER_ENABLED_FILTERS.length()); // remember enabled filters Set<String> enabledFilters = this.getEnabledFilters(queueID); enabledFilters.clear(); enabledFilters.addAll(Arrays.asList(enabledFiltes)); // getting all filters registered for the queue Set<FilterContext> knownFilters = this.getRegisteredFilters(queueID); // updating filter-context status for (FilterContext fContext : knownFilters) { boolean enabled = enabledFilters.contains(fContext.getFilterContextPID()); fContext.setEnabled(enabled); } // getting the queue IFilterQueue queue = this.getQueue(queueID); if (this.queues.containsKey(queueID)) { // apply filters to the queue this.setFilters(queue, knownFilters, enabledFilters); } } } }
From source file:org.openhab.io.caldav.internal.CalDavLoaderImpl.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true); // just temporary Map<String, CalDavConfig> configMap = new HashMap<String, CalDavConfig>(); Enumeration<String> iter = config.keys(); while (iter.hasMoreElements()) { String key = iter.nextElement(); log.trace("configuration parameter: " + key); if (key.equals("service.pid")) { continue; } else if (key.equals(PROP_TIMEZONE)) { log.debug("overriding default timezone {} with {}", defaultTimeZone, config.get(key)); defaultTimeZone = DateTimeZone.forID(config.get(key) + ""); if (defaultTimeZone == null) { throw new ConfigurationException(PROP_TIMEZONE, "invalid timezone value: " + config.get(key)); }//from w w w . ja v a2s . c o m log.debug("found timeZone: {}", defaultTimeZone); continue; } String[] keys = key.split(":"); if (keys.length != 2) { throw new ConfigurationException(key, "unknown identifier"); } String id = keys[0]; String paramKey = keys[1]; CalDavConfig calDavConfig = configMap.get(id); if (calDavConfig == null) { calDavConfig = new CalDavConfig(); configMap.put(id, calDavConfig); } String value = config.get(key) + ""; calDavConfig.setKey(id); if (paramKey.equals(PROP_USERNAME)) { calDavConfig.setUsername(value); } else if (paramKey.equals(PROP_PASSWORD)) { calDavConfig.setPassword(value); } else if (paramKey.equals(PROP_URL)) { calDavConfig.setUrl(value); } else if (paramKey.equals(PROP_RELOAD_INTERVAL)) { calDavConfig.setReloadMinutes(Integer.parseInt(value)); } else if (paramKey.equals(PROP_PRELOAD_TIME)) { calDavConfig.setPreloadMinutes(Integer.parseInt(value)); } else if (paramKey.equals(PROP_HISTORIC_LOAD_TIME)) { calDavConfig.setHistoricLoadMinutes(Integer.parseInt(value)); } else if (paramKey.equals(PROP_DISABLE_CERTIFICATE_VERIFICATION)) { calDavConfig.setDisableCertificateVerification(BooleanUtils.toBoolean(value)); } } // verify if all required parameters are set for (String id : configMap.keySet()) { if (configMap.get(id).getUrl() == null) { throw new ConfigurationException(PROP_URL, PROP_URL + " must be set"); } if (configMap.get(id).getUsername() == null) { throw new ConfigurationException(PROP_USERNAME, PROP_USERNAME + " must be set"); } if (configMap.get(id).getPassword() == null) { throw new ConfigurationException(PROP_PASSWORD, PROP_PASSWORD + " must be set"); } log.trace("config for id '{}': {}", id, configMap.get(id)); } // initialize event cache for (CalDavConfig calDavConfig : configMap.values()) { final CalendarRuntime eventRuntime = new CalendarRuntime(); eventRuntime.setConfig(calDavConfig); File cachePath = Util.getCachePath(calDavConfig.getKey()); if (!cachePath.exists() && !cachePath.mkdirs()) { log.error( "cannot create directory (" + CACHE_PATH + ") for calendar caching (missing rights?)"); continue; } EventStorage.getInstance().getEventCache().put(calDavConfig.getKey(), eventRuntime); } setProperlyConfigured(true); this.startLoading(); } }
From source file:org.openhab.binding.sonos.internal.SonosBinding.java
@SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; }/* ww w. ja v a 2 s .co m*/ if ("pollingPeriod".equals(key)) { pollingPeriod = Integer.parseInt((String) config.get(key)); logger.debug("Setting polling period to {} ms", pollingPeriod); continue; } Matcher matcher = EXTRACT_SONOS_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.debug("given sonos-config-key '" + key + "' does not follow the expected pattern '<sonosId>.<udn>'"); continue; } matcher.reset(); matcher.find(); String sonosID = matcher.group(1); SonosZonePlayer sonosConfig = sonosZonePlayerCache.getById(sonosID); if (sonosConfig == null) { sonosConfig = new SonosZonePlayer(sonosID, self); sonosZonePlayerCache.add(sonosConfig); } String configKey = matcher.group(2); String value = (String) config.get(key); if ("udn".equals(configKey)) { sonosConfig.setUdn(new UDN(value)); logger.debug("Add predefined Sonos device with UDN {}", sonosConfig.getUdn()); } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } } setProperlyConfigured(true); }
From source file:org.jahia.modules.modulemanager.flow.ModuleManagementFlowHandler.java
private void populateActiveVersion(RequestContext context, JahiaTemplatesPackage value) { context.getRequestScope().put("activeVersion", value); Map<String, String> bundleInfo = new HashMap<String, String>(); Dictionary<String, String> dictionary = value.getBundle().getHeaders(); Enumeration<String> keys = dictionary.keys(); while (keys.hasMoreElements()) { String s = keys.nextElement(); bundleInfo.put(s, dictionary.get(s)); }/*from w w w. ja v a 2s .c o m*/ context.getRequestScope().put("bundleInfo", bundleInfo); context.getRequestScope().put("activeVersionDate", new Date(value.getBundle().getLastModified())); context.getRequestScope().put("dependantModules", templateManagerService.getTemplatePackageRegistry().getDependantModules(value)); }
From source file:ddf.catalog.source.opensearch.CddaOpenSearchSite.java
private Map<String, String> updateDefaultClassification() { HashMap<String, String> securityProps = new HashMap<String, String>(); logger.debug("Assigning default classification values"); if (siteSecurityConfig != null) { logger.debug("setting properties from config admin"); try {/*from ww w . j av a 2s .co m*/ // siteSecurityConfig.update(); @SuppressWarnings("unchecked") Dictionary<String, Object> propertyDictionary = (Dictionary<String, Object>) siteSecurityConfig .getProperties(); Enumeration<String> propertyKeys = propertyDictionary.keys(); while (propertyKeys.hasMoreElements()) { String currKey = propertyKeys.nextElement(); String currValue = propertyDictionary.get(currKey).toString(); securityProps.put(currKey, currValue); } logger.debug("security properties: " + securityProps); } catch (Exception e) { logger.warn("Exception thrown while trying to obtain default properties. " + "Setting all default classifications and owner/producers to U and USA respectively as a last resort.", e); securityProps.clear(); // this is being cleared, so the // "last-resort" defaults specified in // the xsl will be used. } } else { logger.info("site security config is null"); securityProps.clear(); // this is being cleared, so the // "last-resort" defaults specified in the // xsl will be used. } return securityProps; }
From source file:org.openhab.binding.plclogo.internal.PLCLogoBinding.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { Boolean configured = false;//from w ww . ja v a2s .com if (config != null) { String refreshIntervalString = Objects.toString(config.get("refresh"), null); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } if (controllers == null) { controllers = new HashMap<String, PLCLogoConfig>(); } Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { continue; } matcher.reset(); matcher.find(); String controllerName = matcher.group(1); PLCLogoConfig deviceConfig = controllers.get(controllerName); if (deviceConfig == null) { deviceConfig = new PLCLogoConfig(); controllers.put(controllerName, deviceConfig); logger.info("Create new config for {}", controllerName); } if (matcher.group(2).equals("host")) { String ip = config.get(key).toString(); deviceConfig.setIP(ip); logger.info("Set host of {}: {}", controllerName, ip); configured = true; } if (matcher.group(2).equals("remoteTSAP")) { String tsap = config.get(key).toString(); deviceConfig.setRemoteTSAP(Integer.decode(tsap)); logger.info("Set remote TSAP for {}: {}", controllerName, tsap); } if (matcher.group(2).equals("localTSAP")) { String tsap = config.get(key).toString(); deviceConfig.setLocalTSAP(Integer.decode(tsap)); logger.info("Set local TSAP for {}: {}", controllerName, tsap); } if (matcher.group(2).equals("model")) { PLCLogoModel model = null; String modelName = config.get(key).toString(); if (modelName.equalsIgnoreCase("0BA7")) { model = PLCLogoModel.LOGO_MODEL_0BA7; } else if (modelName.equalsIgnoreCase("0BA8")) { model = PLCLogoModel.LOGO_MODEL_0BA8; } else { logger.info("Found unknown model for {}: {}", controllerName, modelName); } if (model != null) { deviceConfig.setModel(model); logger.info("Set model for {}: {}", controllerName, modelName); } } } // while Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator(); while (entries.hasNext()) { Entry<String, PLCLogoConfig> thisEntry = entries.next(); String controllerName = thisEntry.getKey(); PLCLogoConfig deviceConfig = thisEntry.getValue(); S7Client LogoS7Client = deviceConfig.getS7Client(); if (LogoS7Client == null) { LogoS7Client = new Moka7.S7Client(); } else { LogoS7Client.Disconnect(); } LogoS7Client.SetConnectionParams(deviceConfig.getlogoIP(), deviceConfig.getlocalTSAP(), deviceConfig.getremoteTSAP()); logger.info("About to connect to {}", controllerName); if ((LogoS7Client.Connect() == 0) && LogoS7Client.Connected) { logger.info("Connected to PLC LOGO! device {}", controllerName); } else { logger.error("Could not connect to PLC LOGO! device {} : {}", controllerName, S7Client.ErrorText(LogoS7Client.LastError)); throw new ConfigurationException("Could not connect to PLC LOGO! device ", controllerName + " " + deviceConfig.getlogoIP()); } deviceConfig.setS7Client(LogoS7Client); } setProperlyConfigured(configured); } else { logger.info("No configuration for PLCLogoBinding"); } }