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)
    • 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
      • parseUri

        String parseUri​(String uri,
                        boolean keepUnresolvedOptional)
        Parses the input text and resolve all property placeholders from within the text.
        Parameters:
        uri - input text
        keepUnresolvedOptional - whether to keep placeholders that are optional and was unresolved
        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.
      • loadPropertiesAsMap

        default Map<String,​Object> loadPropertiesAsMap()
        Loads the properties from the default locations and sources.
        Returns:
        a Map representing 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.
      • loadProperties

        Properties loadProperties​(Predicate<String> filter,
                                  Function<String,​String> keyMapper)
        Loads the properties from the default locations and sources filtering them out according to a predicate, and maps the key using the key mapper.
         PropertiesComponent pc = getPropertiesComponent();
         Properties props = pc.loadProperties(key -> key.startsWith("camel.component.seda"), StringHelper::dashToCamelCase);
         
        Parameters:
        filter - the predicate used to filter out properties based on the key.
        keyMapper - to map keys
        Returns:
        the properties loaded.
      • loadPropertiesAsMap

        default Map<String,​Object> loadPropertiesAsMap​(Predicate<String> filter)
        Loads the properties from the default locations and sources filtering them out according to a predicate.
         PropertiesComponent pc = getPropertiesComponent();
         Map props = pc.loadPropertiesAsMap(key -> key.startsWith("camel.component.seda"));
         
        Parameters:
        filter - the predicate used to filter out properties based on the key.
        Returns:
        a Map representing the properties loaded.
      • getLocations

        List<String> getLocations()
        Gets the configured properties locations. This may be empty if the properties component has only been configured with PropertiesSource.
      • 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 custom PropertiesSource to use as source for loading and/or looking up property values.
      • getPropertiesSource

        PropertiesSource getPropertiesSource​(String name)
        Gets the custom PropertiesSource by the name
        Parameters:
        name - the name of the source
        Returns:
        the source, or null if no source exists
      • 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.
      • addInitialProperty

        void addInitialProperty​(String key,
                                String value)
        Adds an initial property which will be added before any property locations are loaded.
        Parameters:
        key - the key
        value - the value
      • setOverrideProperties

        void setOverrideProperties​(Properties overrideProperties)
        Sets a special list of override properties that take precedence and will use first, if a property exist.
      • addOverrideProperty

        void addOverrideProperty​(String key,
                                 String value)
        Adds a special override property that take precedence and will use first, if a property exist.
        Parameters:
        key - the key
        value - the value
      • setLocalProperties

        void setLocalProperties​(Properties localProperties)
        Sets a special list of local properties (ie thread local) that take precedence and will use first, if a property exist.
      • getLocalProperties

        Properties getLocalProperties()
        Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.
      • getLocalPropertiesAsMap

        default Map<String,​Object> getLocalPropertiesAsMap()
        Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.
        Returns:
        a Map representing the local properties, or null if not currently in use.
      • 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 by Properties.load(java.io.InputStream)

        Important you must set encoding before setting locations.

      • reloadProperties

        boolean reloadProperties​(String pattern)
        Reload properties from the given location patterns.
        Parameters:
        pattern - patterns, or null to reload from all known locations
        Returns:
        true if some properties was reloaded