Package helma.util

Class ResourceProperties

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,​java.lang.Object>

    public class ResourceProperties
    extends java.util.Properties
    A property dictionary that is updated from property resources
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceProperties()
      Constructs an empty ResourceProperties Resources must be added manually afterwards
      ResourceProperties​(Application app)
      Constructs an empty ResourceProperties Resources must be added manually afterwards
      ResourceProperties​(Application app, java.lang.String resourceName)
      Constructs a ResourceProperties retrieving resources from the given application using the given name to fetch resources
      ResourceProperties​(Application app, java.lang.String resourceName, ResourceProperties defaultProperties)
      Constructs a ResourceProperties retrieving resources from the given application using the given name to fetch resources and falling back to the given default properties
      ResourceProperties​(Application app, java.lang.String resourceName, ResourceProperties defaultProperties, boolean ignoreCase)
      Constructs a ResourceProperties retrieving resources from the given application using the given name to fetch resources and falling back to the given default properties
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addResource​(Resource resource)
      Adds a resource to the list of resources and updates all properties if needed
      void clear()
      Overwrite clear() to also empty the key map.
      boolean contains​(java.lang.Object value)
      Checks wether the given object is in the value list
      boolean containsKey​(java.lang.Object key)
      Checks wether the given object is in the key list
      java.util.Enumeration elements()
      Returns an enumeration of all values
      boolean equals​(java.lang.Object o)
      Compares this ResourceProperties instance to the one passed as argument.
      java.lang.Object get​(java.lang.Object key)
      Returns a value in this list fetched by the given key
      long getChecksum()
      Returns a checksum for all resources
      java.lang.String getProperty​(java.lang.String key)
      Returns a value in this list fetched by the given key
      java.lang.String getProperty​(java.lang.String key, java.lang.String defaultValue)
      Returns a value in the list fetched by the given key or a default value if no corresponding key is found
      java.util.Iterator getResources()
      Get an iterator over the properties' resources
      ResourceProperties getSubProperties​(java.lang.String prefix)
      Extract all entries where the key matches the given string prefix from the source map to the target map, cutting off the prefix from the original key.
      boolean isEmpty()
      Checks wether the properties list is empty
      boolean isIgnoreCase()
      Checks wether case-sensitivity is ignored for keys
      java.util.Enumeration keys()
      Returns an enumeration of all keys
      java.util.Set keySet()
      Returns a set of all keys
      long lastModified()
      Returns the date the resources were last modified
      java.lang.Object put​(java.lang.Object key, java.lang.Object value)
      Puts a new key-value pair into the properties list
      java.lang.Object remove​(java.lang.Object key)
      Removes a key-value pair from the properties list
      void removeResource​(Resource resource)
      Removes a resource from the list of resources and updates all properties if needed
      void setDefaultProperties​(ResourceProperties defaultProperties)
      Sets the default properties and updates all properties
      void setIgnoreCase​(boolean ignore)
      Changes how keys are handled
      int size()
      Returns the number of peroperties in the list
      void update()
      Updates all properties if there is a need to update
      • Methods inherited from class java.util.Properties

        clone, compute, computeIfAbsent, computeIfPresent, containsValue, entrySet, forEach, getOrDefault, hashCode, list, list, load, load, loadFromXML, merge, propertyNames, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, save, setProperty, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ResourceProperties

        public ResourceProperties()
        Constructs an empty ResourceProperties Resources must be added manually afterwards
      • ResourceProperties

        public ResourceProperties​(Application app)
        Constructs an empty ResourceProperties Resources must be added manually afterwards
      • ResourceProperties

        public ResourceProperties​(Application app,
                                  java.lang.String resourceName)
        Constructs a ResourceProperties retrieving resources from the given application using the given name to fetch resources
        Parameters:
        app - application to fetch resources from
        resourceName - name to use when fetching resources from the application
      • ResourceProperties

        public ResourceProperties​(Application app,
                                  java.lang.String resourceName,
                                  ResourceProperties defaultProperties)
        Constructs a ResourceProperties retrieving resources from the given application using the given name to fetch resources and falling back to the given default properties
        Parameters:
        app - application to fetch resources from
        resourceName - name to use when fetching resources from the application
        defaultProperties - default properties
      • ResourceProperties

        public ResourceProperties​(Application app,
                                  java.lang.String resourceName,
                                  ResourceProperties defaultProperties,
                                  boolean ignoreCase)
        Constructs a ResourceProperties retrieving resources from the given application using the given name to fetch resources and falling back to the given default properties
        Parameters:
        app - application to fetch resources from
        resourceName - name to use when fetching resources from the application
        defaultProperties - default properties
        ignoreCase - ignore case for property keys, setting all keys to lower case
    • Method Detail

      • setDefaultProperties

        public void setDefaultProperties​(ResourceProperties defaultProperties)
        Sets the default properties and updates all properties
        Parameters:
        defaultProperties - default properties
      • addResource

        public void addResource​(Resource resource)
        Adds a resource to the list of resources and updates all properties if needed
        Parameters:
        resource - resource to add
      • removeResource

        public void removeResource​(Resource resource)
        Removes a resource from the list of resources and updates all properties if needed
        Parameters:
        resource - resource to remove
      • getResources

        public java.util.Iterator getResources()
        Get an iterator over the properties' resources
        Returns:
        iterator over the properties' resources
      • update

        public void update()
        Updates all properties if there is a need to update
      • getSubProperties

        public ResourceProperties getSubProperties​(java.lang.String prefix)
        Extract all entries where the key matches the given string prefix from the source map to the target map, cutting off the prefix from the original key. The ignoreCase property is inherited and also considered when matching keys against the prefix.
        Parameters:
        prefix - the string prefix to match against
        Returns:
        a new subproperties instance
      • contains

        public boolean contains​(java.lang.Object value)
        Checks wether the given object is in the value list
        Overrides:
        contains in class java.util.Properties
        Parameters:
        value - value to look for
        Returns:
        true if the value is found in the value list
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Checks wether the given object is in the key list
        Specified by:
        containsKey in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        containsKey in class java.util.Properties
        Parameters:
        key - key to look for
        Returns:
        true if the key is found in the key list
      • elements

        public java.util.Enumeration elements()
        Returns an enumeration of all values
        Overrides:
        elements in class java.util.Properties
        Returns:
        values enumeration
      • get

        public java.lang.Object get​(java.lang.Object key)
        Returns a value in this list fetched by the given key
        Specified by:
        get in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        get in class java.util.Properties
        Parameters:
        key - key to use for fetching the value
        Returns:
        value belonging to the given key
      • lastModified

        public long lastModified()
        Returns the date the resources were last modified
        Returns:
        last modified date
      • getChecksum

        public long getChecksum()
        Returns a checksum for all resources
        Returns:
        checksum
      • getProperty

        public java.lang.String getProperty​(java.lang.String key,
                                            java.lang.String defaultValue)
        Returns a value in the list fetched by the given key or a default value if no corresponding key is found
        Overrides:
        getProperty in class java.util.Properties
        Parameters:
        key - key to use for fetching the value
        defaultValue - default value to return if key is not found
        Returns:
        spiecific value or default value if not found
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        Returns a value in this list fetched by the given key
        Overrides:
        getProperty in class java.util.Properties
        Parameters:
        key - key to use for fetching the value
        Returns:
        value belonging to the given key
      • isEmpty

        public boolean isEmpty()
        Checks wether the properties list is empty
        Specified by:
        isEmpty in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        isEmpty in class java.util.Properties
        Returns:
        true if the properties list is empty
      • isIgnoreCase

        public boolean isIgnoreCase()
        Checks wether case-sensitivity is ignored for keys
        Returns:
        true if case-sensitivity is ignored for keys
      • keys

        public java.util.Enumeration keys()
        Returns an enumeration of all keys
        Overrides:
        keys in class java.util.Properties
        Returns:
        keys enumeration
      • keySet

        public java.util.Set keySet()
        Returns a set of all keys
        Specified by:
        keySet in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        keySet in class java.util.Properties
        Returns:
        keys set
      • put

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value)
        Puts a new key-value pair into the properties list
        Specified by:
        put in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        put in class java.util.Properties
        Parameters:
        key - key
        value - value
        Returns:
        the old value, if an old value got replaced
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Removes a key-value pair from the properties list
        Specified by:
        remove in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        remove in class java.util.Properties
        Parameters:
        key - key
        Returns:
        the old value
      • setIgnoreCase

        public void setIgnoreCase​(boolean ignore)
        Changes how keys are handled
        Parameters:
        ignore - true if to ignore case-sensitivity for keys
      • size

        public int size()
        Returns the number of peroperties in the list
        Specified by:
        size in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        size in class java.util.Properties
        Returns:
        number of properties
      • clear

        public void clear()
        Overwrite clear() to also empty the key map.
        Specified by:
        clear in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        clear in class java.util.Properties
      • equals

        public boolean equals​(java.lang.Object o)
        Compares this ResourceProperties instance to the one passed as argument. Note that in contrast to Hashtable.equals this method isn't synchronized to avoid deadlocks (which can happen in eg. DbSource.equals), and the comparison might return a wrong result if one of the two instances is modified during this method call. This method however doesn't throw a ConcurrentModificationException.
        Specified by:
        equals in interface java.util.Map<java.lang.Object,​java.lang.Object>
        Overrides:
        equals in class java.util.Properties
        Parameters:
        o - object to be compared for equality with this instance
        Returns:
        true if the specified Object is equal to this instance
        See Also:
        Hashtable.equals(Object)