List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:com.whizzosoftware.hobson.bootstrap.api.hub.OSGIHubManager.java
@Override public boolean authenticateAdmin(String userId, String hubId, String password) { String adminPassword = null;//from w ww .j a v a 2 s.c o m Configuration config = getConfiguration(); // if there's configuration available, try to obtain the encrypted admin password if (config != null) { Dictionary d = config.getProperties(); if (d != null) { adminPassword = (String) d.get(ADMIN_PASSWORD); } } // if it hasn't been set, default to the "admin" password if (adminPassword == null) { adminPassword = DigestUtils.sha256Hex("admin"); } return (adminPassword.equals(password)); }
From source file:org.openhab.binding.tcp.protocol.internal.UDPBinding.java
@SuppressWarnings("rawtypes") @Override/*from w w w . ja v a 2 s. c o m*/ public void updated(Dictionary config) throws ConfigurationException { super.updated(config); if (config != null) { String timeOutString = (String) config.get("buffersize"); if (StringUtils.isNotBlank(timeOutString)) { timeOut = Integer.parseInt((timeOutString)); } else { logger.info( "The maximum time out for blocking write operations will be set to the default vaulue of {}", timeOut); } String blockingString = (String) config.get("retryinterval"); if (StringUtils.isNotBlank(blockingString)) { blocking = Boolean.parseBoolean((blockingString)); } else { logger.info("The blocking nature of read/write operations will be set to the default vaulue of {}", blocking); } String preambleString = (String) config.get("preamble"); if (StringUtils.isNotBlank(preambleString)) { try { preAmble = preambleString.replaceAll("\\\\", "\\"); } catch (Exception e) { preAmble = preambleString; } } else { logger.info("The preamble for all write operations will be set to the default vaulue of {}", preAmble); } String postambleString = (String) config.get("postamble"); if (StringUtils.isNotBlank(postambleString)) { try { postAmble = postambleString.replaceAll("\\\\", "\\"); } catch (Exception e) { postAmble = postambleString; } } else { logger.info("The postamble for all write operations will be set to the default vaulue of {}", postAmble); } String updatewithresponseString = (String) config.get("updatewithresponse"); if (StringUtils.isNotBlank(updatewithresponseString)) { updateWithResponse = Boolean.parseBoolean((updatewithresponseString)); } else { logger.info("Updating states with returned values will be set to the default vaulue of {}", updateWithResponse); } String charsetString = (String) config.get("charset"); if (StringUtils.isNotBlank(charsetString)) { charset = charsetString; } else { logger.info("The characterset will be set to the default vaulue of {}", charset); } } }
From source file:org.openhab.action.pushover.internal.PushoverActionService.java
/** * @{inheritDoc}/*from w w w . jav a 2 s. c om*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.debug("Configuration file is being parsed."); if (config != null) { logger.debug("Configuration data exists. Parsing the paramaters."); String apiKey = (String) config.get(PARAM_KEY_API_KEY); if (!StringUtils.isEmpty(apiKey)) { Pushover.defaultApiKey = apiKey; } String user = (String) config.get(PARAM_KEY_USER); if (!StringUtils.isEmpty(user)) { Pushover.defaultUser = user; } String title = (String) config.get(PARAM_KEY_TITLE); if (!StringUtils.isEmpty(title)) { Pushover.defaultTitle = title; } String url = (String) config.get(PARAM_KEY_DEFAULT_URL); if (!StringUtils.isEmpty(url)) { Pushover.defaultUrl = url; } String urlTitle = (String) config.get(PARAM_KEY_DEFAULT_URL_TITLE); if (!StringUtils.isEmpty(urlTitle)) { Pushover.defaultUrlTitle = urlTitle; } String defaultPriority = (String) config.get(PARAM_KEY_DEFAULT_PRIORITY); if (!StringUtils.isEmpty(defaultPriority)) { try { Pushover.defaultPriority = 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."); } } String retry = (String) config.get(PARAM_KEY_RETRY); if (!StringUtils.isEmpty(retry)) { try { Pushover.retry = Integer.parseInt((String) config.get(PARAM_KEY_RETRY)); } catch (NumberFormatException e) { logger.warn("Can't parse the retry value, falling back to default value"); } } String expire = (String) config.get(PARAM_KEY_EXPIRE); if (!StringUtils.isEmpty(expire)) { try { Pushover.expire = Integer.parseInt((String) config.get(PARAM_KEY_EXPIRE)); } catch (NumberFormatException e) { logger.warn("Can't parse the expire message value, falling back to default value"); } } String timeOut = (String) config.get(PARAM_KEY_TIMEOUT); if (!StringUtils.isEmpty(timeOut)) { try { Pushover.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"); } } } else { // Messages can be sent by providing API Key and User key in the action binding, so no issue here. logger.debug("The configurations information was empty. No defaults for Pushover loaded."); } isProperlyConfigured = true; }
From source file:org.apache.stanbol.enhancer.nlp.utils.LanguageConfiguration.java
/** * Reads the config for the configured {@link #getProperty() property} * from the parsed configuration. <p> * This implementation supports//from w ww.j a v a 2s . c o m * <code>null</code> (sets the default), <code>String[]</code>, * <code>Collections<?></code> (Object{@link #toString() toString()} is called * on members) and comma separated {@link String}. * @param configuration the configuration */ public void setConfiguration(Dictionary<?, ?> configuration) throws ConfigurationException { processConfiguration(configuration.get(property)); }
From source file:org.eclipse.virgo.ide.management.remote.StandardBundleAdmin.java
@ManagedOperation(description = "Returns the current OSGi Bundles") public Map<Long, Bundle> retrieveBundles() { Map<Long, Bundle> bundles = new HashMap<Long, Bundle>(); for (org.osgi.framework.Bundle b : this.bundleContext.getBundles()) { Object version = b.getHeaders().get("Bundle-Version"); Bundle bundle = new Bundle(Long.toString(b.getBundleId()), b.getSymbolicName(), version != null ? version.toString() : "0", getState(b), b.getLocation()); Dictionary<?, ?> headers = b.getHeaders(); Enumeration<?> keys = headers.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = headers.get(key); bundle.addHeader(key.toString(), value.toString()); }/*w w w . j av a 2 s. co m*/ BundleDescription bundleDescription = this.platformAdmin.getState(false).getBundle(b.getBundleId()); ExportPackageDescription[] exportedPackages = bundleDescription.getExportPackages(); if (exportedPackages != null) { for (ExportPackageDescription exportedPackage : exportedPackages) { PackageExport packageExport = new PackageExport(exportedPackage.getName(), exportedPackage.getVersion() != null ? exportedPackage.getVersion().toString() : "0"); bundle.addPackageExport(packageExport); } } ExportPackageDescription[] visiblePackages = this.platformAdmin.getStateHelper() .getVisiblePackages(bundleDescription); if (visiblePackages != null) { for (ExportPackageDescription visiblePackage : visiblePackages) { PackageImport packageImport = new PackageImport(visiblePackage.getName(), visiblePackage.getVersion() != null ? visiblePackage.getVersion().toString() : "0", Long.toString(visiblePackage.getSupplier().getBundleId())); bundle.addPackageImport(packageImport); } } if (b.getRegisteredServices() != null) { for (ServiceReference ref : b.getRegisteredServices()) { org.eclipse.virgo.ide.management.remote.ServiceReference reference = new org.eclipse.virgo.ide.management.remote.ServiceReference( Type.REGISTERED, ref.getBundle().getBundleId(), OsgiServiceReferenceUtils.getServiceObjectClasses(ref)); Map<?, ?> props = OsgiServiceReferenceUtils.getServicePropertiesAsMap(ref); for (Object key : props.keySet()) { String value = props.get(key).toString(); if (props.get(key).getClass().isArray()) { value = Arrays.deepToString((Object[]) props.get(key)); } reference.addProperty(key.toString(), value); } if (ref.getUsingBundles() != null) { for (org.osgi.framework.Bundle usingBundle : ref.getUsingBundles()) { reference.addUsingBundle(usingBundle.getBundleId()); } } bundle.addRegisteredService(reference); } } if (b.getServicesInUse() != null) { for (ServiceReference ref : b.getServicesInUse()) { org.eclipse.virgo.ide.management.remote.ServiceReference reference = new org.eclipse.virgo.ide.management.remote.ServiceReference( Type.IN_USE, ref.getBundle().getBundleId(), OsgiServiceReferenceUtils.getServiceObjectClasses(ref)); Map<?, ?> props = OsgiServiceReferenceUtils.getServicePropertiesAsMap(ref); for (Object key : props.keySet()) { String value = props.get(key).toString(); if (props.get(key).getClass().isArray()) { value = Arrays.deepToString((Object[]) props.get(key)); } reference.addProperty(key.toString(), value); } if (ref.getUsingBundles() != null) { for (org.osgi.framework.Bundle usingBundle : ref.getUsingBundles()) { reference.addUsingBundle(usingBundle.getBundleId()); } } bundle.addUsingService(reference); } } bundles.put(Long.valueOf(bundle.getId()), bundle); } return bundles; }
From source file:org.openhab.binding.akm868.internal.AKM868Binding.java
/** * @{inheritDoc}/*from ww w . j a v a 2 s.c o 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)) { refreshInterval = Long.parseLong(refreshIntervalString); } String hostString = (String) config.get("host"); if (StringUtils.isNotBlank(hostString)) { host = hostString; } String portString = (String) config.get("port"); if (StringUtils.isNotBlank(portString)) { port = Integer.parseInt(portString); } String timeoutString = (String) config.get("timeout"); if (StringUtils.isNotBlank(timeoutString)) { timeout = Long.parseLong(timeoutString); } // make sure that there is no listener running packetlistener.stopListener(); // send the parsed information to the listener packetlistener.initializeReceiver(host, port, timeout); // start the listener new Thread(packetlistener).start(); setProperlyConfigured(true); } }
From source file:ch.entwine.weblounge.kernel.security.SystemAdminDirectoryProvider.java
/** * {@inheritDoc}//from w w w.j a v a2 s . c o m * * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary) */ @SuppressWarnings("rawtypes") public void updated(Dictionary properties) throws ConfigurationException { String login = null; String pass = ""; String digest = null; String name = null; String email = null; if (properties != null) { login = StringUtils.trimToNull((String) properties.get(OPT_ADMIN_LOGIN)); pass = StringUtils.trimToEmpty((String) properties.get(OPT_ADMIN_PASSWORD)); digest = StringUtils.trimToEmpty((String) properties.get(OPT_ADMIN_DIGEST)); name = StringUtils.trimToEmpty((String) properties.get(OPT_ADMIN_NAME)); email = StringUtils.trimToEmpty((String) properties.get(OPT_ADMIN_EMAIL)); } // If no user can be found if (login == null || "".equals(pass)) { logger.info("No system accounts have been defined"); if (administrator != null) logger.info("Deactivating system admin account"); administrator = null; return; } // Register the new one logger.info("Activating system admin user '{}'", login); administrator = new WebloungeUserImpl(login, Security.SYSTEM_CONTEXT); if (StringUtils.isNotBlank(name)) administrator.setName(name); if (StringUtils.isNotBlank(email)) administrator.setEmail(email); DigestType digestType = DigestType.plain; if (StringUtils.isNotBlank(digest)) { try { digestType = DigestType.valueOf(digest); } catch (IllegalArgumentException e) { logger.error("Digest type '{}' is unknown", digest); throw new ConfigurationException(OPT_ADMIN_DIGEST, digest); } } if (StringUtils.isNotBlank(pass)) { Password password = new PasswordImpl(StringUtils.trimToEmpty(pass), digestType); administrator.addPrivateCredentials(password); } // Add the roles for (Role role : SystemRole.SYSTEMADMIN.getClosure()) { administrator.addPublicCredentials(role); } }
From source file:ch.entwine.weblounge.bridge.mail.MailAggregator.java
/** * {@inheritDoc}/*w w w . ja va2 s.c om*/ * * @see ch.entwine.weblounge.common.scheduler.JobWorker#execute(java.lang.String, * java.util.Dictionary) */ public void execute(String name, Dictionary<String, Serializable> ctx) throws JobException { Site site = (Site) ctx.get(Site.class.getName()); // Make sure the site is ready to accept content if (site.getContentRepository().isReadOnly()) { logger.warn("Unable to publish e-mail messages to site '{}': repository is read only", site); return; } WritableContentRepository repository = (WritableContentRepository) site.getContentRepository(); // Extract the configuration from the job properties String provider = (String) ctx.get(OPT_PROVIDER); Account account = null; try { if (StringUtils.isBlank(provider)) { provider = DEFAULT_PROVIDER; } account = new Account(ctx); } catch (IllegalArgumentException e) { throw new JobException(this, e); } // Connect to the server Properties sessionProperties = new Properties(); Session session = Session.getDefaultInstance(sessionProperties, null); Store store = null; Folder inbox = null; try { // Connect to the server try { store = session.getStore(provider); store.connect(account.getHost(), account.getLogin(), account.getPassword()); } catch (NoSuchProviderException e) { throw new JobException(this, "Unable to connect using unknown e-mail provider '" + provider + "'", e); } catch (MessagingException e) { throw new JobException(this, "Error connecting to " + provider + " account " + account, e); } // Open the account's inbox try { inbox = store.getFolder(INBOX); if (inbox == null) throw new JobException(this, "No inbox found at " + account); inbox.open(Folder.READ_WRITE); } catch (MessagingException e) { throw new JobException(this, "Error connecting to inbox at " + account, e); } // Get the messages from the server try { for (Message message : inbox.getMessages()) { if (!message.isSet(Flag.SEEN)) { try { Page page = aggregate(message, site); message.setFlag(Flag.DELETED, true); repository.put(page, true); logger.info("E-Mail message published at {}", page.getURI()); } catch (Exception e) { logger.info("E-Mail message discarded: {}", e.getMessage()); message.setFlag(Flag.SEEN, true); // TODO: Reply to sender if the "from" field exists } } } } catch (MessagingException e) { throw new JobException(this, "Error loading e-mail messages from inbox", e); } // Close the connection // but don't remove the messages from the server } finally { if (inbox != null) { try { inbox.close(true); } catch (MessagingException e) { throw new JobException(this, "Error closing inbox", e); } } if (store != null) { try { store.close(); } catch (MessagingException e) { throw new JobException(this, "Error closing connection to e-mail server", e); } } } }
From source file:org.eclipse.swordfish.core.configuration.ManagedServiceAdapter.java
public void updated(Dictionary properties) throws ConfigurationException { Assert.notNull(delegate, "The ConfigurationConsumer delegate must be supplied"); if (properties == null) { delegate.onReceiveConfiguration(null); return;//from w w w. ja va 2 s. c om } Map configuration = new HashMap(); Enumeration e = properties.keys(); while (e.hasMoreElements()) { Object key = e.nextElement(); configuration.put(key, properties.get(key)); } LOG.info(String.format("Received configuration [%s] for the configurationConsumer with id = [%s] ", configuration.toString(), delegate.getId())); delegate.onReceiveConfiguration(configuration); }