001    /*
002    * Copyright 2004 The Apache Software Foundation
003    *
004    * Licensed under the Apache License, Version 2.0 (the "License");
005    * you may not use this file except in compliance with the License.
006    * You may obtain a copy of the License at
007    *
008    *     http://www.apache.org/licenses/LICENSE-2.0
009    *
010    * Unless required by applicable law or agreed to in writing, software
011    * distributed under the License is distributed on an "AS IS" BASIS,
012    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013    * See the License for the specific language governing permissions and
014    * limitations under the License.
015    */
016    package sessions;
017    
018    import javax.servlet.http.*;
019    import java.util.Vector;
020    import java.util.Enumeration;
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    }