当前位置: 首页>>代码示例>>Java>>正文


Java CompositeConfiguration类代码示例

本文整理汇总了Java中org.apache.commons.configuration.CompositeConfiguration的典型用法代码示例。如果您正苦于以下问题:Java CompositeConfiguration类的具体用法?Java CompositeConfiguration怎么用?Java CompositeConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompositeConfiguration类属于org.apache.commons.configuration包,在下文中一共展示了CompositeConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
private void run(CompositeConfiguration conf) {
    // Spark conf
    SparkConf sparkConf = new SparkConf().setAppName("TwitterSparkCrawler").setMaster(conf.getString("spark.master"))
            .set("spark.serializer", conf.getString("spark.serializer"));
    JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, Durations.seconds(conf.getLong("stream.duration")));

    // Twitter4J
    // IMPORTANT: put keys in twitter4J.properties
    Configuration twitterConf = ConfigurationContext.getInstance();
    Authorization twitterAuth = AuthorizationFactory.getInstance(twitterConf);

    // Create twitter stream
    String[] filters = { "#Car" };
    TwitterUtils.createStream(jssc, twitterAuth, filters).print();
    // Start the computation
    jssc.start();
    jssc.awaitTermination();
}
 
开发者ID:ogidogi,项目名称:laughing-octo-sansa,代码行数:19,代码来源:TwitterSparkCrawler.java

示例2: bake

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
public void bake(final LaunchOptions options, final CompositeConfiguration config) {
    final Oven oven = new Oven(options.getSource(), options.getDestination(), config, options.isClearCache());
    oven.setupPaths();
    oven.bake();

    final List<Throwable> errors = oven.getErrors();
    if (!errors.isEmpty()) {
        final StringBuilder msg = new StringBuilder();
        // TODO: decide, if we want the all errors here
        msg.append( MessageFormat.format("JBake failed with {0} errors:\n", errors.size()));
        int errNr = 1;
        for (final Throwable error : errors) {
            msg.append(MessageFormat.format("{0}. {1}\n", errNr, error.getMessage()));
            ++errNr;
        }
        throw new JBakeException(msg.toString(), errors.get(0));
    }
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:19,代码来源:Baker.java

示例3: render

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Override
public int render(Renderer renderer, ContentStore db, File destination, File templatesPath, CompositeConfiguration config) throws RenderingException {
    int renderedCount = 0;
    final List<String> errors = new LinkedList<String>();
    for (String docType : DocumentTypes.getDocumentTypes()) {
        DocumentList documentList = db.getUnrenderedContent(docType);
        for (Map<String, Object> page : documentList) {
            try {
                renderer.render(page);
                renderedCount++;
            } catch (Exception e) {
                errors.add(e.getMessage());
            }
        }
    }
    if (!errors.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        sb.append("Failed to render documents. Cause(s):");
        for (String error : errors) {
            sb.append("\n").append(error);
        }
        throw new RenderingException(sb.toString());
    } else {
        return renderedCount;
    }
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:27,代码来源:DocumentsRenderer.java

示例4: render

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Override
public int render(Renderer renderer, ContentStore db, File destination, File templatesPath, CompositeConfiguration config) throws RenderingException {
    if (config.getBoolean(Keys.RENDER_INDEX)) {
        try {
            if (shouldPaginateIndex(config)) {
                renderer.renderIndexPaging(config.getString(Keys.INDEX_FILE));
            } else {
                renderer.renderIndex(config.getString(Keys.INDEX_FILE));
            }
            return 1;
        } catch (Exception e) {
            throw new RenderingException(e);
        }
    } else {
        return 0;
    }
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:18,代码来源:IndexRenderer.java

示例5: propagatesRenderingException

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Test(expected = RenderingException.class)
public void propagatesRenderingException() throws Exception {
    IndexRenderer renderer = new IndexRenderer();

    CompositeConfiguration compositeConfiguration = new MockCompositeConfiguration().withDefaultBoolean(true);
    compositeConfiguration.setProperty(PAGINATE_INDEX, false);
    ContentStore contentStore = mock(ContentStore.class);
    Renderer mockRenderer = mock(Renderer.class);

    doThrow(new Exception()).when(mockRenderer).renderIndex(anyString());

    int renderResponse = renderer.render(mockRenderer, contentStore,
            new File("fake"), new File("fake"), compositeConfiguration);

    verify(mockRenderer, never()).renderIndex("random string");
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:17,代码来源:IndexRendererTest.java

示例6: returnsOneWhenConfigRendersIndices

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Test
public void returnsOneWhenConfigRendersIndices() throws Exception {
    TagsRenderer renderer = new TagsRenderer();

    CompositeConfiguration compositeConfiguration = new MockCompositeConfiguration().withDefaultBoolean(true);
    ContentStore contentStore = mock(ContentStore.class);
    Renderer mockRenderer = mock(Renderer.class);

    Set<String> tags = new HashSet(Arrays.asList("tag1", "tags2"));
    when(contentStore.getTags()).thenReturn(tags);

    when(mockRenderer.renderTags("random string")).thenReturn(1);

    int renderResponse = renderer.render(mockRenderer, contentStore,
            new File("fake"), new File("fake"), compositeConfiguration);

    assertThat(renderResponse).isEqualTo(1);
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:19,代码来源:TagsRendererTest.java

示例7: doesRenderWhenConfigDoesNotRenderIndices

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Test
public void doesRenderWhenConfigDoesNotRenderIndices() throws Exception {
    TagsRenderer renderer = new TagsRenderer();

    CompositeConfiguration compositeConfiguration = new MockCompositeConfiguration().withDefaultBoolean(true);
    ContentStore contentStore = mock(ContentStore.class);
    Renderer mockRenderer = mock(Renderer.class);

    Set<String> tags = new HashSet(Arrays.asList("tag1", "tags2"));
    when(contentStore.getTags()).thenReturn(tags);

    int renderResponse = renderer.render(mockRenderer, contentStore,
            new File("fake"), new File("fake"), compositeConfiguration);

    verify(mockRenderer, times(1)).renderTags("random string");
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:17,代码来源:TagsRendererTest.java

示例8: renderWithPrettyUrls

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Test
public void renderWithPrettyUrls() throws Exception {
    Map<String, Object> testProperties = new HashMap<String, Object>();
    testProperties.put(Keys.URI_NO_EXTENSION, true);
    testProperties.put(Keys.URI_NO_EXTENSION_PREFIX, "/blog");

    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new MapConfiguration(testProperties));
    config.addConfiguration(ConfigUtil.load(new File(this.getClass().getResource("/").getFile())));

    Crawler crawler = new Crawler(db, sourceFolder, config);
    crawler.crawl(new File(sourceFolder.getPath() + File.separator + config.getString(Keys.CONTENT_FOLDER)));

    Assert.assertEquals(4, db.getDocumentCount("post"));
    Assert.assertEquals(3, db.getDocumentCount("page"));

    DocumentList documents = db.getPublishedPosts();

    for (Map<String, Object> model : documents) {
        String noExtensionUri = "blog/\\d{4}/" + FilenameUtils.getBaseName((String) model.get("file")) + "/";

        Assert.assertThat(model.get("noExtensionUri"), RegexMatcher.matches(noExtensionUri));
        Assert.assertThat(model.get("uri"), RegexMatcher.matches(noExtensionUri + "index\\.html"));
    }
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:26,代码来源:CrawlerTest.java

示例9: createConfiguration

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
protected CompositeConfiguration createConfiguration() throws ConfigurationException {
    final CompositeConfiguration config = new CompositeConfiguration();

    if (properties != null) {
        config.addConfiguration(new MapConfiguration(properties));
    }
    config.addConfiguration(new MapConfiguration(project.getProperties()));
    config.addConfiguration(ConfigUtil.load(inputDirectory));
    
    if (getLog().isDebugEnabled()) {
        getLog().debug("Configuration:");

        Iterator<String> iter = config.getKeys();
        while (iter.hasNext()) {
            String key = iter.next();
            getLog().debug(key + ": " + config.getString(key));
        }
    }

    return config;
}
 
开发者ID:Blazebit,项目名称:jbake-maven-plugin,代码行数:22,代码来源:BuildMojo.java

示例10: testLoadConfiguration

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Test
public void testLoadConfiguration() {
    Configuration conf1 = new CompositeConfiguration();
    conf1.setProperty("key1", "value1");
    conf1.setProperty("key2", "value2");
    conf1.setProperty("key3", "value3");

    Configuration conf2 = new CompositeConfiguration();
    conf2.setProperty("bkc.key1", "bkc.value1");
    conf2.setProperty("bkc.key4", "bkc.value4");

    assertEquals("value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals(null, conf1.getString("key4"));

    ConfUtils.loadConfiguration(conf1, conf2, "bkc.");

    assertEquals("bkc.value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals("bkc.value4", conf1.getString("key4"));
    assertEquals(null, conf1.getString("bkc.key1"));
    assertEquals(null, conf1.getString("bkc.key4"));
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:26,代码来源:TestConfUtils.java

示例11: jbakeOven

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Bean
public Oven jbakeOven() throws Exception {
    log.info("Baking {} -> {}", source, destination);

    File sourceFile = new File(source);
    final CompositeConfiguration config;
    try {
        config = ConfigUtil.load(sourceFile);
    } catch (final ConfigurationException e) {
        throw new JBakeException("Configuration error: " + e.getMessage(), e);
    }

    System.out.println("JBake " + config.getString(ConfigUtil.Keys.VERSION) + " (" + config.getString(ConfigUtil.Keys.BUILD_TIMESTAMP) + ") [http://jbake.org]");
    System.out.println();

    Oven oven = new Oven(sourceFile, new File(destination), true);
    oven.setupPaths();

    return oven;
}
 
开发者ID:netdava,项目名称:jbakery,代码行数:21,代码来源:JbakeConfig.java

示例12: getCommonConfiguration

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
public Configuration getCommonConfiguration() throws IOException {
    CompositeConfiguration conf = new CompositeConfiguration();
    Enumeration<URL> resources = SAMLConfiguration.class.getClassLoader().getResources("oiosaml-common.properties");
    while (resources.hasMoreElements()) {
        URL u = resources.nextElement();
        log.debug("Loading config from " + u);
        try {
            conf.addConfiguration(new PropertiesConfiguration(u));
        } catch (ConfigurationException e) {
            log.error("Cannot load the configuration file", e);
            throw new WrappedException(Layer.DATAACCESS, e);
        }
    }

    return conf;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:17,代码来源:FileConfiguration.java

示例13: getCommonConfiguration

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
public Configuration getCommonConfiguration() throws IOException {
	CompositeConfiguration conf = new CompositeConfiguration();
	Enumeration<URL> resources = SAMLConfiguration.class.getClassLoader().getResources("oiosaml-common.properties");
	while (resources.hasMoreElements()) {
		URL u = resources.nextElement();
		log.debug("Loading config from " + u);
		try {
			conf.addConfiguration(new PropertiesConfiguration(u));
		} catch (ConfigurationException e) {
			log.error("Cannot load the configuration file", e);
			throw new WrappedException(Layer.DATAACCESS, e);
		}
	}

	return conf;
}
 
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:17,代码来源:FileConfiguration.java

示例14: createConfiguration

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
@Override
protected Configuration createConfiguration(String name) throws ConfigurationException {
  CompositeConfiguration config = new CompositeConfiguration();
  config.addConfiguration(new SystemConfiguration());
  try {
    if (ConfigFactory.DEFAULT_CONFIG_NAME.equals(name)) {
      config.addConfiguration(new PropertiesConfiguration("config.properties"));
    } else {
      config.addConfiguration(new PropertiesConfiguration(name));
    }
  } catch (ConfigurationException e) {
    String message = "No properties file found: " + name
        + ". Using an empty BaseConfiguration instead.";
    if (ConfigFactory.DEFAULT_CONFIG_NAME.equals(name)) {
      LOG.info(message);
    } else {
      LOG.warn(message);
    }
    BaseConfiguration base = new BaseConfiguration();
    config.addConfiguration(base);
  }
  return config;
}
 
开发者ID:irenical,项目名称:jindy,代码行数:24,代码来源:CommonsSimpleImpl.java

示例15: getConfig

import org.apache.commons.configuration.CompositeConfiguration; //导入依赖的package包/类
/**
 * The combined config = current user config + defaults for non-specified properties.
 * TODO: instead of re-reading user config every time, it would be better
 *       to set up Commons Configuration listeners on the userfile.
 * @return even if reading user config fails, will return default config
 */
public CompositeConfiguration getConfig() {

    // try loading user config
    FileConfiguration userConfig = null;
    try {
        userConfig = BmConfig.forClass(BaseMap2D.class);
    } catch (ConfigurationException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    // the order of adding configurations to combined configuration is important
    // whoever is added first "shadows" the same key in all subsequently added
    // configuraions. Thus, add the DEFAULTs at the very end
    if (userConfig != null) {
        compositeConfig.addConfiguration(userConfig);
    }
    compositeConfig.addConfiguration(defaultConfig);

    return compositeConfig;
}
 
开发者ID:chhh,项目名称:batmass,代码行数:27,代码来源:Map2DOptions.java


注:本文中的org.apache.commons.configuration.CompositeConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。