Class GenericRequestKeys

  • All Implemented Interfaces:
    RequestKeys
    Direct Known Subclasses:
    CaseInsensitiveRequestKeys, GenericEventHandler.GenericEventKeys, HttpRequestKeys, WebBeanUtils.SimpleRequestKeys

    public class GenericRequestKeys
    extends java.lang.Object
    implements RequestKeys
    This class provides provides a skeletal implementation of the interface RequestKeys, to minimize the effort required to implement this interface and allow subclasses to focus only on how to initialize the key-values collection from various sources.

    The implementation of this class actually adopts lazy initialization. It calls back the protected method initializeRequestKeys() when the first time you access to the key-values collection. Subclasses should provide their own specific implementation of initialization.

    Since:
    MicroStrategy Web 7.3.1 or earlier
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<java.lang.String,​Source> src  
    • Constructor Summary

      Constructors 
      Constructor Description
      GenericRequestKeys()
      Constructs a new GenericRequestKeys instance
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String add​(java.lang.String key, java.lang.String value)
      Appends a value to a collection mapped by the key specified.
      protected java.lang.String add​(java.lang.String key, java.lang.String value, java.lang.String delimiter)
      Appends a value to a collection mapped by the key specified.
      protected java.util.LinkedList addKeyValue​(java.lang.String key, java.lang.Object value)
      Adds an Object to the collection defined by the key.
      java.lang.Object addObject​(java.lang.String key, java.lang.Object value)
      Appends an Object to a collection mapped by the key specified.
      protected java.util.LinkedList getAllValues​(java.lang.String keyName)
      Retrieves all values associated with the key.
      MarkupOutput getDebugOut()
      Get the Debug Information into the output
      int getIntValue​(java.lang.String keyName, int valueIndex)
      Parses the value of given request key to an integer.
      int getIntValue​(java.lang.String keyName, int valueIndex, int defaultValue)
      Parses the value of given request key to an integer.
      java.util.Enumeration getKeyListByPrefix​(java.lang.String prefix)
      Returns an enumeration over all the keys with the specified prefix.
      java.lang.String getName​(int nameIndex)
      Returns the key at the specified position from the current collection.
      int getNameCount()
      Returns the total number of keys stored in the collection.
      protected java.lang.Object getObjectAtIndex​(java.lang.String keyName, int valueIndex)
      Retrieves the Object located at a specific index within the collection defined by keyName.
      Source getSource​(java.lang.String key)
      Determines where a given request key was sourced from.
      java.lang.String getValue​(java.lang.String keyName)
      Returns from this collection a comma separated string of all the values mapped by the specified keyName.
      java.lang.String getValue​(java.lang.String keyName, int valueIndex)
      Returns the value at the specified position mapped by the specified keyName.
      int getValueCount​(java.lang.String keyName)
      Returns from this collection the number of values mapped with the keyName.
      java.util.Enumeration getValueObject​(java.lang.String key)
      Returns the collection of all the values mapped by the specified keyName.
      java.lang.Object getValueObject​(java.lang.String keyName, int valueIndex)
      Returns the Object at the specified position mapped by the specified keyName.
      protected void initializeRequestKeys()
      Initializes the key-value collection from various sources.
      boolean isEmpty()
      Returns whether the value collection is empty.
      void remove​(java.lang.String key)
      Removes the argument with the given key.
      protected void setInitialized​(boolean initialized)
      Sets a flag indicating whether this collection has been initialized.
      protected void setObjectAtIndex​(java.lang.String key, java.lang.Object value, int index)
      Used by setValue and setValueObject to do the actual work.
      protected void setSource​(java.lang.String key, Source source)  
      void setValue​(java.lang.String key, java.lang.String value, int index)
      Replaces the value at a specific index for a given key.
      void setValueObject​(java.lang.String key, java.lang.Object value, int index)
      Replaces the Object at a specific index for a given key.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • src

        protected java.util.Map<java.lang.String,​Source> src
    • Constructor Detail

      • GenericRequestKeys

        public GenericRequestKeys()
        Constructs a new GenericRequestKeys instance
    • Method Detail

      • initializeRequestKeys

        protected void initializeRequestKeys()
        Initializes the key-value collection from various sources. Implementation class extending this class needs to call the add(String, String) method to add key-value pairs into the collection.
      • add

        public java.lang.String add​(java.lang.String key,
                                    java.lang.String value)
        Appends a value to a collection mapped by the key specified. A new collection is created if there is no such an collection existing. The initialized flag is set to True after calling this method.

        By default, there is no tokenizing of the string. This call is equivalent to call add(key, value, null).

        Specified by:
        add in interface RequestKeys
        Parameters:
        key - the key under which the new value will be appended
        value - the value to be appended
        Returns:
        a copy of the value added
      • addObject

        public java.lang.Object addObject​(java.lang.String key,
                                          java.lang.Object value)
        Appends an Object to a collection mapped by the key specified. A new collection is created if there is no such an collection existing. The initialized flag is set to True after calling this method.
        Specified by:
        addObject in interface RequestKeys
        Parameters:
        key - the key under which the new Object will be appended
        value - the Object to be appended
        Returns:
        a copy of the Object added
        Since:
        MicroStrategy Web 9.0.0
      • addKeyValue

        protected java.util.LinkedList addKeyValue​(java.lang.String key,
                                                   java.lang.Object value)
        Adds an Object to the collection defined by the key. Creates the collection if it doesn't exist yet.
        Parameters:
        key - the key under which the new Object will be appended
        value - the Object to be appended
        Returns:
        the LinkedList of Objects associated with the key
        Since:
        MicroStrategy Web 9.0.0
      • add

        protected java.lang.String add​(java.lang.String key,
                                       java.lang.String value,
                                       java.lang.String delimiter)
        Appends a value to a collection mapped by the key specified. A new collection is created if there is no such an collection existing. The initialized flag is set to True after calling this method.

        This method uses the specified delimiter to tokenize the value before adding each token into the collection.

        Parameters:
        key - the key under which the new value will be appended.
        value - the value to be appended.
        delimiter - the String delimiter used in tokenization.
        Returns:
        a copy of the value added
      • setValue

        public void setValue​(java.lang.String key,
                             java.lang.String value,
                             int index)
        Replaces the value at a specific index for a given key. As any key may have several values, this method replaces a specific value. Nothing happens if the index is out of bounds.
        Specified by:
        setValue in interface RequestKeys
        Parameters:
        key - the new key whose correponding value is to be added
        value - the new value to be added
        index - the position to add the key-value pair.
      • setValueObject

        public void setValueObject​(java.lang.String key,
                                   java.lang.Object value,
                                   int index)
        Replaces the Object at a specific index for a given key. As any key may have several Objects, this method replaces a specific Object. Nothing happens if the index is out of bounds.
        Specified by:
        setValueObject in interface RequestKeys
        Parameters:
        key - the new key whose correponding Object is to be added
        value - the new Object to be added
        index - the position to add the key-value pair.
        Since:
        MicroStrategy Web 9.0.0
      • setObjectAtIndex

        protected void setObjectAtIndex​(java.lang.String key,
                                        java.lang.Object value,
                                        int index)
        Used by setValue and setValueObject to do the actual work.
        Parameters:
        key - the new key whose correponding Object is to be added
        value - the new Object to be added
        index - the position to add the key-value pair.
        Since:
        MicroStrategy Web 9.0.0
      • remove

        public void remove​(java.lang.String key)
        Removes the argument with the given key.
        Specified by:
        remove in interface RequestKeys
        Parameters:
        key - the key of the argument to remove.
        Since:
        MicroStrategy Web 7.5.0
      • setInitialized

        protected void setInitialized​(boolean initialized)
        Sets a flag indicating whether this collection has been initialized. A false value will trigger this object to re-intialize itself by calling the method initializeRequestKeys().
        Parameters:
        initialized - true if the current collection has been initialized.
      • isEmpty

        public boolean isEmpty()
        Returns whether the value collection is empty.
        Specified by:
        isEmpty in interface RequestKeys
        Returns:
        true if the value collection is empty.
      • getNameCount

        public int getNameCount()
        Returns the total number of keys stored in the collection.
        Specified by:
        getNameCount in interface RequestKeys
        Returns:
        the number of keys stored in the collection.
      • getName

        public java.lang.String getName​(int nameIndex)
        Returns the key at the specified position from the current collection.
        Specified by:
        getName in interface RequestKeys
        Parameters:
        nameIndex - the index of the key
        Returns:
        the key at the specified index; null if the index is invalid.
      • getAllValues

        protected java.util.LinkedList getAllValues​(java.lang.String keyName)
        Retrieves all values associated with the key. Decoded values are added if they exist.
        Parameters:
        keyName - the key to retrieve all values for
        Returns:
        LinkedList of all values associated with the key
        Since:
        MicroStrategy Web 9.0.0
      • getValueCount

        public int getValueCount​(java.lang.String keyName)
        Returns from this collection the number of values mapped with the keyName.
        Specified by:
        getValueCount in interface RequestKeys
        Parameters:
        keyName - a key to a value collection
        Returns:
        the count of values to which the specified key is mapped in this collection; 0 if the key is not found.
      • getValue

        public java.lang.String getValue​(java.lang.String keyName)
        Returns from this collection a comma separated string of all the values mapped by the specified keyName.
        Specified by:
        getValue in interface RequestKeys
        Parameters:
        keyName - a key in this collection
        Returns:
        all the values mapped to the keyName, separated by the character comma; null if the key does not exist.
      • getValue

        public java.lang.String getValue​(java.lang.String keyName,
                                         int valueIndex)
        Returns the value at the specified position mapped by the specified keyName.
        Specified by:
        getValue in interface RequestKeys
        Parameters:
        keyName - a key in this collection
        valueIndex - the index of a value mapped to the key specified
        Returns:
        the value at the specified position mapped by the specified key; null if the key does not exist.
      • getIntValue

        public int getIntValue​(java.lang.String keyName,
                               int valueIndex)
        Description copied from interface: RequestKeys
        Parses the value of given request key to an integer.
        Specified by:
        getIntValue in interface RequestKeys
        Parameters:
        keyName - The request key name
        valueIndex - an index of the value to return (must be between 0 and getValueCount(name)-1.
        Returns:
        An integer value, if the value is not null and can be parsed to an integer. Otherwise, it throws NumberFormatException
      • getIntValue

        public int getIntValue​(java.lang.String keyName,
                               int valueIndex,
                               int defaultValue)
        Description copied from interface: RequestKeys
        Parses the value of given request key to an integer.
        Specified by:
        getIntValue in interface RequestKeys
        defaultValue - The default value.
        Returns:
        An integer value, if the value can be parsed to an integer. Otherwise, it returns the default value.
      • getObjectAtIndex

        protected java.lang.Object getObjectAtIndex​(java.lang.String keyName,
                                                    int valueIndex)
        Retrieves the Object located at a specific index within the collection defined by keyName.
        Parameters:
        keyName - key of object collection
        valueIndex - position of Object to retrieve
        Returns:
        the Object retrieved
        Since:
        MicroStrategy Web 9.0.0
      • getValueObject

        public java.util.Enumeration getValueObject​(java.lang.String key)
        Returns the collection of all the values mapped by the specified keyName.
        Specified by:
        getValueObject in interface RequestKeys
        Parameters:
        key - a key in this collection
        Returns:
        all the values mapped to the keyName; null if the key does not exist.
        Since:
        MicroStrategy Web 9.0.0
      • getValueObject

        public java.lang.Object getValueObject​(java.lang.String keyName,
                                               int valueIndex)
        Returns the Object at the specified position mapped by the specified keyName.
        Specified by:
        getValueObject in interface RequestKeys
        Parameters:
        keyName - a key in this collection
        valueIndex - the index of an Object mapped to the key specified
        Returns:
        the Object at the specified position mapped by the specified key; null if the key does not exist.
        Since:
        MicroStrategy Web 9.0.0
      • getKeyListByPrefix

        public java.util.Enumeration getKeyListByPrefix​(java.lang.String prefix)
        Returns an enumeration over all the keys with the specified prefix.
        Returns all the keys if the specified prefix is null or empty.
        Returns an empty list if no key is found.
        Specified by:
        getKeyListByPrefix in interface RequestKeys
        Parameters:
        prefix - the prefix of keys.
        Returns:
        an enumeration over all the keys that have the specified prefix.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Since:
        MicroStrategy Web 8.0.0
      • setSource

        protected void setSource​(java.lang.String key,
                                 Source source)
      • getSource

        public Source getSource​(java.lang.String key)
        Description copied from interface: RequestKeys
        Determines where a given request key was sourced from.
        Specified by:
        getSource in interface RequestKeys