Class ResourceKeyUtils


  • public class ResourceKeyUtils
    extends Object
    Provides a setup of utility methods for operating on a ResourceKey class.
    Author:
    David Kincade
    • Constructor Detail

      • ResourceKeyUtils

        public ResourceKeyUtils()
    • Method Detail

      • createStringResourceKey

        public static String createStringResourceKey​(String schema,
                                                     String identifier,
                                                     Map factoryParameters)
        Returns a string representation of the ResourceKey based on the pieces that are passed as parameters
        Parameters:
        schema - the string representation of the schema
        identifier - the string representation of the identifier
        factoryParameters - the set of factory parameters (null allowed)
        Returns:
        the string version with the pieces delimited and concatenated
      • convertFactoryParametersToString

        public static String convertFactoryParametersToString​(Map factoryParameters)
        Returns the list of factory parameters for the specified ResourceKey as a String representation in the format:
           key=value:key=value:...:key=value
         
        The colon (:) is the separator between parameters and the equal sign (=) is the separator between the key and the value.

        If the factory parameters is empty, null will be returned

        Parameters:
        factoryParameters - the parameter map.
        Returns:
        a String representation of the factory parameters for the ResourceKey
      • parseFactoryParametersFromString

        public static Map parseFactoryParametersFromString​(String factoryParameters)
        Returns a Map of parameters based on the input string. The string will be parsed using the same format as defined in the getFactoryParametersAsString() method.
        Parameters:
        factoryParameters - the String representation of factory parameters
        Returns:
        a Map of factory parameters parsed from the string, or null if the source string was null or contained no data
      • readSchemaFromString

        public static Object readSchemaFromString​(String data)
        Returns the schema portion of the serialized ResourceKey string. If the string is invalid, null will be returned.
        Parameters:
        data - the String serialized version of a ResourceKey
        Returns:
        the schema object.
      • toResourceKey

        public static ResourceKey toResourceKey​(Object value,
                                                ResourceManager resourceManager,
                                                ResourceKey contextKey,
                                                Map parameters)
                                         throws ResourceKeyCreationException
        Performs a simple attempt at a "smart" conversion to a ResourceKey.
        1. If the value is null, this method will return null
        2. If the value is a ResourceKey, the value will be returned
        3. If the value is a String and is syntactically valid as a URL, it will be converted to a URL and then used to create a ResourceKey
        4. If the value is a String and is NOT syntactically valid as a URL, it will be converted ot a File and then used to create a ResourceKey
        5. All other types will be passed along to attempt a key creation as is
        Parameters:
        value - the object to convert to a ResourceKey
        resourceManager - the resource manager used in key creation
        parameters - the parameters that should be passed to generate a resource key
        Returns:
        the resource key created
        Throws:
        ResourceKeyCreationException - indicates the value can not be used to create a Resource Key