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.opencastproject.loadtest.impl.LoadTest.java

/**
 * Sets a new workflow id to process the media package with.
 * // w w  w  . ja  v a2 s.c  om
 * @param properties
 *          The new properties to extract the property from.
 * @throws InvalidConfigurationException
 *           Thrown if property doesn't exist
 */
@SuppressWarnings("unchecked")
private void updateWorkflowID(Dictionary properties) throws InvalidConfigurationException {
    String newWorkflowID = StringUtils.trimToNull((String) properties.get(WORKFLOW_KEY));
    if (newWorkflowID != null) {
        workflowID = newWorkflowID;
    } else if (componentContext != null && componentContext.getBundleContext() != null) {
        // Use the core address as a default.
        workflowID = componentContext.getBundleContext().getProperty(BUNDLE_CONTEXT_DEFAULT_WORKFLOW);
        if (workflowID == null) {
            workflowID = DEFAULT_WORKFLOW_ID;
            logger.warn(
                    "No workflow id set in {FELIX_HOME}/conf/config.properties or {FELIX_HOME}/conf/services/org.opencastproject.loadtest.impl.LoadTestFactory.properties so default of "
                            + DEFAULT_WORKFLOW_ID + " will be used.");
        }
    }
}

From source file:org.opencastproject.loadtest.impl.LoadTest.java

/**
 * Updates to a new interval in seconds to check the ingest jobs.
 * //  w  ww  . j  a  v a  2  s  .  c o  m
 * @param properties
 *          The new properties to extract the property from.
 * @throws InvalidConfigurationException
 *           Thrown if property doesn't exist
 */
@SuppressWarnings("unchecked")
private void updateJobCheckInterval(Dictionary properties) {
    String jobCheckIntervalInputString = StringUtils
            .trimToNull((String) properties.get(JOB_CHECK_INTERVAL_KEY));
    if (jobCheckIntervalInputString != null) {
        try {
            jobCheckInterval = Integer.parseInt(jobCheckIntervalInputString);
            if (jobCheckInterval < 0) {
                jobCheckInterval *= -1;
            }
            logger.info("Set ingest job check interval to {}", jobCheckInterval);
        } catch (NumberFormatException e) {
            jobCheckInterval = DEFAULT_JOB_CHECK_INTERVAL;
            logger.warn("Can not set job check interval to \"" + jobCheckIntervalInputString + "\". "
                    + JOB_CHECK_INTERVAL_KEY + " must be an integer. It is set to default "
                    + DEFAULT_JOB_CHECK_INTERVAL);
        }
    } else {
        jobCheckInterval = DEFAULT_JOB_CHECK_INTERVAL;
        logger.info("Setting job check interval to default " + DEFAULT_JOB_CHECK_INTERVAL + " seconds.");
    }
}

From source file:org.openhab.binding.velux.internal.VeluxBinding.java

/***
 *** Reconfiguration methods/*ww  w. java2 s. c o m*/
 ***/

@Override
public void updated(final Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("updated() called with {} dictionary entries.", config.size());
    if (config != null) {
        final String protocol = (String) config.get(VeluxBridgeConfiguration.BRIDGE_PROTOCOL);
        if (isNotBlank(protocol)) {
            this.config.bridgeProtocol = protocol;
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_PROTOCOL to {}.", this.config.bridgeProtocol);
        }
        final String ipAddressString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_IPADDRESS);
        if (isNotBlank(ipAddressString)) {
            this.config.bridgeIPAddress = ipAddressString;
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_IPADDRESS to {}.", this.config.bridgeIPAddress);
        }
        final String tcpPortString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_TCPPORT);
        if (isNotBlank(tcpPortString)) {
            try {
                this.config.bridgeTCPPort = Integer.parseInt(tcpPortString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_TCPPORT, e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_TCPPORT to {}.", this.config.bridgeTCPPort);
        }
        final String passwordString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_PASSWORD);
        if (isNotBlank(passwordString)) {
            this.config.bridgePassword = passwordString;
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_PASSWORD to {}.", this.config.bridgePassword);
        }
        final String timeoutMsecsString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS);
        if (isNotBlank(timeoutMsecsString)) {
            try {
                this.config.timeoutMsecs = Integer.parseInt(timeoutMsecsString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS, e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_TIMEOUT_MSECS to {}.", this.config.timeoutMsecs);
        }
        final String retryNoString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_RETRIES);
        if (isNotBlank(retryNoString)) {
            try {
                this.config.retries = Integer.parseInt(retryNoString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_RETRIES, e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_RETRIES to {}.", this.config.retries);
        }
        final String bulkRetrievalString = (String) config
                .get(VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED);
        if (isNotBlank(bulkRetrievalString)) {
            try {
                this.config.isBulkRetrievalEnabled = Boolean.parseBoolean(bulkRetrievalString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED,
                        e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_IS_BULK_RETRIEVAL_ENABLED to {}.",
                    this.config.isBulkRetrievalEnabled);
        }
    }

    setProperlyConfigured(true);

    logger.info("{}Config[{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={}]", VeluxBindingConstants.BINDING_ID,
            VeluxBridgeConfiguration.BRIDGE_PROTOCOL, this.config.bridgeProtocol,
            VeluxBridgeConfiguration.BRIDGE_IPADDRESS, this.config.bridgeIPAddress,
            VeluxBridgeConfiguration.BRIDGE_TCPPORT, this.config.bridgeTCPPort,
            VeluxBridgeConfiguration.BRIDGE_PASSWORD, this.config.bridgePassword.replaceAll(".", "*"),
            VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS, this.config.timeoutMsecs,
            VeluxBridgeConfiguration.BRIDGE_RETRIES, this.config.retries,
            VeluxBridgeConfiguration.BRIDGE_REFRESH_MSECS, this.config.refreshMSecs,
            VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED, this.config.isBulkRetrievalEnabled);

    // Now that we've read ALL the configuration, initialize the binding.
    execute();
}

From source file:org.openhab.binding.mochadx10.internal.MochadX10Binding.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    if (properties != null) {
        String ip = (String) properties.get("hostIp");
        if (StringUtils.isNotBlank(ip)) {
            if (isValidIpAddress(ip)) {
                this.hostIp = ip;
            } else {
                throw new ConfigurationException(hostIp,
                        "The specified hostIp address \"" + ip + "\" is not a valid ip address");
            }//from  w  w  w.j a v  a2s  . c om
        }

        String port = (String) properties.get("hostPort");
        if (StringUtils.isNotBlank(port)) {
            if (isValidPort(port)) {
                this.hostPort = Integer.parseInt(port);
            } else {
                throw new ConfigurationException(port,
                        "The specified port \"" + port + "\" is not a valid port number.");
            }
        }

        initializeBinding();
    }
}

From source file:org.jahia.services.render.scripting.bundle.BundleScriptEngineManager.java

private List<BundleScriptEngineFactory> getScriptEngineFactories(Bundle bundle) throws IOException {
    List<String> factoryCandidates = findFactoryCandidates(bundle);
    if (factoryCandidates.isEmpty()) {
        return null;
    }/*  w  w w.j  ava  2s  . c o m*/

    // check if the bundle defined any view extension priorities
    // todo: add more validation and better specify how this functionality should work
    final Dictionary<String, String> headers = bundle.getHeaders();
    final String extensionsPriorities = headers
            .get(BundleScriptingConfigurationConstants.JAHIA_SCRIPTING_EXTENSIONS_PRIORITIES);
    final Map<String, Integer> extensionsPrioritiesMap;
    if (extensionsPriorities != null) {
        final String[] extensionPriorityPairs = StringUtils.split(extensionsPriorities);
        extensionsPrioritiesMap = new HashMap<>(extensionPriorityPairs.length);
        for (String extensionPriorityPair : extensionPriorityPairs) {
            final String[] extensionPrioritySplit = StringUtils.split(extensionPriorityPair, '=');
            boolean valid = false;
            if (extensionPrioritySplit != null && extensionPrioritySplit.length == 2) {
                try {
                    extensionsPrioritiesMap.put(extensionPrioritySplit[0],
                            Integer.parseInt(extensionPrioritySplit[1]));
                    valid = true;
                } catch (NumberFormatException e) {
                    valid = false;
                }
            }

            if (!valid) {
                logger.warn(
                        "Invalid extension - priority pair: {}. Format is extension=priority, priority should"
                                + " be an integer. Extension will be ignored.",
                        extensionPriorityPair);
            }
        }
    } else {
        extensionsPrioritiesMap = null;
    }

    // retrieve the bundle's class loader
    ClassLoader classLoader = bundle.adapt(BundleWiring.class).getClassLoader();

    final BundleScriptingContext scriptingContext = new BundleScriptingContext(classLoader,
            extensionsPrioritiesMap);

    List<BundleScriptEngineFactory> factories = new ArrayList<>(factoryCandidates.size());
    for (String factoryCandidate : factoryCandidates) {
        final Class<? extends ScriptEngineFactory> factoryClass;
        final ScriptEngineFactory factory;
        final BundleScriptEngineFactory bundleScriptEngineFactory;
        try {
            factoryClass = bundle.loadClass(factoryCandidate).asSubclass(ScriptEngineFactory.class);
            factory = factoryClass.cast(factoryClass.newInstance());
        } catch (ClassNotFoundException e) {
            logger.warn(
                    "ScriptEngineFactory {} was registered to be loaded but no associated class was found in bundle {}. Ignoring"
                            + ".",
                    factoryCandidate, bundle);
            continue;
        } catch (InstantiationException | IllegalAccessException e) {
            logger.warn("Couldn't instantiate ScriptEngineFactory {}. Cause: {}. Ignoring.", factoryCandidate,
                    e.getLocalizedMessage());
            continue;
        } catch (ClassCastException e) {
            logger.warn(
                    "Registered ScriptEngineFactory {} doesn't implement ScriptEngineFactory in bundle {}. Ignoring.",
                    factoryCandidate, bundle);
            continue;
        }

        bundleScriptEngineFactory = new BundleScriptEngineFactory(factory, scriptingContext);
        factories.add(bundleScriptEngineFactory);
    }

    return factories;
}

From source file:apps.core.wcm.components.image.v1.image.Image.java

/**
 * Returns the set of supported widths for adaptive images.
 *
 * @return the set of supported widths for adaptive images
 *
 * @throws Exception// ww  w  . jav  a2 s  .com
 */
public Set<Integer> getSupportedWidths() throws Exception {
    if (supportedWidths != null) {
        return supportedWidths;
    }
    ConfigurationAdmin configurationAdmin = getSlingScriptHelper().getService(ConfigurationAdmin.class);
    String filter = String.format("(service.pid=%s)", ADAPTIVE_IMAGE_SERVLET_PID);
    Configuration[] configurations = configurationAdmin.listConfigurations(filter);
    if (configurations != null) {
        for (Configuration config : configurations) {
            Dictionary properties = config.getProperties();
            if (properties != null) {
                String[] widths = PropertiesUtil
                        .toStringArray(properties.get(ADAPTIVE_IMAGE_SERVLET_WIDTH_CONF), null);
                if (widths != null) {
                    supportedWidths = new HashSet<>();
                    for (String strWidth : widths) {
                        try {
                            supportedWidths.add(Integer.valueOf(strWidth));
                        } catch (NumberFormatException e) {
                            LOGGER.error("Invalid number format for supported with: {}", strWidth);
                        }
                    }
                }
                return supportedWidths;
            }
        }
    }
    supportedWidths = DEFAULT_SUPPORTED_WIDTHS;
    return supportedWidths;
}

From source file:org.opencastproject.workflow.handler.textanalyzer.TextAnalysisWorkflowOperationHandler.java

/**
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 *//*  w  w  w.  j a  v  a2s  .  c  o m*/
@SuppressWarnings("rawtypes")
@Override
public void updated(Dictionary properties) throws ConfigurationException {
    if (properties != null && properties.get(OPT_STABILITY_THRESHOLD) != null) {
        String threshold = StringUtils.trimToNull((String) properties.get(OPT_STABILITY_THRESHOLD));
        try {
            stabilityThreshold = Integer.parseInt(threshold);
            logger.info("The videosegmenter's stability threshold has been set to {} frames",
                    stabilityThreshold);
        } catch (Exception e) {
            stabilityThreshold = DEFAULT_STABILITY_THRESHOLD;
            logger.warn(
                    "Found illegal value '{}' for the videosegmenter stability threshold. Falling back to default value of {} frames",
                    threshold, DEFAULT_STABILITY_THRESHOLD);
        }
    } else {
        stabilityThreshold = DEFAULT_STABILITY_THRESHOLD;
        logger.warn("Using the default value of {} frames for the videosegmenter stability threshold",
                DEFAULT_STABILITY_THRESHOLD);
    }
}

From source file:org.openhab.binding.opensprinkler.internal.OpenSprinklerBinding.java

/**
 * @{inheritDoc}//w  w  w .j a v a2  s.  c o  m
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        // to override the mode (gpio or http) one has to add a 
        // parameter to openhab.cfg like openSprinkler:mode=[gpio|http]
        String modeString = (String) config.get("mode");
        if (StringUtils.isNotBlank(modeString)) {
            try {
                mode = OpenSprinklerMode.valueOf(modeString.toUpperCase());
            } catch (IllegalArgumentException iae) {
                throw new ConfigurationException("openSprinkler:mode", "Unknown OpenSprinkler mode " + mode
                        + "! Valid modes are 'gpio' and 'http'. Please fix your openhab.cfg.");
            }
        }

        // to specify the http url one has to add a 
        // parameter to openhab.cfg like openSprinkler:httpUrl=<url>
        url = (String) config.get("httpUrl");

        // to specify the http password one has to add a 
        // parameter to openhab.cfg like openSprinkler:httpPassword=<password>
        password = (String) config.get("httpPassword");

        // to override the refresh rate of the rain sensor check one has to add a
        // parameter to openhab.cfg like openSprinkler:rsRefresh
        String rsRefreshRate = (String) config.get("refreshInterval");
        if (StringUtils.isNotBlank(rsRefreshRate)) {
            refreshInterval = Long.parseLong(rsRefreshRate);
        }

        // to override the number of stations one has to add a 
        // parameter to openhab.cfg like openSprinkler:numberOfStations=<count>
        String numberOfStationsString = (String) config.get("numberOfStations");
        if (StringUtils.isNotBlank(numberOfStationsString)) {
            if (Arrays.asList(VALID_STATION_NUMBER_LIST).contains(numberOfStationsString)) {
                numberOfStations = Integer.parseInt(numberOfStationsString);
            } else {
                logger.warn(numberOfStationsString
                        + " is not a valid number of stations OpenSprinkler supports. Defaulting to 8.");
            }
        }

        // read further config parameters here ...

        setProperlyConfigured(true);

        // then update the binding
        updateBinding();
    }
}

From source file:org.openhab.binding.envisalink3.internal.Envisalink3Binding.java

/**
 * @{inheritDoc}//from  w ww  .j av a2 s  .  co m
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Envisalink3 updated() method is called!");

    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 hostConfig = (String) config.get("host");
        if (StringUtils.isNotBlank(hostConfig)) {
            logger.info("Setting Envisalink3 host=" + (String) hostConfig);
            ipAddress = hostConfig;
        }

        String hostPort = (String) config.get("port");
        if (StringUtils.isNotBlank(hostPort)) {
            logger.info("Setting Envisalink3 port=" + (String) hostPort);
            ipPort = Integer.parseInt(hostPort);
        }

        // Start the listener
        listen();

        logger.info("Attempting to set all zones to closed state initially");
        for (Envisalink3BindingProvider provider : providers) {
            for (int i = 1; i <= 16; i++) {
                for (String itemName : provider.getBindingItemsAtZone(i)) {
                    switch (provider.getFunction(itemName)) {
                    case STATUS:
                        logger.info("Setting {} to CLOSED", itemName);
                        eventPublisher.postUpdate(itemName, (State) OpenClosedType.CLOSED);
                        break;
                    case BYPASS:
                        break;
                    default:
                        break;
                    }
                }
            }
        }

        setProperlyConfigured(true);
    } else {
        logger.debug("Envisalink3 config is null");
    }

}

From source file:org.codice.ddf.configuration.admin.ConfigurationAdminMigratableTest.java

private Map<String, Object> convertToMap(Dictionary<String, ?> dictionary) {
    Map<String, Object> map = new HashMap<>();
    Enumeration<String> keys = dictionary.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        map.put(key, dictionary.get(key));
    }/* ww w  . java  2s . co  m*/
    return map;
}