org.apache.commons.configuration2.AbstractConfiguration Java Examples

The following examples show how to use org.apache.commons.configuration2.AbstractConfiguration. 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: TestServletRequestConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@Override
protected AbstractConfiguration getEmptyConfiguration()
{
    final ServletRequest request = new MockHttpServletRequest()
    {
        @Override
        public String getParameter(final String key)
        {
            return null;
        }

        @Override
        public Map<?, ?> getParameterMap()
        {
            return new HashMap<>();
        }
    };

    return new ServletRequestConfiguration(request);
}
 
Example #3
Source File: TestServletConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@Override
protected AbstractConfiguration getConfiguration()
{
    final MockServletConfig config = new MockServletConfig();
    config.setInitParameter("key1", "value1");
    config.setInitParameter("key2", "value2");
    config.setInitParameter("list", "value1, value2");
    config.setInitParameter("listesc", "value1\\,value2");

    final Servlet servlet = new HttpServlet() {
        /**
         * Serial version UID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public ServletConfig getServletConfig()
        {
            return config;
        }
    };

    final ServletConfiguration servletConfiguration = new ServletConfiguration(servlet);
    servletConfiguration.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return servletConfiguration;
}
 
Example #4
Source File: TestServletRequestConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractConfiguration getConfiguration()
{
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("key1", "value1");
    configuration.setProperty("key2", "value2");
    configuration.addProperty("list", "value1");
    configuration.addProperty("list", "value2");
    configuration.addProperty("listesc", "value1\\,value2");

    return createConfiguration(configuration);
}
 
Example #5
Source File: TestConfigurationLogger.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the logger can be disabled by setting it to null.
 */
@Test
public void testAbstractConfigurationSetLoggerNull()
{
    final AbstractConfiguration config = new BaseConfiguration();
    config.setLogger(new ConfigurationLogger(getClass()));

    config.setLogger(null);
    assertThat("Logger not disabled", config.getLogger().getLog(), instanceOf(NoOpLog.class));
}
 
Example #6
Source File: TestConfigurationLogger.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether the logger can be set.
 */
@Test
public void testAbstractConfigurationSetLogger()
{
    final ConfigurationLogger logger = new ConfigurationLogger(getClass());
    final AbstractConfiguration config = new BaseConfiguration();

    config.setLogger(logger);
    assertThat("Logger not set", config.getLogger(), sameInstance(logger));
}
 
Example #7
Source File: TestConfigurationLogger.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the logger set per default.
 */
@Test
public void testAbstractConfigurationDefaultLogger()
{
    final AbstractConfiguration config = new BaseConfiguration();
    assertThat("Wrong default logger", config.getLogger().getLog(), instanceOf(NoOpLog.class));
}
 
Example #8
Source File: TestDatabaseConfigurationEvents.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    try
    {
        return helper.setUpConfig();
    }
    catch (final ConfigurationException e)
    {
        throw new AssertionError(e);
    }
}
 
Example #9
Source File: TestPropertyListConfigurationEvents.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    try
    {
        final PropertyListConfiguration c = new PropertyListConfiguration();
        new FileHandler(c).load(TEST_FILE);
        return c;
    }
    catch (final ConfigurationException cex)
    {
        throw new ConfigurationRuntimeException(cex);
    }
}
 
Example #10
Source File: TestXMLPropertyListConfigurationEvents.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    try
    {
        final XMLPropertyListConfiguration c = new XMLPropertyListConfiguration();
        new FileHandler(c).load(TEST_FILE);
        return c;
    }
    catch (final ConfigurationException cex)
    {
        throw new ConfigurationRuntimeException(cex);
    }
}
 
Example #11
Source File: TestServletContextConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractConfiguration getEmptyConfiguration()
{
    // create a servlet context
    final ServletContext context = new MockServletContext()
    {
        @Override
        public Enumeration<?> getInitParameterNames()
        {
            return new Properties().keys();
        }
    };

    return new ServletContextConfiguration(context);
}
 
Example #12
Source File: TestServletFilterConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractConfiguration getConfiguration()
{
    final MockFilterConfig config = new MockFilterConfig();
    config.setInitParameter("key1", "value1");
    config.setInitParameter("key2", "value2");
    config.setInitParameter("list", "value1, value2");
    config.setInitParameter("listesc", "value1\\,value2");

    final ServletFilterConfiguration resultConfig = new ServletFilterConfiguration(config);
    resultConfig.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return resultConfig;
}
 
Example #13
Source File: TestAppletConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractConfiguration getEmptyConfiguration()
{
    if (supportsApplet)
    {
        return new AppletConfiguration(new Applet());
    }
    return new BaseConfiguration();
}
 
Example #14
Source File: DoctorKafkaConfig.java    From doctorkafka with Apache License 2.0 5 votes vote down vote up
protected static Map<String, String> configurationToMap(AbstractConfiguration  configuration) {
  Iterator<String> keysIterator = configuration.getKeys();
  Map<String, String> result = new HashMap<>();
  while (keysIterator.hasNext()) {
    String key = keysIterator.next();
    result.put(key, configuration.getString(key));
  }
  return result;
}
 
Example #15
Source File: TestHierarchicalConfigurationEvents.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    return new BaseHierarchicalConfiguration();
}
 
Example #16
Source File: DoctorKafkaClusterConfig.java    From doctorkafka with Apache License 2.0 4 votes vote down vote up
public Map<String, String> getConsumerConfigurations() {
  AbstractConfiguration sslConfiguration = new SubsetConfiguration(clusterConfiguration, CONSUMER_PREFIX);
  return DoctorKafkaConfig.configurationToMap(sslConfiguration);
}
 
Example #17
Source File: DoctorKafkaConfig.java    From doctorkafka with Apache License 2.0 4 votes vote down vote up
/**
 * This method parses the configuration file and returns the kafka producer ssl setting
 * for writing to brokerstats kafka topic
 */
public Map<String, String> getBrokerStatsConsumerSslConfigs() {
  AbstractConfiguration sslConfiguration = new SubsetConfiguration(drkafkaConfiguration, BROKERSTATS_CONSUMER_PREFIX);
  return configurationToMap(sslConfiguration);
}
 
Example #18
Source File: DoctorKafkaConfig.java    From doctorkafka with Apache License 2.0 4 votes vote down vote up
public Map<String, String> getActionReportProducerSslConfigs() {
  AbstractConfiguration sslConfiguration =
      new SubsetConfiguration(drkafkaConfiguration, ACTION_REPORT_PRODUCER_PREFIX);
  return configurationToMap(sslConfiguration);
}
 
Example #19
Source File: TestSubsetConfigurationEvents.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    return (SubsetConfiguration)new MapConfiguration(new HashMap<String, Object>()).subset("test");
}
 
Example #20
Source File: TestXMLConfigurationEvents.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    return new XMLConfiguration();
}
 
Example #21
Source File: TestPropertiesConfigurationEvents.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    return new PropertiesConfiguration();
}
 
Example #22
Source File: TestMapConfigurationEvents.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration createConfiguration()
{
    return new MapConfiguration(new HashMap<String, Object>());
}
 
Example #23
Source File: TestServletContextConfiguration.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration getConfiguration()
{
    final Properties parameters = new Properties();
    parameters.setProperty("key1", "value1");
    parameters.setProperty("key2", "value2");
    parameters.setProperty("list", "value1, value2");
    parameters.setProperty("listesc", "value1\\,value2");

    // create a servlet context
    final ServletContext context = new MockServletContext()
    {
        @Override
        public String getInitParameter(final String key)
        {
            return parameters.getProperty(key);
        }

        @Override
        public Enumeration<?> getInitParameterNames()
        {
            return parameters.keys();
        }
    };

    // create a servlet config
    final MockServletConfig config = new MockServletConfig();
    config.setServletContext(context);

    // create a servlet
    final Servlet servlet = new HttpServlet()
    {
        /**
         * Serial version UID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public ServletConfig getServletConfig()
        {
            return config;
        }
    };

    final ServletContextConfiguration resultConfig = new ServletContextConfiguration(servlet);
    resultConfig.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return resultConfig;
}
 
Example #24
Source File: Schema2MarkupConfigBuilder.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public Schema2MarkupConfigBuilder(final Class<T> selfClass,
                                  C config,
                                  Schema2MarkupProperties schema2MarkupProperties,
                                  Configuration configuration) {
    this.self = selfClass.cast(this);
    this.config = config;

    config.listDelimiterEnabled = schema2MarkupProperties.getBoolean(LIST_DELIMITER_ENABLED, false);
    config.listDelimiter = schema2MarkupProperties.getString(LIST_DELIMITER, ",").charAt(0);

    if (config.listDelimiterEnabled && configuration instanceof AbstractConfiguration) {
        ((AbstractConfiguration) configuration).setListDelimiterHandler(new DefaultListDelimiterHandler(config.listDelimiter));
    }

    config.requestExamplesFormat = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_FORMAT);
    config.requestExamplesSourceFormat = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_SOURCE_FORMAT);
    config.requestExamplesHost = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_HOST);
    config.requestExamplesSchema = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_SCHEMA);
    config.requestExamplesHideBasePath = schema2MarkupProperties.getRequiredBoolean(REQUEST_EXAMPLES_HIDE_BASE_PATH);
    config.requestExamplesQueryArrayStyle = schema2MarkupProperties.getRequiredString(REQUEST_EXAMPLES_QUERY_ARRAY_STYLE);
    config.requestExamplesIncludeAllQueryParams = schema2MarkupProperties.getRequiredBoolean(REQUEST_EXAMPLES_INCLUDE_ALL_QUERY_PARAMS);
    config.markupLanguage = schema2MarkupProperties.getRequiredMarkupLanguage(MARKUP_LANGUAGE);
    config.schemaMarkupLanguage = schema2MarkupProperties.getRequiredMarkupLanguage(SWAGGER_MARKUP_LANGUAGE);
    config.generatedExamplesEnabled = schema2MarkupProperties.getRequiredBoolean(GENERATED_EXAMPLES_ENABLED);
    config.hostnameEnabled = schema2MarkupProperties.getRequiredBoolean(HOSTNAME_ENABLED);
    config.basePathPrefixEnabled = schema2MarkupProperties.getRequiredBoolean(BASE_PATH_PREFIX_ENABLED);
    config.separatedDefinitionsEnabled = schema2MarkupProperties.getRequiredBoolean(SEPARATED_DEFINITIONS_ENABLED);
    config.separatedOperationsEnabled = schema2MarkupProperties.getRequiredBoolean(SEPARATED_OPERATIONS_ENABLED);
    config.pathsGroupedBy = schema2MarkupProperties.getGroupBy(PATHS_GROUPED_BY);
    config.language = schema2MarkupProperties.getLanguage(OUTPUT_LANGUAGE);
    config.inlineSchemaEnabled = schema2MarkupProperties.getRequiredBoolean(INLINE_SCHEMA_ENABLED);
    config.interDocumentCrossReferencesEnabled = schema2MarkupProperties.getRequiredBoolean(INTER_DOCUMENT_CROSS_REFERENCES_ENABLED);
    config.interDocumentCrossReferencesPrefix = schema2MarkupProperties.getString(INTER_DOCUMENT_CROSS_REFERENCES_PREFIX, null);
    config.flatBodyEnabled = schema2MarkupProperties.getRequiredBoolean(FLAT_BODY_ENABLED);
    config.pathSecuritySectionEnabled = schema2MarkupProperties.getRequiredBoolean(PATH_SECURITY_SECTION_ENABLED);
    config.anchorPrefix = schema2MarkupProperties.getString(ANCHOR_PREFIX, null);
    config.overviewDocument = schema2MarkupProperties.getRequiredString(OVERVIEW_DOCUMENT);
    config.pathsDocument = schema2MarkupProperties.getRequiredString(PATHS_DOCUMENT);
    config.definitionsDocument = schema2MarkupProperties.getRequiredString(DEFINITIONS_DOCUMENT);
    config.securityDocument = schema2MarkupProperties.getRequiredString(SECURITY_DOCUMENT);
    config.separatedOperationsFolder = schema2MarkupProperties.getRequiredString(SEPARATED_OPERATIONS_FOLDER);
    config.separatedDefinitionsFolder = schema2MarkupProperties.getRequiredString(SEPARATED_DEFINITIONS_FOLDER);
    config.tagOrderBy = schema2MarkupProperties.getOrderBy(TAG_ORDER_BY);
    config.operationOrderBy = schema2MarkupProperties.getOrderBy(OPERATION_ORDER_BY);
    config.definitionOrderBy = schema2MarkupProperties.getOrderBy(DEFINITION_ORDER_BY);
    config.parameterOrderBy = schema2MarkupProperties.getOrderBy(PARAMETER_ORDER_BY);
    config.propertyOrderBy = schema2MarkupProperties.getOrderBy(PROPERTY_ORDER_BY);
    config.responseOrderBy = schema2MarkupProperties.getOrderBy(RESPONSE_ORDER_BY);
    Optional<String> lineSeparator = schema2MarkupProperties.getString(LINE_SEPARATOR);
    if (lineSeparator.isPresent() && StringUtils.isNoneBlank(lineSeparator.get())) {
        config.lineSeparator = LineSeparator.valueOf(lineSeparator.get());
    }

    config.pageBreakLocations = schema2MarkupProperties.getPageBreakLocations(PAGE_BREAK_LOCATIONS);

    Optional<Pattern> headerPattern = schema2MarkupProperties.getHeaderPattern(HEADER_REGEX);

    config.headerPattern = headerPattern.orElse(null);

    Configuration swagger2markupConfiguration = schema2MarkupProperties.getConfiguration().subset(PROPERTIES_PREFIX);
    Configuration extensionsConfiguration = swagger2markupConfiguration.subset(EXTENSION_PREFIX);
    config.extensionsProperties = new Schema2MarkupProperties(extensionsConfiguration);
    config.asciidocPegdownTimeoutMillis = schema2MarkupProperties.getRequiredInt(ASCIIDOC_PEGDOWN_TIMEOUT);
}
 
Example #25
Source File: DoctorKafkaClusterConfig.java    From doctorkafka with Apache License 2.0 4 votes vote down vote up
public DoctorKafkaClusterConfig(String clusterName, AbstractConfiguration configuration) {
  this.clusterName = clusterName;
  this.clusterConfiguration = configuration;
}
 
Example #26
Source File: TestServletConfiguration.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration getEmptyConfiguration()
{
    return new ServletConfiguration(new MockServletConfig());
}
 
Example #27
Source File: TestServletFilterConfiguration.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractConfiguration getEmptyConfiguration()
{
    return new ServletFilterConfiguration(new MockFilterConfig());
}
 
Example #28
Source File: AbstractTestConfigurationEvents.java    From commons-configuration with Apache License 2.0 2 votes vote down vote up
/**
 * Creates the configuration instance to be tested.
 *
 * @return the configuration instance under test
 */
protected abstract AbstractConfiguration createConfiguration();