Example usage for java.util Properties containsKey

List of usage examples for java.util Properties containsKey

Introduction

In this page you can find the example usage for java.util Properties containsKey.

Prototype

@Override
    public boolean containsKey(Object key) 

Source Link

Usage

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static int[] getDemoAddons(File buildFile) {

    List<Integer> listIndices = new ArrayList<Integer>();

    Properties defaultProps = loadProperties(
            buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties");
    Properties personalProps = loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator
            + "conf" + File.separator + "build-personal.properties");

    @SuppressWarnings("serial")
    Properties sortedProps = new Properties() {
        @Override/*from   w  w  w  .j  av  a 2 s  . c om*/
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }
    };
    sortedProps.putAll(defaultProps);

    // Looping through all possible options
    Enumeration<?> e = sortedProps.keys();

    int currentIndice = 0;
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        if (key.startsWith("demo.addons.") & !(key.endsWith("help") || key.endsWith("label"))) {
            String value = sortedProps.getProperty(key);
            if (personalProps.containsKey(key)) {
                value = personalProps.getProperty(key);
            }
            if (value.equals("true")) {
                listIndices.add(currentIndice);
            }
            currentIndice = currentIndice + 1;
        }
    }
    int[] array = new int[listIndices.size()];
    for (int i = 0; i < listIndices.size(); i++)
        array[i] = listIndices.get(i);
    return array;

}

From source file:com.github.htfv.maven.plugins.buildconfigurator.core.el.BuildConfiguratorELResolver.java

/**
 * Resolves value of a property.//from  w ww .  j a  va 2s.  co m
 *
 * @param context
 *            {@link ELContext} used to resolve EL expressions.
 * @param property
 *            name of the property to resolve.
 *
 * @return resolved value of the property.
 */
public Object resolve(final ELContext context, final String property) {
    if (valueCache.containsKey(property)) {
        context.setPropertyResolved(true);
        return valueCache.get(property);
    }

    final Properties userProperties = mavenProject.getProjectBuildingRequest().getUserProperties();

    if (userProperties.containsKey(property)) {
        final String value = userProperties.getProperty(property);

        context.setPropertyResolved(true);

        valueCache.put(property, value);
        return value;
    }

    final Properties projectProperties = mavenProject.getProperties();

    if (projectProperties.containsKey(property)) {
        final String value = projectProperties.getProperty(property);

        context.setPropertyResolved(true);

        valueCache.put(property, value);
        return value;
    }

    if (configuration.containsKey(property)) {
        final Object value = ELUtils.getValue(context, configuration.getString(property), Object.class);

        context.setPropertyResolved(true);

        valueCache.put(property, value);
        return value;
    }

    return null;
}

From source file:blueprint.sdk.experimental.florist.db.ConnectionListener.java

public void contextInitialized(final ServletContextEvent arg0) {
    Properties poolProp = new Properties();
    try {//  w ww.j a v  a 2 s.co  m
        Context initContext = new InitialContext();

        // load pool properties file (from class path)
        poolProp.load(ConnectionListener.class.getResourceAsStream("/jdbc_pools.properties"));
        StringTokenizer stk = new StringTokenizer(poolProp.getProperty("PROP_LIST"));

        // process all properties files list in pool properties (from class
        // path)
        while (stk.hasMoreTokens()) {
            try {
                String propName = stk.nextToken();
                LOGGER.info(this, "loading jdbc properties - " + propName);

                Properties prop = new Properties();
                prop.load(ConnectionListener.class.getResourceAsStream(propName));

                DataSource dsr;
                if (prop.containsKey("JNDI_NAME")) {
                    // lookup DataSource from JNDI
                    // FIXME JNDI support is not tested yet. SPI or Factory
                    // is needed here.
                    LOGGER.warn(this, "JNDI DataSource support needs more hands on!");
                    dsr = (DataSource) initContext.lookup(prop.getProperty("JNDI_NAME"));
                } else {
                    // create new BasicDataSource
                    BasicDataSource bds = new BasicDataSource();
                    bds.setMaxActive(Integer.parseInt(prop.getProperty("MAX_ACTIVE")));
                    bds.setMaxIdle(Integer.parseInt(prop.getProperty("MAX_IDLE")));
                    bds.setMaxWait(Integer.parseInt(prop.getProperty("MAX_WAIT")));
                    bds.setInitialSize(Integer.parseInt(prop.getProperty("INITIAL")));
                    bds.setDriverClassName(prop.getProperty("CLASS_NAME"));
                    bds.setUrl(prop.getProperty("URL"));
                    bds.setUsername(prop.getProperty("USER"));
                    bds.setPassword(prop.getProperty("PASSWORD"));
                    bds.setValidationQuery(prop.getProperty("VALIDATION"));
                    dsr = bds;
                }
                boundDsrs.put(prop.getProperty("POOL_NAME"), dsr);
                initContext.bind(prop.getProperty("POOL_NAME"), dsr);
            } catch (RuntimeException e) {
                LOGGER.trace(e);
            }
        }
    } catch (IOException | NamingException e) {
        LOGGER.trace(e);
    }
}

From source file:blueprint.sdk.util.config.Config.java

/**
 * Replace '$' enclosed value with system property.
 *
 * @param value XPath to evaluate/*www. ja va  2s .c  o  m*/
 * @return system property or value itself(no such property)
 */
@SuppressWarnings("WeakerAccess")
protected String resolveProperty(String value) {
    String result = value;

    if (!Validator.isEmpty(value) && value.charAt(0) == '$' && value.endsWith("$")) {
        String key = value.substring(1, value.length() - 1);

        Properties props = System.getProperties();
        if (props.containsKey(key)) {
            result = props.getProperty(key);
        }
    }

    return result;
}

From source file:org.deegree.console.ResourceProviderMetadata.java

private ResourceProviderMetadata(ResourceProvider rp) {
    String className = rp.getClass().getName();
    name = rp.getClass().getSimpleName();
    URL url = rp.getClass().getResource("/META-INF/console/resourceprovider/" + className);
    if (url != null) {
        LOG.debug("Loading resource provider metadata from '" + url + "'");
        Properties props = new Properties();
        InputStream is = null;//from w w  w .  ja va2  s  .c  om
        try {
            is = url.openStream();
            props.load(is);
            if (props.containsKey("name")) {
                name = props.getProperty("name").trim();
            }
            if (props.containsKey("wizard")) {
                wizardView = props.getProperty("wizard").trim();
            }
            int i = 1;
            while (true) {
                String examplePrefix = "example" + i + "_";
                String exampleLocation = props.getProperty(examplePrefix + "location");
                if (exampleLocation == null) {
                    break;
                }
                exampleLocation = exampleLocation.trim();
                String exampleName = "example";
                if (props.containsKey(examplePrefix + "name")) {
                    exampleName = props.getProperty(examplePrefix + "name").trim();
                }
                String exampleDescription = null;
                if (props.containsKey(examplePrefix + "description")) {
                    exampleDescription = props.getProperty(examplePrefix + "description").trim();
                }
                URL exampleUrl = this.getClass().getResource(exampleLocation);
                ConfigExample example = new ConfigExample(exampleUrl, exampleName, exampleDescription);
                exampleNameToExample.put(exampleName, example);
                i++;
            }
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        } finally {
            closeQuietly(is);
        }
    }
}

From source file:gobblin.metrics.kafka.KafkaAvroSchemaRegistry.java

/**
 * @param properties properties should contain property "kafka.schema.registry.url", and optionally
 * "kafka.schema.registry.max.cache.size" (default = 1000) and
 * "kafka.schema.registry.cache.expire.after.write.min" (default = 10).
 *//* w w  w.  j a  v a  2s  .co  m*/
public KafkaAvroSchemaRegistry(Properties props) {
    super(props);
    Preconditions.checkArgument(props.containsKey(KAFKA_SCHEMA_REGISTRY_URL),
            String.format("Property %s not provided.", KAFKA_SCHEMA_REGISTRY_URL));

    this.url = props.getProperty(KAFKA_SCHEMA_REGISTRY_URL);

    int objPoolSize = Integer
            .parseInt(props.getProperty(ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_THREADS,
                    "" + ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_DEFAULT_THREAD_COUNT));
    LOG.info("Create HttpClient pool with size " + objPoolSize);

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(objPoolSize);
    config.setMaxIdle(objPoolSize);
    this.httpClientPool = new GenericObjectPool<>(new HttpClientFactory(), config);
}

From source file:org.obiba.mica.search.queries.DatasetQuery.java

@Nullable
@Override/*  ww  w .  j  a va2s.c om*/
protected Properties getAggregationsProperties(List<String> filter) {
    Properties properties = getAggregationsProperties(filter, taxonomyService.getDatasetTaxonomy());
    if (!properties.containsKey(STUDY_JOIN_FIELD))
        properties.put(STUDY_JOIN_FIELD, "");
    if (!properties.containsKey(HARMONIZATION_STUDY_JOIN_FIELD))
        properties.put(HARMONIZATION_STUDY_JOIN_FIELD, "");
    if (!properties.containsKey(ID))
        properties.put(ID, "");
    return properties;
}

From source file:org.apache.gobblin.kafka.schemareg.LiKafkaSchemaRegistry.java

/**
 * @param props properties should contain property "kafka.schema.registry.url", and optionally
 * "kafka.schema.registry.max.cache.size" (default = 1000) and
 * "kafka.schema.registry.cache.expire.after.write.min" (default = 10).
 */// w  ww.  j a  v a 2s .c o m
public LiKafkaSchemaRegistry(Properties props) {
    Preconditions.checkArgument(
            props.containsKey(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_URL),
            String.format("Property %s not provided.",
                    KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_URL));

    this.url = props.getProperty(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_URL);
    this.namespaceOverride = KafkaAvroReporterUtil.extractOverrideNamespace(props);
    this.switchTopicNames = PropertiesUtils.getPropAsBoolean(props,
            KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_SWITCH_NAME,
            KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_SWITCH_NAME_DEFAULT);

    int objPoolSize = Integer
            .parseInt(props.getProperty(ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_THREADS,
                    "" + ConfigurationKeys.KAFKA_SOURCE_WORK_UNITS_CREATION_DEFAULT_THREAD_COUNT));
    LOG.info("Create HttpClient pool with size " + objPoolSize);

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(objPoolSize);
    config.setMaxIdle(objPoolSize);
    this.httpClientPool = new GenericObjectPool<>(new HttpClientFactory(), config);
}

From source file:org.apache.openejb.resource.jdbc.dbcp.DbcpDataSourceCreator.java

@Override
public CommonDataSource pool(final String name, final String driver, final Properties properties) {
    final String xa = String.class.cast(properties.remove("XaDataSource"));
    if (xa != null) {
        return XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa);
    }//from w w  w  .j  ava 2 s . c  o m

    if (!properties.containsKey("JdbcDriver")) {
        properties.setProperty("driverClassName", driver);
    }
    properties.setProperty("name", name);

    final BasicDataSource ds = build(BasicDataSource.class, properties);
    ds.setDriverClassName(driver);
    // if (xa != null) ds.setDelegate(XADataSourceResource.proxy(Thread.currentThread().getContextClassLoader(), xa));

    return ds;
}

From source file:net.certifi.audittablegen.AuditTableGenTest.java

/**
 * Test of getRunTimeDataSource method, of class AuditTableGen.
 *//*from ww  w  . ja va  2s.  c  o  m*/
@Test
public void testGetRunTimeDataSource() {
    System.out.println("getRunTimeDataSource");

    Properties props = mock(Properties.class);
    when(props.containsKey("url")).thenReturn(false);

    //default behavior is connect to in memory db (for testing).
    DataSource result = AuditTableGen.getRunTimeDataSource(props);
    assertNotNull(result);
}