DummyCart.java
01 /**
02  *
03  * All content copyright (c) 2003-2008 Terracotta, Inc.,
04  * except as may otherwise be noted in a separate copyright notice.
05  * All rights reserved.
06  *
07  */
08 package demo.cart;
09 
10 import javax.servlet.http.*;
11 import java.util.Vector;
12 import java.util.Enumeration;
13 
14 /**
15  *  Description of the Class
16  *
17  *@author    Terracotta, Inc.
18  */
19 public class DummyCart {
20    Vector v = new Vector();
21    String submit = null;
22    String item = null;
23 
24    public void setItem(String name) {
25       item = name;
26    }
27 
28    public void setSubmit(String s) {
29       submit = s;
30    }
31 
32    public String[] getItems() {
33       String[] s = new String[v.size()];
34       v.copyInto(s);
35       return s;
36    }
37 
38    public void processRequest(HttpServletRequest request) {
39       // null value for submit - user hit enter instead of clicking on
40       // "add" or "remove"
41       if (submit != null && item != null) {
42          if (submit.equals("add")) {
43             addItem(item);
44          }
45          else if (submit.equals("remove")) {
46             removeItem(item);
47          }
48       }
49 
50       // reset at the end of the request
51       reset();
52    }
53 
54    private void addItem(String name) {
55       v.addElement(name);
56    }
57 
58    private void removeItem(String name) {
59       v.removeElement(name);
60    }
61 
62    // reset
63    private void reset() {
64       submit = null;
65       item = null;
66    }
67 }