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.openhab.action.mail.internal.MailActionService.java

@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        Mail.hostname = (String) config.get("hostname");

        String portString = (String) config.get("port");
        if (portString != null) {
            Mail.port = Integer.valueOf(portString);
        }// w  ww  . j  ava 2s .com

        Mail.username = (String) config.get("username");
        Mail.password = (String) config.get("password");
        Mail.from = (String) config.get("from");

        String tlsString = (String) config.get("tls");
        if (StringUtils.isNotBlank(tlsString)) {
            Mail.tls = tlsString.equalsIgnoreCase("true");
        }
        String popBeforeSmtpString = (String) config.get("popbeforesmtp");
        if (StringUtils.isNotBlank(popBeforeSmtpString)) {
            Mail.popBeforeSmtp = popBeforeSmtpString.equalsIgnoreCase("true");
        }

        Mail.charset = (String) config.get("charset");

        // check mandatory settings
        if (StringUtils.isBlank(Mail.hostname) || StringUtils.isBlank(Mail.from)) {
            throw new ConfigurationException("mail",
                    "Parameters mail:hostname and mail:from are mandatory and must be configured. Please check your openhab.cfg!");
        }

        // set defaults for optional settings
        if (Mail.port == null) {
            Mail.port = Mail.tls ? 587 : 25;
        }

        isProperlyConfigured = true;
    }
}

From source file:io.wcm.devops.conga.plugins.sling.postprocessor.ProvisioningOsgiConfigPostProcessorTest.java

@Test
public void testProvisioningExample() throws Exception {

    // post process example valid provisioning file
    File provisioningFile = new File(targetDir, "provisioningExample.txt");
    FileUtils.copyFile(new File(getClass().getResource("/validProvisioning.txt").toURI()), provisioningFile);
    postProcess(provisioningFile);/*w w w .  ja v  a2  s .com*/

    // validate generated configs
    Dictionary<?, ?> config = readConfig("my.pid.config");
    assertEquals("value1", config.get("stringProperty"));
    assertArrayEquals(new String[] { "v1", "v2", "v3" }, (String[]) config.get("stringArrayProperty"));
    assertEquals(true, config.get("booleanProperty"));
    assertEquals(999999999999L, config.get("longProperty"));

    assertExists("my.factory-my.pid.config");
    assertExists("mode1/my.factory-my.pid2.config");
    assertExists("mode2/my.pid2.config");
}

From source file:org.opencastproject.textextractor.tesseract.TesseractTextExtractor.java

@Override
@SuppressWarnings("unchecked")
public void updated(Dictionary properties) throws ConfigurationException {
    String path = (String) properties.get(TESSERACT_BINARY_CONFIG_KEY);
    if (path != null) {
        logger.info("Setting Tesseract path to {}", path);
        this.binary = path;
    }//from w w w  . j  a v  a 2 s  .c  o m
}

From source file:ch.entwine.weblounge.aws.AmazonWebServices.java

/**
 * {@inheritDoc}//from ww w. j a  v  a  2s .co  m
 * 
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 */
@SuppressWarnings("rawtypes")
public void updated(Dictionary properties) throws ConfigurationException {

    // Read the access key id
    accessKeyId = (String) properties.get(OPT_ACCESS_KEY_ID);
    if (StringUtils.isBlank(accessKeyId))
        throw new ConfigurationException(OPT_ACCESS_KEY_ID, "not set");
    logger.debug("Amazon access key id is '{}'", accessKeyId);

    // Read the access key secret
    accessKeySecret = (String) properties.get(OPT_ACCESS_KEY_SECRET);
    if (StringUtils.isBlank(accessKeySecret))
        throw new ConfigurationException(OPT_ACCESS_KEY_SECRET, "not set");
    logger.debug("Amazon access key secret is '{}'", accessKeySecret);

    // Create the credentials
    accessCredentials = new BasicAWSCredentials(accessKeyId, accessKeySecret);

    s3Serializer = new AmazonResourceSerializer(accessCredentials);
}

From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManagerTest.java

public void testModifyingALoadedDictionaryDoesNotAffectThePersistedData() throws Exception {
    Dictionary first = manager.load(GOOD_PID);
    first.put("favorite", "apocrypha");

    Dictionary second = manager.load(GOOD_PID);
    assertEquals("godspeed", second.get("favorite"));
}

From source file:io.wcm.dam.assetservice.impl.AssetService.java

@Activate
protected void activate(ComponentContext componentContext) {
    bundleContext = componentContext.getBundleContext();
    Dictionary config = componentContext.getProperties();

    String assetServletSelector = PropertiesUtil.toString(config.get(ASSET_SERVLET_SELECTOR_PROPERTY), null);
    String dataVersionServletSelector = PropertiesUtil
            .toString(config.get(DATAVERSION_SERVLET_SELECTOR_PROPERTY), null);

    String[] damPaths = PropertiesUtil.toStringArray(config.get(DAM_PATHS_PROPERTY));
    damPathHandler = new DamPathHandler(damPaths);

    // register servlets to resource types to handle the JSON requests
    // they are registred dynamically because the selectors are configurable
    assetRequestServletReg = registerServlet(bundleContext, new AssetRequestServlet(damPathHandler),
            DamConstants.NT_DAM_ASSET, assetServletSelector);
    dataVersionServletReg = registerServlet(bundleContext, new DataVersionServlet(damPathHandler),
            "sling:OrderedFolder", dataVersionServletSelector);
}

From source file:org.sdntest.app.SDNTest.java

/**
 * Get Integer property from the propertyName
 * Return null if propertyName is not found.
 *
 * @param properties   properties to be looked up
 * @param propertyName the name of the property to look up
 * @return value when the propertyName is defined or return null
 */// w w w  .  ja  v a2s . com
private static Integer getIntegerProperty(Dictionary<?, ?> properties, String propertyName) {
    Integer value = null;
    try {
        String s = (String) properties.get(propertyName);
        value = isNullOrEmpty(s) ? value : Integer.parseInt(s.trim());
    } catch (NumberFormatException | ClassCastException e) {
        value = null;
    }
    return value;
}

From source file:io.wcm.devops.conga.plugins.sling.postprocessor.ProvisioningOsgiConfigPostProcessorTest.java

@Test
public void testSimpleConfigWithNewline() throws Exception {
    final String PROVISIONING_FILE = "[feature name=test]\n" + "[configurations]\n"
            + "com.example.ServiceConfiguration\n" + "" + "  foo=\"foo\"";

    // post process provisioning example
    File provisioningFile = new File(targetDir, "simpleConfigWithNewline.txt");
    FileUtils.write(provisioningFile, PROVISIONING_FILE, StandardCharsets.UTF_8);
    postProcess(provisioningFile);//from   w w w.j a v  a 2s .  com

    // validate generated configs
    Dictionary<?, ?> config = readConfig("com.example.ServiceConfiguration.config");
    assertNull(config.get("bar"));
    assertEquals("foo", config.get("foo"));
}

From source file:org.openhab.action.xpl.internal.xPLActionService.java

/**
 * @{inheritDoc}//w w w .ja  va2  s  .  c om
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Updating config");
    if (config != null) {
        String instancename = (String) config.get("instance");
        logger.debug("Received new config : " + instancename);
        xPL.setInstance(instancename);
        isProperlyConfigured = true;
        // check mandatory settings
        if (StringUtils.isBlank(xPL.getInstance())) {
            throw new ConfigurationException("xPL",
                    "Parameters xPL:instance is mandatory and must be configured. Please check your openhab.cfg!");
        }
    }
}

From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilter.java

@Override
protected void doActivate(ComponentContext context) throws Exception {
    super.doActivate(context);

    @SuppressWarnings("unchecked")
    Dictionary<String, Object> props = context.getProperties();
    dayOfMonth = PropertiesUtil.toString(props.get(PROP_EXPIRES_DAY_OF_MONTH), null);

    if (StringUtils.isBlank(dayOfMonth)) {
        throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month must be specified.");
    }/*from  w  w w .j ava  2  s. co m*/

    if (!StringUtils.equalsIgnoreCase(LAST, dayOfMonth)) {
        // Make sure it's a valid value for Calendar.
        try {
            int intDay = Integer.parseInt(dayOfMonth);
            Calendar test = Calendar.getInstance();
            if (intDay < test.getMinimum(Calendar.DAY_OF_MONTH)) {
                throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH,
                        "Day of month is smaller than minimum allowed value.");
            }
            if (intDay > test.getActualMaximum(Calendar.DAY_OF_MONTH)) {
                throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH,
                        "Day of month is larger than least maximum allowed value.");
            }
        } catch (NumberFormatException ex) {
            throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month is not a valid value.");
        }
    }
}