org.paneris.melati.shopping
Class Trolley

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.melati.servlet.ConfigServlet
              extended by org.melati.servlet.PoemServlet
                  extended by org.melati.servlet.TemplateServlet
                      extended by org.paneris.melati.shopping.Trolley
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class Trolley
extends org.melati.servlet.TemplateServlet

A servlet that handles the user's interaction with the Shopping Trolley.

See Also:
ShoppingTrolley, ShoppingTrolleyItem, DefaultShoppingTrolley, DefaultShoppingTrolleyItem, Serialized Form

Field Summary
 MelatiShoppingConfig config
           
 
Fields inherited from class org.melati.servlet.TemplateServlet
templateEngine
 
Fields inherited from class org.melati.servlet.ConfigServlet
melatiConfig, sysAdminEmail, sysAdminName
 
Constructor Summary
Trolley()
           
 
Method Summary
protected  java.lang.String Abandon(org.melati.Melati melati)
          Abandon a trolley.
protected  java.lang.String Add(org.melati.Melati melati, java.lang.Integer id, double quantity)
          Add a single item to the trolley, or add to the quantity already in the trolley.
protected  void assertLogin(org.melati.Melati melati)
          Force a user to login.
protected  java.lang.String Confirm(org.melati.Melati melati)
          Update the user's information and return the confirmation page.
protected  java.lang.String Details(org.melati.Melati melati)
          Return the page where the user enters their details.
protected  java.lang.String doTemplateRequest(org.melati.Melati melati, org.melati.template.ServletTemplateContext context)
          Main entry point for this servlet.
 void init(javax.servlet.ServletConfig conf)
          Inititialise the Shopping Trolley Engine.
protected  java.lang.String Load(org.melati.Melati melati, java.lang.Integer id)
          Load the trolley from something persistent.
protected  java.lang.String MultipleAdd(org.melati.Melati melati)
          Add multiple items to the trolley, or add to the quantities already in the trolley.
protected  java.lang.String Paid(org.melati.Melati melati)
          Complete the user's shopping experience, and remove their Shopping Trolley from the Session.
protected  org.melati.PoemContext poemContext(org.melati.Melati melati)
          Override the building of the PoemContext in order to glean the additional information required for the Shopping Trolley system.
protected  java.lang.String Remove(org.melati.Melati melati, java.lang.Integer id)
          Remove a single item from the trolley, the product is specified on the pathinfo which should be of the form: ///Remove/
protected  java.lang.String Save(org.melati.Melati melati)
          Load the trolley from something persistent.
protected  java.lang.String Set(org.melati.Melati melati, java.lang.Integer id, double quantity)
          Set the quantity of an item in the trolley, the product and new quantity is specified on the pathinfo which should be of the form: ////Set/
protected  java.lang.String shoppingTemplate(org.melati.Melati melati, java.lang.String name)
          Create the full name of the template to be returned.
protected  java.lang.String Update(org.melati.Melati melati)
          Update the entire trolley, changing quantities and removing items.
protected  java.lang.String View(org.melati.Melati melati)
          View the trolley.
 
Methods inherited from class org.melati.servlet.TemplateServlet
addExtension, doPoemRequest, error, prePoemSession
 
Methods inherited from class org.melati.servlet.PoemServlet
_handleException, dbBusyMessage, destroy, doConfiguredRequest, getSysAdminEmail, getSysAdminName, handleException, poemContextWithLDB
 
Methods inherited from class org.melati.servlet.ConfigServlet
doGet, doPost, melatiConfig, setSysAdminEmail, setSysAdminName, writeConnectionPendingException, writeError
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

public MelatiShoppingConfig config
Constructor Detail

Trolley

public Trolley()
Method Detail

init

public void init(javax.servlet.ServletConfig conf)
          throws javax.servlet.ServletException
Inititialise the Shopping Trolley Engine. This will load a file called org.paneris.melati.shopping.ShoppingTrolley.properties in order to find the classes that implement this shopping implementation.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class org.melati.servlet.TemplateServlet
Parameters:
conf - - the Servlet's config parameters
Throws:
javax.servlet.ServletException
See Also:
MelatiShoppingConfig

doTemplateRequest

protected java.lang.String doTemplateRequest(org.melati.Melati melati,
                                             org.melati.template.ServletTemplateContext context)
                                      throws java.lang.Exception
Main entry point for this servlet.

Specified by:
doTemplateRequest in class org.melati.servlet.TemplateServlet
Parameters:
melati - - the melati for this request
context - - the Template Context for this request
Returns:
- the name of the template to be returned to the user
Throws:
org.melati.servlet.InvalidUsageException - - if this request has an invalid form
java.lang.Exception

Load

protected java.lang.String Load(org.melati.Melati melati,
                                java.lang.Integer id)
                         throws org.melati.util.InstantiationPropertyException
Load the trolley from something persistent.

Parameters:
melati - - the melati for this request
id - - an id that can be used to identify the trolley to be loaded
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Save

protected java.lang.String Save(org.melati.Melati melati)
                         throws org.melati.util.InstantiationPropertyException
Load the trolley from something persistent.

Parameters:
melati - - the melati for this request
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

View

protected java.lang.String View(org.melati.Melati melati)
                         throws org.melati.util.InstantiationPropertyException
View the trolley.

Parameters:
melati - - the melati for this request
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - if we cannot construct the trolley

Update

protected java.lang.String Update(org.melati.Melati melati)
                           throws org.melati.util.InstantiationPropertyException
Update the entire trolley, changing quantities and removing items. The POSTed form is analysed for fields with names of the form: trolleyitem__quantity - the new quantity of the item (if set) trolleyitem__deleted - remove this item from the trolley (if set) items will also be deleted if the quantity is set to 0

Parameters:
melati - - the melati for this request
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - if we cannot construct the trolley

MultipleAdd

protected java.lang.String MultipleAdd(org.melati.Melati melati)
                                throws org.melati.util.InstantiationPropertyException
Add multiple items to the trolley, or add to the quantities already in the trolley. The POSTed form is analysed for fields with names of the form: product_ - the id of the item to be added quantity_ - the quantity to add If no quantity is set, a single item will be added.

Parameters:
melati - - the melati for this request
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Add

protected java.lang.String Add(org.melati.Melati melati,
                               java.lang.Integer id,
                               double quantity)
                        throws org.melati.util.InstantiationPropertyException
Add a single item to the trolley, or add to the quantity already in the trolley. The product is specified on the pathinfo which should be of the form: ////Add/ if no quantity is set, a single item will be added. The form parmaeters will be parsed to see if they contain "price" and/or "description" fields. if they are present, they will be used to set up the item

Parameters:
melati - - the melati for this request
id - - the id of the item to be added
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Remove

protected java.lang.String Remove(org.melati.Melati melati,
                                  java.lang.Integer id)
                           throws org.melati.util.InstantiationPropertyException
Remove a single item from the trolley, the product is specified on the pathinfo which should be of the form: ///Remove/

Parameters:
melati - - the melati for this request
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Set

protected java.lang.String Set(org.melati.Melati melati,
                               java.lang.Integer id,
                               double quantity)
                        throws org.melati.util.InstantiationPropertyException
Set the quantity of an item in the trolley, the product and new quantity is specified on the pathinfo which should be of the form: ////Set/

Parameters:
melati - - the melati for this request
id - - the id of the item to be removed
Returns:
- "Trolley" - the page where users manipulate their Shopping Trolley
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Details

protected java.lang.String Details(org.melati.Melati melati)
                            throws org.melati.util.InstantiationPropertyException
Return the page where the user enters their details.

Parameters:
melati - - the melati for this request
Returns:
- "Details" - the page where users enter their details
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Confirm

protected java.lang.String Confirm(org.melati.Melati melati)
                            throws org.melati.util.InstantiationPropertyException
Update the user's information and return the confirmation page.

Parameters:
melati - - the melati for this request
Returns:
- "Confirm" - the page where users confirm their order
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Paid

protected java.lang.String Paid(org.melati.Melati melati)
                         throws org.melati.util.InstantiationPropertyException
Complete the user's shopping experience, and remove their Shopping Trolley from the Session. If you need to do something (like send an email) following confirmation of payment, define the method in ShoppingTrolley.java: public void confirmPayment(Melati melati) {} Because the callback request (typically) comes from the Payment Server, you will not have the user's shoping trolley (Session) available to them. You will therefore need to get whatever information you require from something persistent. The alternative is to get the Payment Server to generate the emails (or whatever) for you. Most Payment Servers offer this facility.

Parameters:
melati - - the melati for this request
Returns:
- "Paid" - a message thanking the user for their order
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

Abandon

protected java.lang.String Abandon(org.melati.Melati melati)
                            throws org.melati.util.InstantiationPropertyException
Abandon a trolley.

Parameters:
melati - - the melati for this request
Returns:
- "Trolley" - the initial trolley page
Throws:
org.melati.util.InstantiationPropertyException - - if we cannot construct trolley

assertLogin

protected void assertLogin(org.melati.Melati melati)
                    throws org.melati.util.InstantiationPropertyException
Force a user to login.

Parameters:
melati - - the melati for this request
Throws:
org.melati.util.InstantiationPropertyException

shoppingTemplate

protected java.lang.String shoppingTemplate(org.melati.Melati melati,
                                            java.lang.String name)
Create the full name of the template to be returned.

Parameters:
melati - - the melati for this request (not used)
name - - the name of the template
Returns:
- the full path to the template

poemContext

protected org.melati.PoemContext poemContext(org.melati.Melati melati)
                                      throws org.melati.servlet.PathInfoException
Override the building of the PoemContext in order to glean the additional information required for the Shopping Trolley system.

Overrides:
poemContext in class org.melati.servlet.PoemServlet
Parameters:
melati - - the melati for this request
Returns:
- the ShoppingContext with as many bits set up as possible
Throws:
org.melati.servlet.PathInfoException - - if we don't understand the PathInfo


Copyright © 1997-2009 PanEris. All Rights Reserved.