當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。