001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package sessions;
018
019 import javax.servlet.http.*;
020 import java.util.Vector;
021
022 public class DummyCart {
023 Vector v = new Vector();
024 String submit = null;
025 String item = null;
026
027 private void addItem(String name) {
028 v.addElement(name);
029 }
030
031 private void removeItem(String name) {
032 v.removeElement(name);
033 }
034
035 public void setItem(String name) {
036 item = name;
037 }
038
039 public void setSubmit(String s) {
040 submit = s;
041 }
042
043 public String[] getItems() {
044 String[] s = new String[v.size()];
045 v.copyInto(s);
046 return s;
047 }
048
049 public void processRequest(HttpServletRequest request) {
050 // null value for submit - user hit enter instead of clicking on
051 // "add" or "remove"
052 if (submit == null)
053 addItem(item);
054
055 if (submit.equals("add"))
056 addItem(item);
057 else if (submit.equals("remove"))
058 removeItem(item);
059
060 // reset at the end of the request
061 reset();
062 }
063
064 // reset
065 private void reset() {
066 submit = null;
067 item = null;
068 }
069 }