Example usage for org.apache.commons.configuration PropertiesConfiguration isEmpty

List of usage examples for org.apache.commons.configuration PropertiesConfiguration isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Usage

From source file:com.konakart.apiexamples.BaseApiExample.java

/**
 * Initialise a KonaKart engine instance and perform a login to get a session id.
 * //from ww  w  .j  a v a2  s.  c  o m
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws KKException
 * @throws ConfigurationException
 * @throws IOException
 * @throws InvocationTargetException
 * @throws IllegalArgumentException
 */
static protected void init() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
        KKException, ConfigurationException, IOException, IllegalArgumentException, InvocationTargetException {
    EngineConfig engConf = new EngineConfig();
    engConf.setMode(getEngineMode());
    engConf.setStoreId(getStoreId());
    engConf.setCustomersShared(isCustomersShared());
    engConf.setProductsShared(isProductsShared());
    engConf.setCategoriesShared(isCategoriesShared());

    /*
     * Instantiate a KonaKart Engine. Different engines can be instantiated by passing
     * KKWSEngName or KKRMIEngName or KKJSONEngName for the SOAP, RMI or JSON engines
     */
    eng = getKKEngByName(KKEngName, engConf);

    /*
     * Login with default credentials
     */
    sessionId = eng.login(getUsername(), getPassword());

    if (sessionId == null) {
        String msg = "Login of " + DEFAULT_USERNAME + " was unsuccessful";
        log.warn(msg);
        throw new KKException(msg);
    }

    if (getEngineMode() == EngineConfig.MODE_MULTI_STORE_NON_SHARED_DB) {
        dbName = getStoreId();
    }

    // Read the KonaKart config file - note that this is done in the engine but if we are
    // running this over SOAP we might not have access to the engine's Configuration data - so
    // we do it here explicitly on the client side.
    PropertiesConfiguration allConfig = new PropertiesConfiguration(KKConstants.KONAKART_PROPERTIES_FILE);
    if (allConfig.isEmpty()) {
        throw new KKException("The configuration file: " + KKConstants.KONAKART_PROPERTIES_FILE
                + " does not appear to contain any keys");
    }

    // Look for properties that are in the "konakart" namespace.
    Configuration subConf = allConfig.subset("konakart");
    if (subConf == null || subConf.isEmpty()) {
        log.error("The konakart section in the properties file is missing. "
                + "You must add at least one property to resolve this problem. "
                + "e.g. konakart.session.expirationMinutes=30");
        return;
    }
    konakartConfig = subConf;
    log.info((new File(KKConstants.KONAKART_PROPERTIES_FILE)).getCanonicalPath() + " read");
}

From source file:com.konakartadmin.apiexamples.GetCustomerExamples.java

private String[] getPropertiesFromFile(String fileName, String keysStartingWith)
        throws KKAdminException, KKException, ConfigurationException {
    /*/*from  w  w  w  . j av a 2s  .c om*/
     * Find the specified properties file which is guaranteed to return the URL of
     * the properties file or throw an exception.
     */
    URL configFileURL = PropertyFileFinder.findPropertiesURL(fileName);

    PropertiesConfiguration conf = new PropertiesConfiguration(configFileURL);

    if (conf.isEmpty()) {
        throw new KKAdminException(
                "The configuration file: " + configFileURL + " does not appear to contain any keys");
    }

    // Now create the array of properties

    Iterator<?> keys = (conf.getKeys());
    int keyCount = 0;
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String value = (String) conf.getProperty(key);
        if (keysStartingWith == null || key.startsWith(keysStartingWith)) {
            System.out.println(keyCount + ") " + key + " => " + value);
            keyCount++;
        }
    }

    String[] properties = new String[keyCount * 2];
    keys = (conf.getKeys());
    int propIdx = 0;
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String value = (String) conf.getProperty(key);
        if (keysStartingWith == null || key.startsWith(keysStartingWith)) {
            properties[propIdx++] = key;
            properties[propIdx++] = value;
        }
    }

    return properties;
}

From source file:com.mirth.connect.manager.ManagerController.java

private PropertiesConfiguration initializeProperties(String path, boolean alert) {
    PropertiesConfiguration properties = new PropertiesConfiguration();

    // Auto reload changes
    FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy();
    fileChangedReloadingStrategy.setRefreshDelay(1000);
    properties.setReloadingStrategy(fileChangedReloadingStrategy);
    properties.setFile(new File(path));

    if (properties.isEmpty() && alert) {
        alertErrorDialog("Could not load properties from file: " + path);
    }//w w w .  ja va2 s .  c  om

    return properties;
}

From source file:dk.dma.ais.abnormal.analyzer.AbnormalAnalyzerAppModule.java

@Provides
@Singleton//from w  w  w  .  j  av  a 2  s .co  m
Configuration provideConfiguration() {
    PropertiesConfiguration configuration = null;
    if (Files.exists(configFile)) {
        try {
            configuration = new PropertiesConfiguration(configFile.toFile());
        } catch (ConfigurationException e) {
            LOG.error(e.getMessage(), e);
            System.exit(-1);
        }
        LOG.info("Using configuration file: " + configFile);
    }
    if (configuration == null) {
        LOG.error("Could not find configuration file: " + configFile);
        printConfigurationTemplate();
        System.exit(-1);
    }
    if (configuration.isEmpty()) {
        LOG.error("Configuration file was empty: " + configFile);
        printConfigurationTemplate();
        System.exit(-1);
    }
    if (!dk.dma.ais.abnormal.analyzer.config.Configuration.isValid(configuration)) {
        LOG.error("Configuration is invalid: " + configFile);
        printConfigurationTemplate();
        System.exit(-1);
    }
    LOG.info("Configuration file located, read and presumed valid.");
    return configuration;
}

From source file:org.wisdom.maven.utils.Properties2HoconConverterTest.java

@Test
public void testOnWikipediaSample() throws IOException {
    File props = new File(root, "/wiki.properties");
    File hocon = Properties2HoconConverter.convert(props, true);

    PropertiesConfiguration properties = loadPropertiesWithApacheConfiguration(props);
    assertThat(properties).isNotNull();//from   www  .jav a2  s.  co m
    Config config = load(hocon);
    assertThat(properties.isEmpty()).isFalse();
    assertThat(config.isEmpty()).isFalse();

    Iterator<String> iterator = properties.getKeys();
    String[] names = Iterators.toArray(iterator, String.class);
    for (String name : names) {
        if (!name.isEmpty()) {
            // 'cheeses' is not supported by commons-config.
            String o = properties.getString(name);
            String v = config.getString(name);
            assertThat(o).isEqualTo(v);
        }
    }

    assertThat(config.getString("cheeses")).isEmpty();

}

From source file:org.wisdom.maven.utils.Properties2HoconConverterTest.java

@Test
public void testTypes() throws IOException {
    File props = new File(root, "/types.properties");
    File hocon = Properties2HoconConverter.convert(props, true);

    PropertiesConfiguration properties = loadPropertiesWithApacheConfiguration(props);

    Config config = load(hocon);// w  ww  .  j ava 2  s. co  m
    assertThat(properties).isNotNull();
    assertThat(properties.isEmpty()).isFalse();
    assertThat(config.isEmpty()).isFalse();

    assertThat(config.getString("conf.string")).isEqualTo("foo");
    assertThat(config.getString("conf.int")).isEqualTo("1");
    assertThat(config.getInt("conf.int")).isEqualTo(1);
    assertThat(config.getNumber("conf.int")).isEqualTo(1);

    assertThat(config.getString("conf.float")).isEqualTo("1.1");
    assertThat(config.getNumber("conf.float")).isEqualTo(1.1);
    assertThat(config.getNumber("conf.float")).isEqualTo(1.1d);
    assertThat(config.getDouble("conf.float")).isEqualTo(1.1d);

    assertThat(config.getBoolean("conf.boolean.true")).isTrue();
    assertThat(config.getBoolean("conf.boolean.false")).isFalse();
    assertThat(config.getBoolean("conf.boolean.yes")).isTrue();
    assertThat(config.getBoolean("conf.boolean.no")).isFalse();
    assertThat(config.getBoolean("conf.boolean.on")).isTrue();
    assertThat(config.getBoolean("conf.boolean.off")).isFalse();

    assertThat(config.getDuration("conf.unit.time", TimeUnit.MILLISECONDS)).isEqualTo(10l);
    assertThat(config.getDuration("conf.unit.time", TimeUnit.MICROSECONDS)).isEqualTo(10000l);

    assertThat(config.getBytes("conf.unit.size")).isEqualTo(512 * 1024);
    assertThat(config.getBytes("conf.unit.size2")).isEqualTo(10);

    assertThat(config.getIntList("conf.list.int")).containsExactly(1, 2, 3);
    assertThat(config.getStringList("conf.list.string")).containsExactly("a", "b", "c");

    assertThat(config.hasPath("conf.missing")).isFalse();

    assertThat(config.getString("conf.quotes")).isEqualTo("http://example.com");
}