org.apache.commons.configuration2.ConfigurationConverter Java Examples

The following examples show how to use org.apache.commons.configuration2.ConfigurationConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadPropertiesStepExecution.java    From pipeline-utility-steps-plugin with MIT License 6 votes vote down vote up
/**
 * Using commons collection to interpolated the values inside the properties
 * @param properties the list of properties to be interpolated
 * @return a new Properties object with the interpolated values
 */
private Properties interpolateProperties(Properties properties) throws Exception {
    if ( properties == null)
        return null;
    Configuration interpolatedProp;
    PrintStream logger = getLogger();
    try {
        // Convert the Properties to a Configuration object in order to apply the interpolation
        Configuration conf = ConfigurationConverter.getConfiguration(properties);

        // Apply interpolation
        interpolatedProp = ((AbstractConfiguration)conf).interpolatedConfiguration();
    } catch (Exception e) {
        logger.println("Got exception while interpolating the variables: " + e.getMessage());
        logger.println("Returning the original properties list!");
        return properties;
    }

    // Convert back to properties
    return ConfigurationConverter.getProperties(interpolatedProp);
}
 
Example #2
Source File: DbDataComparisonConfigFactory.java    From obevo with Apache License 2.0 5 votes vote down vote up
private static DbDataComparisonConfig createFromProperties(final Configuration config) {
    Properties propsView = ConfigurationConverter.getProperties(config);  // config.getString() automatically parses
    // for commas...would like to avoid this
    DbDataComparisonConfig compConfig = new DbDataComparisonConfig();
    compConfig.setInputTables(Lists.mutable.with(propsView.getProperty("tables.include").split(",")));
    compConfig.setExcludedTables(Lists.mutable.with(propsView.getProperty("tables.exclude").split(",")).toSet());
    String comparisonsStr = propsView.getProperty("comparisons");

    MutableList<Pair<String, String>> compCmdPairs = Lists.mutable.empty();
    MutableSet<String> dsNames = UnifiedSet.newSet();
    for (String compPairStr : comparisonsStr.split(";")) {
        String[] pairParts = compPairStr.split(",");
        compCmdPairs.add(Tuples.pair(pairParts[0], pairParts[1]));

        // note - if I knew where the Pair.TO_ONE TO_TWO selectors were, I'd use those
        dsNames.add(pairParts[0]);
        dsNames.add(pairParts[1]);
    }

    compConfig.setComparisonCommandNamePairs(compCmdPairs);

    MutableList<DbDataSource> dbDataSources = dsNames.toList().collect(new Function<String, DbDataSource>() {
        @Override
        public DbDataSource valueOf(String dsName) {
            Configuration dsConfig = config.subset(dsName);

            DbDataSource dbDataSource = new DbDataSource();
            dbDataSource.setName(dsName);
            dbDataSource.setUrl(dsConfig.getString("url"));
            dbDataSource.setSchema(dsConfig.getString("schema"));
            dbDataSource.setUsername(dsConfig.getString("username"));
            dbDataSource.setPassword(dsConfig.getString("password"));
            dbDataSource.setDriverClassName(dsConfig.getString("driverClass"));

            return dbDataSource;
        }
    });
    compConfig.setDbDataSources(dbDataSources);
    return compConfig;
}
 
Example #3
Source File: PackageMetadataReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
private ImmutableHierarchicalConfiguration getConfig(String configContent) {
    if (configContent == null) {
        return new BaseHierarchicalConfiguration();
    }

    Properties props = new Properties();
    try {
        props.load(new StringReader(configContent));
        return ConfigurationUtils.convertToHierarchical(ConfigurationConverter.getConfiguration(props));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final TraversalStrategy traversalStrategy, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    for (final Map.Entry<Object, Object> entry : ConfigurationConverter.getMap(traversalStrategy.getConfiguration()).entrySet()) {
        jsonGenerator.writeObjectField((String) entry.getKey(), entry.getValue());
    }
    jsonGenerator.writeEndObject();
}
 
Example #5
Source File: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(final TraversalStrategy traversalStrategy, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
        throws IOException {
    jsonGenerator.writeStartObject();
    for (final Map.Entry<Object, Object> entry : ConfigurationConverter.getMap(traversalStrategy.getConfiguration()).entrySet()) {
        jsonGenerator.writeObjectField((String) entry.getKey(), entry.getValue());
    }
    jsonGenerator.writeEndObject();
}
 
Example #6
Source File: Neo4jGraph.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
protected Neo4jGraph(final Configuration configuration) {
    this.configuration.copy(configuration);
    final String directory = this.configuration.getString(CONFIG_DIRECTORY);
    final Map neo4jSpecificConfig = ConfigurationConverter.getMap(this.configuration.subset(CONFIG_CONF));
    this.baseGraph = Neo4jFactory.Builder.open(directory, neo4jSpecificConfig);
    this.initialize(this.baseGraph, configuration);
}
 
Example #7
Source File: Elepy.java    From elepy with Apache License 2.0 4 votes vote down vote up
private void init() {
    this.http.port(1337);

    this.propertyConfiguration.setListDelimiterHandler(new DefaultListDelimiterHandler(','));

    registerDependencySupplier(Validator.class,
            () -> Validation
                    .byProvider(HibernateValidator.class)
                    .configure()
                    .propertyNodeNameProvider(new PrettyNodeNameProvider())

                    .buildValidatorFactory().getValidator());


    registerDependencySupplier(org.apache.commons.configuration2.Configuration.class, () -> propertyConfiguration);

    registerDependencySupplier(Properties.class, () -> ConfigurationConverter.getProperties(propertyConfiguration));
    withFileService(new DefaultFileService());


    registerDependencySupplier(ObjectMapper.class, () -> new ObjectMapper()
            .enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
            .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
}
 
Example #8
Source File: OpenAPI2MarkupConfigBuilder.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public OpenAPI2MarkupConfigBuilder(Properties properties) {
    this(ConfigurationConverter.getConfiguration(properties));
}
 
Example #9
Source File: Swagger2MarkupConfigBuilder.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public Swagger2MarkupConfigBuilder(Properties properties) {
    this(ConfigurationConverter.getConfiguration(properties));
}
 
Example #10
Source File: Schema2MarkupProperties.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public Schema2MarkupProperties(Properties properties) {
    this(ConfigurationConverter.getConfiguration(properties));
}
 
Example #11
Source File: TraversalStrategySerializer.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
protected void writeValue(final TraversalStrategy value, final Buffer buffer, final GraphBinaryWriter context) throws IOException {
    context.writeValue(value.getClass(), buffer, false);
    context.writeValue(translateToBytecode(ConfigurationConverter.getMap(value.getConfiguration())), buffer, false);
}
 
Example #12
Source File: ConfigurationPropertiesFactoryBean.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.springframework.beans.factory.FactoryBean#getObject()
 */
@Override
public Properties getObject() throws Exception
{
    return compositeConfiguration != null ? ConfigurationConverter.getProperties(compositeConfiguration) : null;
}