KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cal > TableBean


1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

16 package cal;
17
18 import java.beans.*;
19 import javax.servlet.http.*;
20 import javax.servlet.*;
21 import java.util.Hashtable JavaDoc;
22
23 public class TableBean {
24
25   Hashtable JavaDoc table;
26   JspCalendar JspCal;
27   Entries entries;
28   String JavaDoc date;
29   String JavaDoc name = null;
30   String JavaDoc email = null;
31   boolean processError = false;
32
33   public TableBean () {
34     this.table = new Hashtable JavaDoc (10);
35     this.JspCal = new JspCalendar ();
36     this.date = JspCal.getCurrentDate ();
37   }
38
39   public void setName (String JavaDoc nm) {
40     this.name = nm;
41   }
42
43   public String JavaDoc getName () {
44     return this.name;
45   }
46   
47   public void setEmail (String JavaDoc mail) {
48     this.email = mail;
49   }
50
51   public String JavaDoc getEmail () {
52     return this.email;
53   }
54
55   public String JavaDoc getDate () {
56     return this.date;
57   }
58
59   public Entries getEntries () {
60     return this.entries;
61   }
62
63   public void processRequest (HttpServletRequest request) {
64
65     // Get the name and e-mail.
66
this.processError = false;
67     if (name == null || name.equals("")) setName(request.getParameter ("name"));
68     if (email == null || email.equals("")) setEmail(request.getParameter ("email"));
69     if (name == null || email == null ||
70         name.equals("") || email.equals("")) {
71       this.processError = true;
72       return;
73     }
74
75     // Get the date.
76
String JavaDoc dateR = request.getParameter ("date");
77     if (dateR == null) date = JspCal.getCurrentDate ();
78     else if (dateR.equalsIgnoreCase("next")) date = JspCal.getNextDate ();
79     else if (dateR.equalsIgnoreCase("prev")) date = JspCal.getPrevDate ();
80
81     entries = (Entries) table.get (date);
82     if (entries == null) {
83       entries = new Entries ();
84       table.put (date, entries);
85     }
86
87     // If time is provided add the event.
88
String JavaDoc time = request.getParameter("time");
89     if (time != null) entries.processRequest (request, time);
90   }
91
92   public boolean getProcessError () {
93     return this.processError;
94   }
95 }
96
97
98
99
100
101
102
Popular Tags