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 cal;
017
018 import java.beans.*;
019 import javax.servlet.http.*;
020 import javax.servlet.*;
021 import java.util.Hashtable;
022
023 public class TableBean {
024
025 Hashtable table;
026 JspCalendar JspCal;
027 Entries entries;
028 String date;
029 String name = null;
030 String email = null;
031 boolean processError = false;
032
033 public TableBean () {
034 this.table = new Hashtable (10);
035 this.JspCal = new JspCalendar ();
036 this.date = JspCal.getCurrentDate ();
037 }
038
039 public void setName (String nm) {
040 this.name = nm;
041 }
042
043 public String getName () {
044 return this.name;
045 }
046
047 public void setEmail (String mail) {
048 this.email = mail;
049 }
050
051 public String getEmail () {
052 return this.email;
053 }
054
055 public String getDate () {
056 return this.date;
057 }
058
059 public Entries getEntries () {
060 return this.entries;
061 }
062
063 public void processRequest (HttpServletRequest request) {
064
065 // Get the name and e-mail.
066 this.processError = false;
067 if (name == null || name.equals("")) setName(request.getParameter ("name"));
068 if (email == null || email.equals("")) setEmail(request.getParameter ("email"));
069 if (name == null || email == null ||
070 name.equals("") || email.equals("")) {
071 this.processError = true;
072 return;
073 }
074
075 // Get the date.
076 String dateR = request.getParameter ("date");
077 if (dateR == null) date = JspCal.getCurrentDate ();
078 else if (dateR.equalsIgnoreCase("next")) date = JspCal.getNextDate ();
079 else if (dateR.equalsIgnoreCase("prev")) date = JspCal.getPrevDate ();
080
081 entries = (Entries) table.get (date);
082 if (entries == null) {
083 entries = new Entries ();
084 table.put (date, entries);
085 }
086
087 // If time is provided add the event.
088 String time = request.getParameter("time");
089 if (time != null) entries.processRequest (request, time);
090 }
091
092 public boolean getProcessError () {
093 return this.processError;
094 }
095 }
096
097
098
099
100
101