com.elasticpath.sfweb.util.impl
Class RequestHelperImpl

java.lang.Object
  extended by com.elasticpath.sfweb.util.impl.RequestHelperImpl
All Implemented Interfaces:
RequestHelper

public class RequestHelperImpl
extends java.lang.Object
implements RequestHelper

The default implementation of RequestHelper.


Constructor Summary
RequestHelperImpl()
           
 
Method Summary
 java.lang.String getCookieValue(javax.servlet.http.HttpServletRequest request, java.lang.String cookieName)
          Returns the value of a cookie with the specified name.
 ElasticPath getElasticPath()
          Get the ElasticPath singleton.
 int getIntParameterOrAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name, int defaultVal)
          Get an int parameter or attribute, with a fallback value.
 java.lang.Long getLongParameter(javax.servlet.http.HttpServletRequest request, java.lang.String parameterName)
          Retrieve the given parameter as Long from the given request.
 ShoppingCart getShoppingCart(javax.servlet.http.HttpServletRequest request)
          Return a ShoppingCart instance if there is one stored in http session.
 java.lang.String getStringParameterOrAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String defaultVal)
          Get a string parameter or attribute, with a fallback value.
 java.lang.String getUrl(javax.servlet.http.HttpServletRequest request)
          Retrive the absolute url from the given request.
 void setElasticPath(ElasticPath elasticpath)
          Inject the ElasticPath singleton.
 void setShoppingCart(javax.servlet.http.HttpServletRequest request, ShoppingCart shoppingCart)
          Set a ShoppingCart into http sessino.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestHelperImpl

public RequestHelperImpl()
Method Detail

getCookieValue

public java.lang.String getCookieValue(javax.servlet.http.HttpServletRequest request,
                                       java.lang.String cookieName)
Returns the value of a cookie with the specified name.

Specified by:
getCookieValue in interface RequestHelper
Parameters:
request - The Http request to retrieve cookies from
cookieName - The name of the cookie to be retrieved
Returns:
the value of the cookie as a string

getElasticPath

public ElasticPath getElasticPath()
Get the ElasticPath singleton.

Specified by:
getElasticPath in interface RequestHelper
Returns:
elasticpath the ElasticPath singleton.

getIntParameterOrAttribute

public int getIntParameterOrAttribute(javax.servlet.http.HttpServletRequest request,
                                      java.lang.String name,
                                      int defaultVal)
Get an int parameter or attribute, with a fallback value. Never throws an exception. Can pass a distinguished value as default to enable checks of whether it was supplied.

Specified by:
getIntParameterOrAttribute in interface RequestHelper
Parameters:
request - current HTTP request
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the int value of parameter or attribute if it exists, otherwise, returns a fallback value

getLongParameter

public java.lang.Long getLongParameter(javax.servlet.http.HttpServletRequest request,
                                       java.lang.String parameterName)
                                throws EpSfWebException
Retrieve the given parameter as Long from the given request.

Specified by:
getLongParameter in interface RequestHelper
Parameters:
request - the request
parameterName - the parameter name
Returns:
a Long type instance if the parameter is set, otherwise null
Throws:
EpSfWebException - in case of any error happens

getShoppingCart

public ShoppingCart getShoppingCart(javax.servlet.http.HttpServletRequest request)
                             throws EpSfWebException
Return a ShoppingCart instance if there is one stored in http session. Otherwise, create a new one and return it.

Specified by:
getShoppingCart in interface RequestHelper
Parameters:
request - the http request
Returns:
a ShoppingCart instance
Throws:
EpSfWebException - document me

getStringParameterOrAttribute

public java.lang.String getStringParameterOrAttribute(javax.servlet.http.HttpServletRequest request,
                                                      java.lang.String name,
                                                      java.lang.String defaultVal)
Get a string parameter or attribute, with a fallback value. Never throws an exception.

Specified by:
getStringParameterOrAttribute in interface RequestHelper
Parameters:
request - current HTTP request
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the int value of parameter or attribute if it exists, otherwise, returns a fallback value

getUrl

public java.lang.String getUrl(javax.servlet.http.HttpServletRequest request)
Retrive the absolute url from the given request.

Specified by:
getUrl in interface RequestHelper
Parameters:
request - the request
Returns:
the absolute url

setElasticPath

public void setElasticPath(ElasticPath elasticpath)
Inject the ElasticPath singleton.

Specified by:
setElasticPath in interface RequestHelper
Parameters:
elasticpath - the ElasticPath singleton.

setShoppingCart

public void setShoppingCart(javax.servlet.http.HttpServletRequest request,
                            ShoppingCart shoppingCart)
                     throws EpSfWebException
Set a ShoppingCart into http sessino.

Specified by:
setShoppingCart in interface RequestHelper
Parameters:
request - the http request
shoppingCart - the shopping cart to save
Throws:
EpSfWebException - when request or shoppingCart is null