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.apache.felix.webconsole.internal.core.BundlesServlet.java

private void listImportExportsUnresolved(JSONWriter jsonWriter, Bundle bundle) throws JSONException {
    Dictionary dictHeader = bundle.getHeaders();

    String exportPkg = (String) dictHeader.get(Constants.EXPORT_PACKAGE);
    if (exportPkg != null) {
        R4Package[] pkgs = R4Package.parseImportOrExportHeader(exportPkg);
        if (pkgs != null && pkgs.length > 0) {
            // do alphabetical sort
            Arrays.sort(pkgs, new Comparator() {
                public int compare(Object o1, Object o2) {
                    return compare((R4Package) o1, (R4Package) o2);
                }//from   w ww  .j  a  v  a2 s .c o  m

                public int compare(R4Package p1, R4Package p2) {
                    return p1.getName().compareTo(p2.getName());
                }
            });

            JSONArray val = new JSONArray();
            for (int i = 0; i < pkgs.length; i++) {
                R4Export export = new R4Export(pkgs[i]);
                getDelegationInfo(val, export.getName(), export.getVersion());
            }
            jsonKeyVal(jsonWriter, "Exported Packages", val);
        } else {
            jsonKeyVal(jsonWriter, "Exported Packages", "None");
        }
    }

    exportPkg = (String) dictHeader.get(Constants.IMPORT_PACKAGE);
    if (exportPkg != null) {
        R4Package[] pkgs = R4Package.parseImportOrExportHeader(exportPkg);
        if (pkgs != null && pkgs.length > 0) {
            Map imports = new TreeMap();
            for (int i = 0; i < pkgs.length; i++) {
                R4Package pkg = pkgs[i];
                imports.put(pkg.getName(), new R4Import(pkg));
            }

            // collect import packages first
            final Map candidates = new HashMap();
            PackageAdmin packageAdmin = getPackageAdmin();
            if (packageAdmin != null) {
                ExportedPackage[] exports = packageAdmin.getExportedPackages((Bundle) null);
                if (exports != null && exports.length > 0) {

                    for (int i = 0; i < exports.length; i++) {
                        final ExportedPackage ep = exports[i];

                        R4Import imp = (R4Import) imports.get(ep.getName());
                        if (imp != null && imp.isSatisfied(toR4Export(ep))) {
                            candidates.put(ep.getName(), ep);
                        }
                    }
                }
            }

            // now sort
            JSONArray importArray = new JSONArray();
            if (imports.size() > 0) {
                for (Iterator importsIter = imports.values().iterator(); importsIter.hasNext();) {
                    R4Import r4Import = (R4Import) importsIter.next();
                    ExportedPackage ep = (ExportedPackage) candidates.get(r4Import.getName());

                    // if there is no matching export, check whether this
                    // bundle has the package, ignore the entry in this case
                    if (ep == null) {
                        String path = r4Import.getName().replace('.', '/');
                        if (bundle.getResource(path) != null) {
                            continue;
                        }
                    }

                    collectImport(importArray, r4Import.getName(), r4Import.getVersion(), r4Import.isOptional(),
                            ep);
                }
            } else {
                // add description if there are no imports
                importArray.put("None");
            }

            jsonKeyVal(jsonWriter, "Imported Packages", importArray);
        }
    }
}

From source file:org.openhab.binding.ebus.EBusBinding.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {

    logger.info("Update eBus Binding configuration ...");

    try {/*from w  ww  . j  a va 2  s .  co m*/
        // stop last thread if active
        if (connector != null && connector.isAlive()) {
            connector.interrupt();
        }

        // check to ensure that it is available
        checkConfigurationProvider();

        // clear current configuration
        configurationProvider.clear();

        // load parser from default url
        parser = new EBusTelegramParser(configurationProvider);

        URL configurationUrl = null;
        String parsers = (String) properties.get("parsers");

        if (StringUtils.isEmpty(parsers)) {
            // set to current stable configurations as default
            parsers = "common,wolf";
        }

        for (String elem : parsers.split(",")) {
            configurationUrl = null;

            // check for keyword custom to load custom configuration
            if (elem.trim().equals("custom")) {
                String parserUrl = (String) properties.get("parserUrl");
                if (parserUrl != null) {
                    logger.debug("Load custom eBus Parser with url {}", parserUrl);
                    configurationUrl = new URL(parserUrl);
                }

            } else {
                logger.debug("Load eBus Parser Configuration \"{}\" ...", elem.trim());
                configurationUrl = this.getClass()
                        .getResource("/META-INF/" + elem.trim() + "-configuration.json");
            }

            if (configurationUrl != null) {
                configurationProvider.loadConfigurationFile(configurationUrl);
            }
        }

        // check minimal config
        if (properties.get("serialPort") != null && properties.get("hostname") != null) {
            throw new ConfigurationException("hostname", "Set property serialPort or hostname, not both!");
        }

        if (StringUtils.isNotEmpty((String) properties.get("serialPort"))) {

            // use the serial connector
            connector = new EBusSerialConnector((String) properties.get("serialPort"));

        } else if (StringUtils.isNotEmpty((String) properties.get("hostname"))) {

            // use the tcp-ip connector
            connector = new EBusTCPConnector((String) properties.get("hostname"),
                    Integer.parseInt((String) properties.get("port")));
        }

        // Set eBus sender id or default 0xFF
        if (StringUtils.isNotEmpty((String) properties.get("senderId"))) {
            connector.setSenderId(EBusUtils.toByte((String) properties.get("senderId")));
        }

        // add event listener
        connector.addEBusEventListener(this);

        // start thread
        connector.start();

        // set the new connector
        commandProcessor.setConnector(connector);
        commandProcessor.setConfigurationProvider(configurationProvider);

    } catch (MalformedURLException e) {
        logger.error(e.toString(), e);
    } catch (IOException e) {
        throw new ConfigurationException("general", e.toString(), e);
    }
}

From source file:org.openhab.io.transport.mqtt.MqttService.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {

    // load broker configurations from configuration file
    if (properties == null || properties.isEmpty()) {
        return;/*  w  ww.  j a v a2 s  .  c  om*/
    }

    Enumeration<String> keys = properties.keys();
    while (keys.hasMoreElements()) {

        String key = keys.nextElement();

        if (key.equals("service.pid")) {
            // ignore the only non-broker property..
            continue;
        }

        String[] subkeys = key.split("\\.");
        if (subkeys.length != 2) {
            logger.debug("MQTT Broker property '{}' should have the format 'broker.propertykey'", key);
            continue;
        }

        String value = (String) properties.get(key);
        String name = subkeys[0].toLowerCase();
        String property = subkeys[1];

        if (StringUtils.isBlank(value)) {
            logger.trace("Property is empty: {}", key);
            continue;
        } else {
            logger.trace("Processing property: {} = {}", key, value);
        }

        MqttBrokerConnection conn = brokerConnections.get(name);
        if (conn == null) {
            conn = new MqttBrokerConnection(name);
            brokerConnections.put(name, conn);
        }

        if (property.equals("url")) {
            conn.setUrl(value);
        } else if (property.equals("user")) {
            conn.setUser(value);
        } else if (property.equals("pwd")) {
            conn.setPassword(value);
        } else if (property.equals("qos")) {
            conn.setQos(Integer.parseInt(value));
        } else if (property.equals("retain")) {
            conn.setRetain(Boolean.parseBoolean(value));
        } else if (property.equals("async")) {
            conn.setAsync(Boolean.parseBoolean(value));
        } else if (property.equals("clientId")) {
            conn.setClientId(value);
        } else if (property.equals("lwt")) {
            MqttWillAndTestament will = MqttWillAndTestament.fromString(value);
            logger.debug("Setting last will: {}", will);
            conn.setLastWill(will);
        } else if (property.equals("keepAlive")) {
            conn.setKeepAliveInterval(Integer.parseInt(value));
        } else {
            logger.warn("Unrecognized property: {}", key);
        }
    }
    logger.info("MQTT Service initialization completed.");

    for (MqttBrokerConnection con : brokerConnections.values()) {
        try {
            con.start();
        } catch (Exception e) {
            logger.error("Error starting broker connection", e);
        }
    }
}

From source file:org.openhab.io.dropbox.internal.DropboxSynchronizerImpl.java

@SuppressWarnings("rawtypes")
@Override// ww  w  . ja va  2  s .c  om
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        isProperlyConfigured = false;

        String appKeyString = (String) config.get("appkey");
        if (isNotBlank(appKeyString)) {
            DropboxSynchronizerImpl.appKey = appKeyString;
        }

        String appSecretString = (String) config.get("appsecret");
        if (isNotBlank(appSecretString)) {
            DropboxSynchronizerImpl.appSecret = appSecretString;
        }

        if (isBlank(DropboxSynchronizerImpl.appKey) || isBlank(DropboxSynchronizerImpl.appSecret)) {
            throw new ConfigurationException("dropbox:appkey",
                    "The parameters 'appkey' or 'appsecret' are missing! Please refer to your 'openhab.cfg'");
        }

        String initializeString = (String) config.get("initialize");
        if (isNotBlank(initializeString)) {
            DropboxSynchronizerImpl.initializeDropboxOnReset = BooleanUtils.toBoolean(initializeString);
        }

        String contentDirString = (String) config.get("contentdir");
        if (isNotBlank(contentDirString)) {
            DropboxSynchronizerImpl.contentDir = contentDirString;
        }

        String uploadIntervalString = (String) config.get("uploadInterval");
        if (isNotBlank(uploadIntervalString)) {
            DropboxSynchronizerImpl.uploadInterval = uploadIntervalString;
        }

        String downloadIntervalString = (String) config.get("downloadInterval");
        if (isNotBlank(downloadIntervalString)) {
            DropboxSynchronizerImpl.downloadInterval = downloadIntervalString;
        }

        String syncModeString = (String) config.get("syncmode");
        if (isNotBlank(syncModeString)) {
            try {
                DropboxSynchronizerImpl.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 = (String) config.get("uploadfilter");
        if (isNotBlank(uploadFilterString)) {
            String[] newFilterElements = uploadFilterString.split(",");
            uploadFilterElements.addAll(Arrays.asList(newFilterElements));
        }

        String downloadFilterString = (String) config.get("downloadfilter");
        if (isNotBlank(downloadFilterString)) {
            String[] newFilterElements = downloadFilterString.split(",");
            downloadFilterElements.addAll(Arrays.asList(newFilterElements));
        }

        // we got thus far, so we define this synchronizer as properly configured ...
        isProperlyConfigured = true;
        activate();
    }
}

From source file:org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator.java

/**
 * Activates this component (called by SCR before)
 *//*  w w  w  . j a va  2  s .  c  om*/
@Activate
protected void activate(final ComponentContext componentContext) {
    this.componentContext = componentContext;
    final Dictionary<?, ?> properties = componentContext.getProperties();

    final BidiMap virtuals = new TreeBidiMap();
    final String[] virtualList = PropertiesUtil.toStringArray(properties.get(PROP_VIRTUAL));
    for (int i = 0; virtualList != null && i < virtualList.length; i++) {
        final String[] parts = Mapping.split(virtualList[i]);
        virtuals.put(parts[0], parts[2]);
    }
    virtualURLMap = virtuals;

    final List<Mapping> maps = new ArrayList<Mapping>();
    final String[] mappingList = (String[]) properties.get(PROP_MAPPING);
    for (int i = 0; mappingList != null && i < mappingList.length; i++) {
        maps.add(new Mapping(mappingList[i]));
    }
    final Mapping[] tmp = maps.toArray(new Mapping[maps.size()]);

    // check whether direct mappings are allowed
    final Boolean directProp = (Boolean) properties.get(PROP_ALLOW_DIRECT);
    allowDirect = (directProp != null) ? directProp.booleanValue() : true;
    if (allowDirect) {
        final Mapping[] tmp2 = new Mapping[tmp.length + 1];
        tmp2[0] = Mapping.DIRECT;
        System.arraycopy(tmp, 0, tmp2, 1, tmp.length);
        mappings = tmp2;
    } else {
        mappings = tmp;
    }

    // from configuration if available
    searchPath = PropertiesUtil.toStringArray(properties.get(PROP_PATH));
    if (searchPath != null && searchPath.length > 0) {
        for (int i = 0; i < searchPath.length; i++) {
            // ensure leading slash
            if (!searchPath[i].startsWith("/")) {
                searchPath[i] = "/" + searchPath[i];
            }
            // ensure trailing slash
            if (!searchPath[i].endsWith("/")) {
                searchPath[i] += "/";
            }
        }
    }
    if (searchPath == null) {
        searchPath = new String[] { "/" };
    }
    // namespace mangling
    mangleNamespacePrefixes = PropertiesUtil.toBoolean(properties.get(PROP_MANGLE_NAMESPACES), false);

    // the root of the resolver mappings
    mapRoot = PropertiesUtil.toString(properties.get(PROP_MAP_LOCATION), MapEntries.DEFAULT_MAP_ROOT);

    defaultVanityPathRedirectStatus = PropertiesUtil.toInteger(
            properties.get(PROP_DEFAULT_VANITY_PATH_REDIRECT_STATUS),
            MapEntries.DEFAULT_DEFAULT_VANITY_PATH_REDIRECT_STATUS);
    this.enableVanityPath = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_VANITY_PATH),
            DEFAULT_ENABLE_VANITY_PATH);
    // vanity path white list
    this.vanityPathWhiteList = null;
    String[] vanityPathPrefixes = PropertiesUtil.toStringArray(properties.get(PROP_ALLOWED_VANITY_PATH_PREFIX));
    if (vanityPathPrefixes != null) {
        final List<String> prefixList = new ArrayList<String>();
        for (final String value : vanityPathPrefixes) {
            if (value.trim().length() > 0) {
                if (value.trim().endsWith("/")) {
                    prefixList.add(value.trim());
                } else {
                    prefixList.add(value.trim() + "/");
                }
            }
        }
        if (prefixList.size() > 0) {
            this.vanityPathWhiteList = prefixList.toArray(new String[prefixList.size()]);
        }
    }
    // vanity path black list
    this.vanityPathBlackList = null;
    vanityPathPrefixes = PropertiesUtil.toStringArray(properties.get(PROP_DENIED_VANITY_PATH_PREFIX));
    if (vanityPathPrefixes != null) {
        final List<String> prefixList = new ArrayList<String>();
        for (final String value : vanityPathPrefixes) {
            if (value.trim().length() > 0) {
                if (value.trim().endsWith("/")) {
                    prefixList.add(value.trim());
                } else {
                    prefixList.add(value.trim() + "/");
                }
            }
        }
        if (prefixList.size() > 0) {
            this.vanityPathBlackList = prefixList.toArray(new String[prefixList.size()]);
        }
    }

    this.enableOptimizeAliasResolution = PropertiesUtil.toBoolean(
            properties.get(PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION), DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION);
    this.maxCachedVanityPathEntries = PropertiesUtil.toLong(properties.get(PROP_MAX_CACHED_VANITY_PATHS),
            DEFAULT_MAX_CACHED_VANITY_PATHS);
    this.maxCachedVanityPathEntriesStartup = PropertiesUtil.toBoolean(
            properties.get(PROP_MAX_CACHED_VANITY_PATHS_STARTUP), DEFAULT_MAX_CACHED_VANITY_PATHS_STARTUP);
    this.vanityBloomFilterMaxBytes = PropertiesUtil.toInteger(
            properties.get(PROP_VANITY_BLOOM_FILTER_MAX_BYTES), DEFAULT_VANITY_BLOOM_FILTER_MAX_BYTES);

    this.vanityPathPrecedence = PropertiesUtil.toBoolean(properties.get(PROP_VANITY_PATH_PRECEDENCE),
            DEFAULT_VANITY_PATH_PRECEDENCE);
    this.logResourceResolverClosing = PropertiesUtil.toBoolean(
            properties.get(PROP_LOG_RESOURCE_RESOLVER_CLOSING), DEFAULT_LOG_RESOURCE_RESOLVER_CLOSING);
    this.paranoidProviderHandling = PropertiesUtil.toBoolean(properties.get(PROP_PARANOID_PROVIDER_HANDLING),
            DEFAULT_PARANOID_PROVIDER_HANDLING);

    final BundleContext bc = componentContext.getBundleContext();

    // check for required property
    final String[] requiredResourceProvidersLegacy = PropertiesUtil
            .toStringArray(properties.get(PROP_REQUIRED_PROVIDERS_LEGACY));
    final String[] requiredResourceProviderNames = PropertiesUtil
            .toStringArray(properties.get(PROP_REQUIRED_PROVIDERS));

    if (requiredResourceProvidersLegacy != null && requiredResourceProvidersLegacy.length > 0) {
        boolean hasRealValue = false;
        for (final String name : requiredResourceProvidersLegacy) {
            if (name != null && !name.trim().isEmpty()) {
                hasRealValue = true;
                break;
            }
        }
        if (hasRealValue) {
            logger.error("ResourceResolverFactory is using deprecated required providers configuration ("
                    + PROP_REQUIRED_PROVIDERS_LEGACY + "). Please change to use the property "
                    + PROP_REQUIRED_PROVIDERS + " for values: "
                    + Arrays.toString(requiredResourceProvidersLegacy));
        }
    }
    // for testing: if we run unit test, both trackers are set from the outside
    if (this.resourceProviderTracker == null) {
        this.resourceProviderTracker = new ResourceProviderTracker();
        this.changeListenerWhiteboard = new ResourceChangeListenerWhiteboard();
        this.preconds.activate(bc, requiredResourceProvidersLegacy, requiredResourceProviderNames,
                resourceProviderTracker);
        this.changeListenerWhiteboard.activate(this.componentContext.getBundleContext(),
                this.resourceProviderTracker, searchPath);
        this.resourceProviderTracker.activate(this.componentContext.getBundleContext(), this.eventAdmin,
                new ChangeListener() {

                    @Override
                    public void providerAdded() {
                        if (factoryRegistration == null) {
                            checkFactoryPreconditions(null, null);
                        }

                    }

                    @Override
                    public void providerRemoved(final String name, final String pid, final boolean stateful,
                            final boolean isUsed) {
                        if (factoryRegistration != null) {
                            if (isUsed && (stateful || paranoidProviderHandling)) {
                                unregisterFactory();
                            }
                            checkFactoryPreconditions(name, pid);
                        }
                    }
                });
    } else {
        this.preconds.activate(bc, requiredResourceProvidersLegacy, requiredResourceProviderNames,
                resourceProviderTracker);
        this.checkFactoryPreconditions(null, null);
    }
}

From source file:org.openhab.binding.ebus.internal.EBusBinding.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {

    logger.info("Update eBus Binding configuration ...");

    try {// w ww. java 2  s.c o m
        // stop last thread if active
        if (connector != null && connector.isAlive()) {
            connector.interrupt();
        }

        // check to ensure that it is available
        checkConfigurationProvider();

        // clear current configuration
        configurationProvider.clear();

        // load parser from default url
        parser = new EBusTelegramParser(configurationProvider);

        URL configurationUrl = null;
        String parsers = (String) properties.get("parsers");

        if (StringUtils.isEmpty(parsers)) {
            // set to current stable configurations as default
            parsers = "common,wolf";
        }

        for (String elem : parsers.split(",")) {
            configurationUrl = null;

            // check for keyword custom to load custom configuration
            if (elem.trim().equals("custom")) {
                String parserUrl = (String) properties.get("parserUrl");
                if (parserUrl != null) {
                    logger.debug("Load custom eBus Parser with url {}", parserUrl);
                    configurationUrl = new URL(parserUrl);
                }

            } else {
                logger.debug("Load eBus Parser Configuration \"{}\" ...", elem.trim());
                configurationUrl = this.getClass().getResource("/" + elem.trim() + "-configuration.json");
            }

            if (configurationUrl != null) {
                configurationProvider.loadConfigurationFile(configurationUrl);
            }
        }

        // check minimal config
        if (properties.get("serialPort") != null && properties.get("hostname") != null) {
            throw new ConfigurationException("hostname", "Set property serialPort or hostname, not both!");
        }

        if (StringUtils.isNotEmpty((String) properties.get("serialPort"))) {

            // use the serial connector
            connector = new EBusSerialConnector((String) properties.get("serialPort"));

        } else if (StringUtils.isNotEmpty((String) properties.get("hostname"))) {

            // use the tcp-ip connector
            connector = new EBusTCPConnector((String) properties.get("hostname"),
                    Integer.parseInt((String) properties.get("port")));
        }

        // Set eBus sender id or default 0xFF
        if (StringUtils.isNotEmpty((String) properties.get("senderId"))) {
            connector.setSenderId(EBusUtils.toByte((String) properties.get("senderId")));
        }

        // add event listener
        connector.addEBusEventListener(this);

        // start thread
        connector.start();

        // set the new connector
        commandProcessor.setConnector(connector);
        commandProcessor.setConfigurationProvider(configurationProvider);

    } catch (MalformedURLException e) {
        logger.error(e.toString(), e);
    } catch (IOException e) {
        throw new ConfigurationException("general", e.toString(), e);
    }
}

From source file:net.wasdev.wlp.netflixoss.archaius.Activator.java

private Set<String> generateKeyVals(ConfigurationAdmin configAdmin, String key, String[] values)
        throws IOException {

    Set<String> keys = new HashSet<String>();

    for (String value : values) {

        Configuration config = configAdmin.getConfiguration(value);
        Dictionary valueProps = config.getProperties();

        if (valueProps == null) {
            if (configuration.containsKey(key)) {
                if (!configuration.getProperty(key).equals(value)) {
                    LOGGER.fine("Updating key \'" + key + "\' to value \'" + value + "\'");
                    configuration.setProperty(key, value);
                }//w w w .j a va 2  s  .c o m
            } else {
                LOGGER.fine("Adding key \'" + key + "\' with value \'" + value + "\'");
                configuration.addProperty(key, value);
            }
            keys.add(key);
        } else {
            Enumeration<String> valuePropKeys = valueProps.keys();
            while (valuePropKeys.hasMoreElements()) {
                String valuePropKey = valuePropKeys.nextElement();
                Object valuePropValue = valueProps.get(valuePropKey);
                if (valuePropValue instanceof String[]) {
                    keys.addAll(
                            generateKeyVals(configAdmin, key + "." + valuePropKey, (String[]) valuePropValue));
                }
            }
        }

    }

    return keys;

}

From source file:org.opendaylight.controller.cluster.datastore.DatastoreContextIntrospector.java

/**
 * Applies the given properties to the cached DatastoreContext and yields a new DatastoreContext
 * instance which can be obtained via {@link getContext}.
 *
 * @param properties the properties to apply
 * @return true if the cached DatastoreContext was updated, false otherwise.
 *///from   w  ww  .  jav  a  2 s  .c  om
public synchronized boolean update(Dictionary<String, Object> properties) {
    currentProperties = null;
    if (properties == null || properties.isEmpty()) {
        return false;
    }

    LOG.debug("In update: properties: {}", properties);

    ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.<String, Object>builder();

    Builder builder = DatastoreContext.newBuilderFrom(context);

    final String dataStoreTypePrefix = context.getDataStoreName() + '.';

    List<String> keys = getSortedKeysByDatastoreType(Collections.list(properties.keys()), dataStoreTypePrefix);

    boolean updated = false;
    for (String key : keys) {
        Object value = properties.get(key);
        mapBuilder.put(key, value);

        // If the key is prefixed with the data store type, strip it off.
        if (key.startsWith(dataStoreTypePrefix)) {
            key = key.replaceFirst(dataStoreTypePrefix, "");
        }

        if (convertValueAndInvokeSetter(key, value, builder)) {
            updated = true;
        }
    }

    currentProperties = mapBuilder.build();

    if (updated) {
        context = builder.build();
    }

    return updated;
}

From source file:ch.entwine.weblounge.kernel.site.SiteDispatcherServiceImpl.java

/**
 * Configures this service using the given configuration properties.
 * //from ww w .ja v  a2 s .  co  m
 * @param config
 *          the service configuration
 * @throws ConfigurationException
 *           if configuration fails
 */
private boolean configure(Dictionary<?, ?> config) throws ConfigurationException {

    logger.debug("Configuring the site registration service");
    boolean configurationChanged = true;

    // Activate precompilation?
    String precompileSetting = StringUtils.trimToNull((String) config.get(OPT_PRECOMPILE));
    precompile = precompileSetting == null || ConfigurationUtils.isTrue(precompileSetting);
    logger.debug("Jsp precompilation {}", precompile ? "activated" : "deactivated");

    // Log compilation errors?
    String logPrecompileErrors = StringUtils.trimToNull((String) config.get(OPT_PRECOMPILE_LOGGING));
    logCompileErrors = logPrecompileErrors != null && ConfigurationUtils.isTrue(logPrecompileErrors);
    logger.debug("Precompilation errors will {} logged", logCompileErrors ? "be" : "not be");

    // Store the jasper configuration keys
    Enumeration<?> keys = config.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        if (key.startsWith(OPT_JASPER_PREFIX) && key.length() > OPT_JASPER_PREFIX.length()) {
            String value = (String) config.get(key);
            if (StringUtils.trimToNull(value) == null)
                continue;
            value = ConfigurationUtils.processTemplate(value);
            key = key.substring(OPT_JASPER_PREFIX.length());

            boolean optionChanged = value.equalsIgnoreCase(jasperConfig.get(key));
            configurationChanged |= !optionChanged;
            if (optionChanged)
                logger.debug("Jetty jsp parameter '{}' configured to '{}'", key, value);

            jasperConfig.put(key, value);
            // This is a work around for jasper's horrible implementation of the
            // compiler context configuration. Some keys are camel case, others are
            // lower case.
            jasperConfig.put(key.toLowerCase(), value);
        }
    }

    return configurationChanged;
}

From source file:org.apache.felix.webconsole.internal.servlet.OsgiManager.java

synchronized void updateConfiguration(Dictionary config) {
    if (config == null) {
        config = new Hashtable();
    }/*from   w w  w . j  a  va 2s. co  m*/

    configuration = config;

    final Object locale = config.get(PROP_LOCALE);
    configuredLocale = locale == null || locale.toString().trim().length() == 0 //
            ? null
            : Util.parseLocaleString(locale.toString().trim());

    logLevel = getProperty(config, PROP_LOG_LEVEL, DEFAULT_LOG_LEVEL);
    AbstractWebConsolePlugin.setLogLevel(logLevel);

    // default plugin page configuration
    holder.setDefaultPluginLabel(getProperty(config, PROP_DEFAULT_RENDER, DEFAULT_PAGE));

    // get the web manager root path
    String newWebManagerRoot = this.getProperty(config, PROP_MANAGER_ROOT, DEFAULT_MANAGER_ROOT);
    if (!newWebManagerRoot.startsWith("/")) {
        newWebManagerRoot = "/" + newWebManagerRoot;
    }

    // get the HTTP Service selector (and dispose tracker for later
    // recreation)
    final String newHttpServiceSelector = getProperty(config, PROP_HTTP_SERVICE_SELECTOR,
            DEFAULT_HTTP_SERVICE_SELECTOR);
    if (httpServiceTracker != null && !httpServiceTracker.isSameSelector(newHttpServiceSelector)) {
        httpServiceTracker.close();
        httpServiceTracker = null;
    }

    // get enabled plugins
    Object pluginValue = config.get(PROP_ENABLED_PLUGINS);
    if (pluginValue == null) {
        enabledPlugins = null;
    } else if (pluginValue.getClass().isArray()) {
        final Object[] names = (Object[]) pluginValue;
        enabledPlugins = new HashSet();
        for (int i = 0; i < names.length; i++) {
            enabledPlugins.add(String.valueOf(names[i]));
        }
    } else if (pluginValue instanceof Collection) {
        enabledPlugins = new HashSet();
        enabledPlugins.addAll((Collection) pluginValue);
    }

    // might update http service registration
    HttpService httpService = this.httpService;
    if (httpService != null) {
        // unbind old location first
        unbindHttpService(httpService);

        // switch location
        this.webManagerRoot = newWebManagerRoot;

        // bind new location now
        bindHttpService(httpService);
    } else {
        // just set the configured location (FELIX-2034)
        this.webManagerRoot = newWebManagerRoot;
    }

    // create or recreate the HTTP service tracker with the new selector
    if (httpServiceTracker == null) {
        httpServiceTracker = HttpServiceTracker.create(this, newHttpServiceSelector);
        httpServiceTracker.open();
    }
}