Package org.apache.camel.spi
Interface PropertiesComponent
-
- All Superinterfaces:
AutoCloseable
,Service
,StaticService
public interface PropertiesComponent extends StaticService
Component for property placeholders and loading properties from sources (such as .properties file from classpath or file system)
-
-
Field Summary
Fields Modifier and Type Field Description static String
FACTORY
Service factory key.static String
PREFIX_TOKEN
The prefix token.static String
SUFFIX_TOKEN
The suffix token.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addLocation(String location)
Adds the list of locations to the current locations, where to load properties.void
addPropertiesFunction(PropertiesFunction function)
Registers thePropertiesFunction
as a function to this component.void
addPropertiesSource(PropertiesSource propertiesSource)
Adds a customPropertiesSource
to use as source for loading and/or looking up property values.List<String>
getLocations()
Gets the configured properties locations.Properties
loadProperties()
Loads the properties from the default locations and sources.Properties
loadProperties(Predicate<String> filter)
Loads the properties from the default locations and sources filtering them out according to a predicate.String
parseUri(String uri)
Parses the input text and resolve all property placeholders from within the text.Optional<String>
resolveProperty(String key)
Looks up the property with the given keyvoid
setEncoding(String encoding)
Encoding to use when loading properties file from the file system or classpath.void
setIgnoreMissingLocation(boolean ignoreMissingLocation)
Whether to silently ignore if a location cannot be located, such as a properties file not found.void
setInitialProperties(Properties initialProperties)
Sets initial properties which will be added before any property locations are loaded.void
setLocation(String location)
A list of locations to load properties.void
setOverrideProperties(Properties overrideProperties)
Sets a special list of override properties that take precedence and will use first, if a property exist.
-
-
-
Field Detail
-
FACTORY
static final String FACTORY
Service factory key.- See Also:
- Constant Field Values
-
PREFIX_TOKEN
static final String PREFIX_TOKEN
The prefix token.- See Also:
- Constant Field Values
-
SUFFIX_TOKEN
static final String SUFFIX_TOKEN
The suffix token.- See Also:
- Constant Field Values
-
-
Method Detail
-
parseUri
String parseUri(String uri)
Parses the input text and resolve all property placeholders from within the text.- Parameters:
uri
- input text- Returns:
- text with resolved property placeholders
- Throws:
IllegalArgumentException
- is thrown if error during parsing
-
resolveProperty
Optional<String> resolveProperty(String key)
Looks up the property with the given key- Parameters:
key
- the name of the property- Returns:
- the property value if present
-
loadProperties
Properties loadProperties()
Loads the properties from the default locations and sources.- Returns:
- the properties loaded.
-
loadProperties
Properties loadProperties(Predicate<String> filter)
Loads the properties from the default locations and sources filtering them out according to a predicate.PropertiesComponent pc = getPropertiesComponent(); Properties props = pc.loadProperties(key -> key.startsWith("camel.component.seda"));
- Parameters:
filter
- the predicate used to filter out properties based on the key.- Returns:
- the properties loaded.
-
getLocations
List<String> getLocations()
Gets the configured properties locations. This may be empty if the properties component has only been configured withPropertiesSource
.
-
setLocation
void setLocation(String location)
A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option.
-
addLocation
void addLocation(String location)
Adds the list of locations to the current locations, where to load properties. You can use comma to separate multiple locations.
-
addPropertiesSource
void addPropertiesSource(PropertiesSource propertiesSource)
Adds a customPropertiesSource
to use as source for loading and/or looking up property values.
-
addPropertiesFunction
void addPropertiesFunction(PropertiesFunction function)
Registers thePropertiesFunction
as a function to this component.
-
setIgnoreMissingLocation
void setIgnoreMissingLocation(boolean ignoreMissingLocation)
Whether to silently ignore if a location cannot be located, such as a properties file not found.
-
setInitialProperties
void setInitialProperties(Properties initialProperties)
Sets initial properties which will be added before any property locations are loaded.
-
setOverrideProperties
void setOverrideProperties(Properties overrideProperties)
Sets a special list of override properties that take precedence and will use first, if a property exist.
-
setEncoding
void setEncoding(String encoding)
Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented byProperties.load(java.io.InputStream)
Important you must set encoding before setting locations.
-
-