com.wewebu.ow.server.util.paramcodec
Class OwCookieStoreCodec

java.lang.Object
  extended by com.wewebu.ow.server.util.paramcodec.OwCookieStoreCodec
All Implemented Interfaces:
OwParameterMapCodec
Direct Known Subclasses:
OwAttributeBagCodec, OwTransientCodec

public abstract class OwCookieStoreCodec
extends Object
implements OwParameterMapCodec

An OwParameterMap codec that relays on a stored cookie scheme.
When encoding an OwParameterMap a cookie value is generated, stored in the encoded map and the generated cookie is associated with the parameters to be encoded.
When decoding an OwParameterMap the value of the URL parameter is fetched and the parameter map associated with it is returned as the decoded value.
The stored cookies expire after a certain amount of time and they are removed along with the parameter map they are associated with. When expired cookies are subject to decoding an OwUserOperationException is thrown to signal expiration.
Storing the cookies is delegated to subclasses.

Alfresco Workdesk
Copyright (c) Alfresco Software, Inc.
All rights reserved.

For licensing information read the license.txt file or
go to: http://wiki.alfresco.com

Since:
3.0.0.0

Nested Class Summary
protected static class OwCookieStoreCodec.OwTimedCookie
           Inner cookie name class used to encapsulate a cookie name and its expiration time.
protected static class OwCookieStoreCodec.OwTimedCookieValue
           Inner cookie name class used to encapsulate an OwCookieStoreCodec.OwTimedCookie and its associated parameter map.
 
Field Summary
static String CONFIGURATION_BOOTSTRAP_ELEMENT_NAME
          Configuration root element which contains the definition of values
static String CONFIGURATION_DAYS_ATTRIBUTE
          Configuration attribute for count of days
static String CONFIGURATION_HOURS_ATTRIBUTE
          Configuration attribute for count of hours
static String CONFIGURATION_MINUTES_ATTRIBUTE
          Configuration attribute for count of minutes
static String CONFIGURATION_NAME_ATTRIBUTE
          Configuration attribute of name for CONFIGURATION_URL_PARAMETER_ELEMENT
static String CONFIGURATION_SECONDS_ATTRIBUTE
          Configuration attribute for count of seconds
static String CONFIGURATION_URL_LIFE_TIME_ELEMENT
          Configuration element for definition of life time
static String CONFIGURATION_URL_PARAMETER_ELEMENT
          Configuration element for definition of the URL parameter
static long DEFAULT_CONFIG_URL_LIFE_TIME
          default value for expiration time 5 years value in milliseconds, calculated 5 (years) * 365 (days) * 24 (hours) * 60 (minutes) * 60 (seconds) * 1000 (milliseconds)
static String DEFAULT_URL_PARAMETER_NAME
          Default value for URL parameter name
 
Constructor Summary
OwCookieStoreCodec()
          Constructor
Defaults DEFAULT_CONFIG_URL_LIFE_TIME and DEFAULT_URL_PARAMETER_NAME will be used.
OwCookieStoreCodec(long namesUrlLifeTime_p)
          Constructor
OwCookieStoreCodec(OwAlphabetCoder alphabetCder_p, String urlParamenterName_p, long namesUrlLifeTime_p)
          Constructor
OwCookieStoreCodec(String urlParamenterName_p, long namesUrlLifeTime_p)
          Constructor
 
Method Summary
protected abstract  void addCookieValue(OwCookieStoreCodec.OwTimedCookieValue timedCookieValue_p)
          Adds the given OwCookieStoreCodec.OwTimedCookieValue to the cookie store
 boolean canDecode(OwParameterMap parameterMap_p)
          Verifies that this codec can decode the given OwParameterMap without system-errors.
protected  void collectExpiredNames()
           
protected  String createCookie(long uniqueNameIndex_p)
           
protected abstract  List createTimedCookieCollectList()
          Hook method that returns a list of OwCookieStoreCodec.OwTimedCookies to be collected.
 OwParameterMap decode(OwParameterMap parameterMap_p, boolean preserveEncoding_p)
          Decodes the given OwParameterMap
 OwParameterMap encode(OwParameterMap parameterMap_p)
          Encodes the given OwParameterMap
protected abstract  OwCookieStoreCodec.OwTimedCookieValue getCookieValue(String cookieName_p)
           
static long loadUrlLifeTimeConfig(OwXMLUtil codecConfiguration_p)
          Loads XML URLLifeTime configuration : URLLifeTime - tag
Configures the amount of time an encoded URL parameter map is valid.
After that the parameter map is considered expired and links that relay
on are considered out of date / expired and will not produce the desired response.

Attributes :
days = days until the parameter map expires considering the URL parameter map encoding time
hours = hours until the parameter map expires considering the URL parameter map encoding time
minutes = minutes until the parameter map expires considering the URL parameter map encoding time
seconds = seconds until the parameter map expires considering the URL parameter map encoding time
static String loadUrlParameterConfig(OwXMLUtil codecConfiguration_p)
          Loads URL parameter XML configuration : URLParameter - tag
The parameter map codec encodes a parameter map into another parameter map containing
one cookie defining parameter.
protected abstract  void remove(OwCookieStoreCodec.OwTimedCookie timedCookie_p)
          Removes the given OwCookieStoreCodec.OwTimedCookie from cookie storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.wewebu.ow.server.util.paramcodec.OwParameterMapCodec
getNextUnqiueNameIndex
 

Field Detail

CONFIGURATION_BOOTSTRAP_ELEMENT_NAME

public static final String CONFIGURATION_BOOTSTRAP_ELEMENT_NAME
Configuration root element which contains the definition of values

See Also:
Constant Field Values

CONFIGURATION_DAYS_ATTRIBUTE

public static final String CONFIGURATION_DAYS_ATTRIBUTE
Configuration attribute for count of days

See Also:
Constant Field Values

CONFIGURATION_HOURS_ATTRIBUTE

public static final String CONFIGURATION_HOURS_ATTRIBUTE
Configuration attribute for count of hours

See Also:
Constant Field Values

CONFIGURATION_MINUTES_ATTRIBUTE

public static final String CONFIGURATION_MINUTES_ATTRIBUTE
Configuration attribute for count of minutes

See Also:
Constant Field Values

CONFIGURATION_NAME_ATTRIBUTE

public static final String CONFIGURATION_NAME_ATTRIBUTE
Configuration attribute of name for CONFIGURATION_URL_PARAMETER_ELEMENT

See Also:
Constant Field Values

CONFIGURATION_SECONDS_ATTRIBUTE

public static final String CONFIGURATION_SECONDS_ATTRIBUTE
Configuration attribute for count of seconds

See Also:
Constant Field Values

CONFIGURATION_URL_LIFE_TIME_ELEMENT

public static final String CONFIGURATION_URL_LIFE_TIME_ELEMENT
Configuration element for definition of life time

See Also:
Constant Field Values

CONFIGURATION_URL_PARAMETER_ELEMENT

public static final String CONFIGURATION_URL_PARAMETER_ELEMENT
Configuration element for definition of the URL parameter

See Also:
Constant Field Values

DEFAULT_CONFIG_URL_LIFE_TIME

public static final long DEFAULT_CONFIG_URL_LIFE_TIME
default value for expiration time 5 years value in milliseconds, calculated 5 (years) * 365 (days) * 24 (hours) * 60 (minutes) * 60 (seconds) * 1000 (milliseconds)

See Also:
Constant Field Values

DEFAULT_URL_PARAMETER_NAME

public static final String DEFAULT_URL_PARAMETER_NAME
Default value for URL parameter name

See Also:
Constant Field Values
Constructor Detail

OwCookieStoreCodec

public OwCookieStoreCodec()
Constructor
Defaults DEFAULT_CONFIG_URL_LIFE_TIME and DEFAULT_URL_PARAMETER_NAME will be used.


OwCookieStoreCodec

public OwCookieStoreCodec(long namesUrlLifeTime_p)
Constructor

Parameters:
namesUrlLifeTime_p - the time in which a URL will expire (in milliseconds)

OwCookieStoreCodec

public OwCookieStoreCodec(String urlParamenterName_p,
                          long namesUrlLifeTime_p)
Constructor

Parameters:
urlParamenterName_p - name of the encoded URL parameter
namesUrlLifeTime_p - the time in which a cookie will expire (in milliseconds)

OwCookieStoreCodec

public OwCookieStoreCodec(OwAlphabetCoder alphabetCder_p,
                          String urlParamenterName_p,
                          long namesUrlLifeTime_p)
Constructor

Parameters:
alphabetCder_p - the alphabet coder used to generate cookie string values based on unique long values
urlParamenterName_p - name of the encoded URL parameter
namesUrlLifeTime_p - the time in which a cookie will expire (in milliseconds)
Method Detail

addCookieValue

protected abstract void addCookieValue(OwCookieStoreCodec.OwTimedCookieValue timedCookieValue_p)
                                throws OwException
Adds the given OwCookieStoreCodec.OwTimedCookieValue to the cookie store

Parameters:
timedCookieValue_p -
Throws:
OwException

canDecode

public boolean canDecode(OwParameterMap parameterMap_p)
                  throws OwException
Description copied from interface: OwParameterMapCodec
Verifies that this codec can decode the given OwParameterMap without system-errors.

Specified by:
canDecode in interface OwParameterMapCodec
Returns:
true if the given OwParameterMap can be decoded or false otherwise
Throws:
OwException

collectExpiredNames

protected void collectExpiredNames()
                            throws OwException
Throws:
OwException

createTimedCookieCollectList

protected abstract List createTimedCookieCollectList()
                                              throws OwException
Hook method that returns a list of OwCookieStoreCodec.OwTimedCookies to be collected.

Returns:
a List of OwCookieStoreCodec.OwTimedCookie
Throws:
OwException - if the collect List creation fails
See Also:
collectExpiredNames()

decode

public OwParameterMap decode(OwParameterMap parameterMap_p,
                             boolean preserveEncoding_p)
                      throws OwException
Description copied from interface: OwParameterMapCodec
Decodes the given OwParameterMap

Specified by:
decode in interface OwParameterMapCodec
preserveEncoding_p - if true the decoded OwParameterMap will also contain the encoded parameters
Returns:
the decoded OwParameterMap
Throws:
OwException - if the decoding process fails
OwUserOperationException - if the decoding process fails but recovery is possible (non-system-errors)
egg. expired cookies in cookie based encoding scheme

createCookie

protected String createCookie(long uniqueNameIndex_p)
                       throws OwInvalidOperationException,
                              OwException
Parameters:
uniqueNameIndex_p -
Returns:
the cookie URL parameter value for the given unique index
Throws:
OwInvalidOperationException
OwException
Since:
3.2.0.1

encode

public OwParameterMap encode(OwParameterMap parameterMap_p)
                      throws OwException
Description copied from interface: OwParameterMapCodec
Encodes the given OwParameterMap

Specified by:
encode in interface OwParameterMapCodec
Returns:
the encoded OwParameterMap
Throws:
OwException - if the encoding process fails

getCookieValue

protected abstract OwCookieStoreCodec.OwTimedCookieValue getCookieValue(String cookieName_p)
                                                                 throws OwException
Parameters:
cookieName_p -
Returns:
the OwCookieStoreCodec.OwTimedCookieValue for the given cookie
Throws:
OwException

remove

protected abstract void remove(OwCookieStoreCodec.OwTimedCookie timedCookie_p)
                        throws OwException
Removes the given OwCookieStoreCodec.OwTimedCookie from cookie storage.

Parameters:
timedCookie_p -
Throws:
OwException

loadUrlLifeTimeConfig

public static long loadUrlLifeTimeConfig(OwXMLUtil codecConfiguration_p)
                                  throws Exception
Loads XML URLLifeTime configuration : URLLifeTime - tag
Configures the amount of time an encoded URL parameter map is valid.
After that the parameter map is considered expired and links that relay
on are considered out of date / expired and will not produce the desired response.

Attributes :
days = days until the parameter map expires considering the URL parameter map encoding time
hours = hours until the parameter map expires considering the URL parameter map encoding time
minutes = minutes until the parameter map expires considering the URL parameter map encoding time
seconds = seconds until the parameter map expires considering the URL parameter map encoding time

Parameters:
codecConfiguration_p -
Returns:
a long representing the URL life time in milliseconds
Throws:
Exception

loadUrlParameterConfig

public static String loadUrlParameterConfig(OwXMLUtil codecConfiguration_p)
                                     throws Exception
Loads URL parameter XML configuration : URLParameter - tag
The parameter map codec encodes a parameter map into another parameter map containing
one cookie defining parameter.

Attributes :
name = string name of the URL parameter

Parameters:
codecConfiguration_p -
Returns:
the String URL parameter name
Throws:
Exception


Copyright © 2013 Alfresco Business Solutions. All Rights Reserved.