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 java.util.Vector;
020
021 import javax.servlet.http.HttpServletRequest;
022
023 public class DummyCart {
024 Vector v = new Vector();
025 String submit = null;
026 String item = null;
027
028 private void addItem(String name) {
029 v.addElement(name);
030 }
031
032 private void removeItem(String name) {
033 v.removeElement(name);
034 }
035
036 public void setItem(String name) {
037 item = name;
038 }
039
040 public void setSubmit(String s) {
041 submit = s;
042 }
043
044 public String[] getItems() {
045 String[] s = new String[v.size()];
046 v.copyInto(s);
047 return s;
048 }
049
050 public void processRequest(HttpServletRequest request) {
051 // null value for submit - user hit enter instead of clicking on
052 // "add" or "remove"
053 if (submit == null)
054 addItem(item);
055
056 if (submit.equals("add"))
057 addItem(item);
058 else if (submit.equals("remove"))
059 removeItem(item);
060
061 // reset at the end of the request
062 reset();
063 }
064
065 // reset
066 private void reset() {
067 submit = null;
068 item = null;
069 }
070 }