Example usage for org.apache.commons.configuration Configuration getProperty

List of usage examples for org.apache.commons.configuration Configuration getProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getProperty.

Prototype

Object getProperty(String key);

Source Link

Document

Gets a property from the configuration.

Usage

From source file:com.flipkart.flux.guice.module.AkkaModule.java

/**
 * Returns map of all the available routers and actors per router,
 * currently a router is created per Task of deployment unit //todo: handle dynamic deployments
 *//*from w w  w .  java  2s .co m*/
@Provides
@Singleton
@Named("routerConfigMap")
public Map<String, Integer> getRouterConfigs(
        @Named("deploymentUnits") Map<String, DeploymentUnit> deploymentUnitsMap,
        @Named("routers.default.instancesPerNode") int defaultNoOfActors) {
    Map<String, Integer> routerConfigMap = new ConcurrentHashMap<>();

    //add all deployment units' routers
    for (Map.Entry<String, DeploymentUnit> deploymentUnitEntry : deploymentUnitsMap.entrySet()) {
        DeploymentUnit deploymentUnit = deploymentUnitEntry.getValue();
        Set<Method> taskMethods = deploymentUnit.getTaskMethods();
        Configuration taskConfiguration = deploymentUnit.getTaskConfiguration();

        for (Method taskMethod : taskMethods) {
            String routerName = new MethodId(taskMethod).getPrefix();
            Integer taskExecConcurrency = Optional
                    .ofNullable((Integer) taskConfiguration.getProperty(routerName + ".executionConcurrency"))
                    .orElse(defaultNoOfActors);
            routerConfigMap.put(routerName, taskExecConcurrency);
        }
    }
    return routerConfigMap;
}

From source file:com.example.titan.dynamodb.hystrix.issue.TitanConfigurationProvider.java

private String secureToString(final Configuration configuration) {
    final Iterator keys = configuration.getKeys();
    final StringBuilder result = new StringBuilder();

    while (keys.hasNext()) {
        final String key = (String) keys.next();
        final Object value = configuration.getProperty(key);
        result.append(key).append("=");

        if (key.contains("password")) {
            result.append("*********");
        } else {//from ww w .  j  a va 2  s.co  m
            result.append(value);
        }

        if (keys.hasNext()) {
            result.append("\n");
        }
    }

    return result.toString();
}

From source file:com.ripariandata.timberwolf.conf4j.ConfigFileParser.java

/**
 * Takes the values from the given Configuration instance and applies them to
 * the target class.  Fields in the target class marked with ConfigEntry
 * annotations that don't correspond to any properties in the given configuration
 * are not modified.  Properties in the configuration that don't match any
 * fields marked as ConfigEntry are ignored.
 *///from www .  j  a  v a  2 s  .  co  m
public void parseConfiguration(final Configuration config) {
    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        if (fields.containsKey(key)) {
            fields.get(key).set(config.getProperty(key));
        }
    }
}

From source file:it.geosolutions.opensdi2.configurations.model.converters.PropertiesConfigurationConverter.java

/**
 * This implementation expects an input object instance of org.apache.commons.configuration.Configuration otherwise an unchecked exception is thrown. 
 * The concrete return type is always an instance of OSDIConfigurationKVP
 *//*  w  w w  .ja  v  a  2s.co  m*/
@Override
public OSDIConfiguration buildConfig(Object configToBeConverted, String scopeID, String instanceID) {
    if (!(configToBeConverted instanceof Configuration)) {
        throw new IllegalArgumentException(
                "You are using the class OSDIPropertiesConverter as implementation of the OSDIConfigConverter interface, you need to pass to this method an instance of org.apache.commons.configuration.Configuration");
    }
    Configuration inConfig = (Configuration) configToBeConverted;
    OSDIConfigurationKVP outConfig = new OSDIConfigurationKVP(scopeID, instanceID);

    Iterator<String> iter = inConfig.getKeys();
    String tmpKey = "";
    while (iter.hasNext()) {
        tmpKey = iter.next();
        outConfig.addNew(tmpKey, inConfig.getProperty(tmpKey));
    }
    return outConfig;
}

From source file:lp.reminiscens.crawler.FlickrToURL.java

public FlickrToURL() {

    FlickrSearchQuery_url = "http://api.flickr.com/services/rest/?method=flickr.photos.search";
    FlickrGetLocationQuery_url = "http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation";

    FlickrGetLocationQuery_id = "&photo_id=";
    FlickrQuery_per_page = "&per_page=100";
    seconds = "+00:00:00";
    FlickrExtraQuery = "&extras=";
    FlickrExtraGeo = "geo";
    FlickrExtraTags = "tags";
    FlickrExtraTakenDate = "date_taken";
    FlickrExtraUploadDate = "date_upload";
    FlickrMin_Taken_Date = "&min_taken_date=";
    FlickrMax_Taken_Date = "&max_taken_date=";
    FlickrQuery_nojsoncallback = "&nojsoncallback=1";
    FlickrQuery_format = "&format=json";
    FlickrQuery_license = "&license=1%2C2%2C4%2C5%2C7"; // creative commons
    FlickrQuery_tag = "&tags=";
    FlickrQuery_key = "&api_key=";

    try {/*from  w ww  . ja  va  2  s .  c  o m*/
        Configuration config = new PropertiesConfiguration("lifecontext.utils.config");
        FlickrApiKey = config.getProperty("flickr.apikey").toString();
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    photos = new HashSet<Media>();
}

From source file:dk.itst.oiosaml.sp.develmode.DevelModeImpl.java

public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain fc, Configuration conf)
        throws IOException, ServletException {

    // Inserted to avoid loginpage when a samlhandler is requested in develmode
    if (req.getServletPath().equals(conf.getProperty(Constants.PROP_SAML_SERVLET))) {
        log.debug("Develmode: Request to SAML servlet, access granted");
        fc.doFilter(req, res);//from  w w w.  jav a 2  s  . c  o m
        return;
    }

    UserAssertionHolder.set(null);
    UserAssertion ua = (UserAssertion) req.getSession().getAttribute(Constants.SESSION_USER_ASSERTION);
    if (ua == null) {
        String[] users = conf.getStringArray("oiosaml-sp.develmode.users");
        if (users == null || users.length == 0) {
            log.error("No users defined in properties. Set oiosaml-sp.develmode.users");
            res.setStatus(500);
            HTTPUtils.sendCacheHeaders(res);
            render("nousers.vm", res, new HashMap<String, Object>());
            return;
        }

        if (users.length == 1) {
            ua = selectUser(users[0], conf);
        } else {
            String selected = req.getParameter("__oiosaml_devel");
            if (selected == null || !Arrays.asList(users).contains(selected)) {
                HTTPUtils.sendCacheHeaders(res);

                Map<String, Object> params = new HashMap<String, Object>();
                params.put("users", users);
                params.put("params", buildParameterString(req.getParameterMap()));
                render("users.vm", res, params);
                return;
            } else {
                HTTPUtils.sendCacheHeaders(res);
                ua = selectUser(selected, conf);
                req.getSession().setAttribute(Constants.SESSION_USER_ASSERTION, ua);
                res.sendRedirect(req.getRequestURI() + "?" + buildParameterString(req.getParameterMap()));
                return;
            }
        }
    }

    if (ua != null) {
        req.getSession().setAttribute(Constants.SESSION_USER_ASSERTION, ua);
        UserAssertionHolder.set(ua);

        HttpServletRequestWrapper requestWrap = new SAMLHttpServletRequest(req, ua, "");
        fc.doFilter(requestWrap, res);
        return;
    } else {
        log.error("No assertion found");
        res.sendError(500);
        return;
    }
}

From source file:com.ripariandata.timberwolf.conf4j.ConfigFileParserTest.java

License:asdf

private Configuration mockConfiguration(final Object... settings) {
    if ((settings.length % 2) != 0) {
        return null;
    }/*from   w ww .j  a v a  2  s.c  o  m*/

    Configuration config = mock(Configuration.class);

    Vector<String> keys = new Vector<String>();
    for (int i = 0; i < settings.length; i += 2) {
        String key = settings[i].toString();
        keys.add(key);
        when(config.getProperty(key)).thenReturn(settings[i + 1]);
    }
    when(config.getKeys()).thenReturn(keys.iterator());

    return config;
}

From source file:com.amazon.janusgraph.TestGraphUtil.java

public WriteConfiguration appendStoreConfig(final BackendDataModel model, final WriteConfiguration config,
        final List<String> storeNames) {
    final Configuration baseconfig = createTestConfig(model);
    final Iterator<String> it = baseconfig.getKeys();
    while (it.hasNext()) {
        final String key = it.next();
        config.set(key, baseconfig.getProperty(key));
    }/*from w  w  w .j a va2 s .  c  o  m*/
    return appendClusterPartitionsAndStores(model, config, storeNames, 1 /*titanClusterPartitions*/);
}

From source file:com.amazon.janusgraph.TestGraphUtil.java

public WriteConfiguration appendClusterPartitionsAndStores(final BackendDataModel model,
        final WriteConfiguration config, final List<String> storeNames, final int janusGraphClusterPartitions) {
    final Configuration baseconfig = createTestConfig(model);
    final Iterator<String> it = baseconfig.getKeys();
    while (it.hasNext()) {
        final String key = it.next();
        config.set(key, baseconfig.getProperty(key));
    }//from ww w  .j  a v  a  2  s. c  o  m

    Preconditions.checkArgument(janusGraphClusterPartitions > 0);
    if (janusGraphClusterPartitions > 1) {
        config.set("cluster.max-partitions", Integer.toString(janusGraphClusterPartitions));
    }

    for (String store : storeNames) {
        final String prefix = "storage.dynamodb.stores." + store;
        TestGraphUtil.configureStore(model.name(), provisionedReadAndWriteTps, config, isUnlimitedIops(),
                prefix);
    }

    return config;
}

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

@Test
public void testBoolean() throws Exception {
    Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test");

    final String key = UUID.randomUUID().toString();

    assertThat(config.getProperty(key), nullValue());

    config.setProperty(key, true);//from  www. j  a va  2s.c o  m
    assertTrue(config.getBoolean(key, false));
    assertEquals(config.getBoolean(key, Boolean.FALSE), Boolean.TRUE);

    config.setProperty(key, false);
    assertFalse(config.getBoolean(key, true));
    assertEquals(config.getBoolean(key, Boolean.TRUE), Boolean.FALSE);

}