Filter example - read collection configuration options
The FilterContext
includes a number of methods for accessing the data source configuration.
Set<String> getConfigKeys()
-
Gets the set of all configuration keys for data source the filter is running under.
Map<String, List<String>> getConfigKeysMatchingPattern(String pattern)
-
Provides config settings which match the given key pattern.
Set<String> getConfigKeysWithPrefix(String prefix)
-
Provides a list of config setting keys which have some prefix.
Optional<String> getConfigValue(String key):
-
Gets the value of the configuration setting for the data source the filter is running under.
@Override
public FilterResult filterAsStringDocument(StringDocument document, FilterContext context) {
String color = context.getConfigValue(PluginUtils.KEY_PREFIX+".color").get(); (1)
String library = Optional.ofNullable(this.setup.getConfigSetting(PluginUtils.KEY_PREFIX+".library")).orElse("British Library"); (2)
log.info("Color: "+color);
log.info("Library: "+library);
return FilterResult.of(document);
}
1 | Read the color variable from a configuration key. |
2 | Read the library variable from a configuration key, setting it to British Library if the configuration key is not set. |