001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/jsf/backingbean/LocalMeetingModel.java $
003: * $Id: LocalMeetingModel.java 20144 2007-01-06 01:30:09Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.section.jsf.backingbean;
021:
022: import java.io.Serializable;
023: import java.sql.Time;
024: import java.util.Calendar;
025: import java.util.GregorianCalendar;
026:
027: import org.apache.commons.lang.StringUtils;
028: import org.apache.commons.lang.builder.ToStringBuilder;
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.section.api.coursemanagement.Meeting;
032: import org.sakaiproject.tool.section.jsf.JsfUtil;
033:
034: public class LocalMeetingModel implements Meeting, Serializable {
035: private static final Log log = LogFactory
036: .getLog(LocalMeetingModel.class);
037: private static final long serialVersionUID = 1L;
038:
039: public LocalMeetingModel() {
040: startTimeAm = true;
041: endTimeAm = true;
042: startTimeString = JsfUtil
043: .getLocalizedMessage("section_start_time_default");
044: endTimeString = JsfUtil
045: .getLocalizedMessage("section_end_time_default");
046: }
047:
048: public LocalMeetingModel(Meeting meeting) {
049: this .location = meeting.getLocation();
050: this .monday = meeting.isMonday();
051: this .tuesday = meeting.isTuesday();
052: this .wednesday = meeting.isWednesday();
053: this .thursday = meeting.isThursday();
054: this .friday = meeting.isFriday();
055: this .saturday = meeting.isSaturday();
056: this .sunday = meeting.isSunday();
057: this .startTimeString = JsfUtil.convertTimeToString(meeting
058: .getStartTime());
059: if (startTimeString == null) {
060: startTimeString = JsfUtil
061: .getLocalizedMessage("section_start_time_default");
062: }
063:
064: this .endTimeString = JsfUtil.convertTimeToString(meeting
065: .getEndTime());
066: if (endTimeString == null) {
067: endTimeString = JsfUtil
068: .getLocalizedMessage("section_end_time_default");
069: }
070:
071: Calendar cal = new GregorianCalendar();
072: if (meeting.getStartTime() == null) {
073: this .startTimeAm = true;
074: } else {
075: cal.setTime(meeting.getStartTime());
076: if (log.isDebugEnabled())
077: log.debug("cal.get(Calendar.AM_PM) = "
078: + cal.get(Calendar.AM_PM));
079: this .startTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM);
080: }
081: if (meeting.getEndTime() == null) {
082: this .endTimeAm = true;
083: } else {
084: cal.setTime(meeting.getEndTime());
085: if (log.isDebugEnabled())
086: log.debug("cal.get(Calendar.AM_PM) = "
087: + cal.get(Calendar.AM_PM));
088: this .endTimeAm = (cal.get(Calendar.AM_PM) == Calendar.AM);
089: }
090: }
091:
092: private String location, startTimeString, endTimeString;
093: private boolean monday, tuesday, wednesday, thursday, friday,
094: saturday, sunday;
095: private boolean startTimeAm, endTimeAm;
096:
097: public boolean isEmpty() {
098: return !monday
099: && !tuesday
100: && !wednesday
101: && !thursday
102: && !friday
103: && !saturday
104: && !sunday
105: && (StringUtils.trimToNull(startTimeString) == null || isStartTimeDefault())
106: && (StringUtils.trimToNull(endTimeString) == null || isEndTimeDefault())
107: && StringUtils.trimToNull(location) == null;
108: }
109:
110: public Time getStartTime() {
111: if (isStartTimeDefault()) {
112: return null;
113: }
114: return JsfUtil
115: .convertStringToTime(startTimeString, startTimeAm);
116: }
117:
118: public Time getEndTime() {
119: if (isEndTimeDefault()) {
120: return null;
121: }
122: return JsfUtil.convertStringToTime(endTimeString, endTimeAm);
123: }
124:
125: public String getEndTimeString() {
126: return endTimeString;
127: }
128:
129: public void setEndTimeString(String endTimeString) {
130: this .endTimeString = endTimeString;
131: }
132:
133: // Must use a string due to http://issues.apache.org/jira/browse/MYFACES-570
134: public String getEndTimeAmString() {
135: return Boolean.toString(endTimeAm);
136: }
137:
138: // Must use a string due to http://issues.apache.org/jira/browse/MYFACES-570
139: public void setEndTimeAmString(String endTimeAm) {
140: this .endTimeAm = Boolean.parseBoolean(endTimeAm);
141: }
142:
143: public boolean isFriday() {
144: return friday;
145: }
146:
147: public void setFriday(boolean friday) {
148: this .friday = friday;
149: }
150:
151: public String getLocation() {
152: return location;
153: }
154:
155: public void setLocation(String location) {
156: this .location = location;
157: }
158:
159: public boolean isMonday() {
160: return monday;
161: }
162:
163: public void setMonday(boolean monday) {
164: this .monday = monday;
165: }
166:
167: public boolean isSaturday() {
168: return saturday;
169: }
170:
171: public void setSaturday(boolean saturday) {
172: this .saturday = saturday;
173: }
174:
175: public String getStartTimeString() {
176: return startTimeString;
177: }
178:
179: public void setStartTimeString(String startTimeString) {
180: this .startTimeString = startTimeString;
181: }
182:
183: // Must use a string due to http://issues.apache.org/jira/browse/MYFACES-570
184: public String getStartTimeAmString() {
185: return Boolean.toString(startTimeAm);
186: }
187:
188: // Must use a string due to http://issues.apache.org/jira/browse/MYFACES-570
189: public void setStartTimeAmString(String startTimeAm) {
190: this .startTimeAm = Boolean.parseBoolean(startTimeAm);
191: if (log.isDebugEnabled())
192: log.debug("String " + startTimeAm
193: + " caused startTimeAm to be set to "
194: + this .startTimeAm);
195: }
196:
197: public boolean isStartTimeAm() {
198: return startTimeAm;
199: }
200:
201: public boolean isEndTimeAm() {
202: return endTimeAm;
203: }
204:
205: public boolean isSunday() {
206: return sunday;
207: }
208:
209: public void setSunday(boolean sunday) {
210: this .sunday = sunday;
211: }
212:
213: public boolean isThursday() {
214: return thursday;
215: }
216:
217: public void setThursday(boolean thursday) {
218: this .thursday = thursday;
219: }
220:
221: public boolean isTuesday() {
222: return tuesday;
223: }
224:
225: public void setTuesday(boolean tuesday) {
226: this .tuesday = tuesday;
227: }
228:
229: public boolean isWednesday() {
230: return wednesday;
231: }
232:
233: public void setWednesday(boolean wednesday) {
234: this .wednesday = wednesday;
235: }
236:
237: public String toString() {
238: return new ToStringBuilder(this ).append(location).append(
239: startTimeString).append(startTimeAm).append(
240: endTimeString).append(endTimeAm).append(monday).append(
241: tuesday).append(wednesday).append(thursday).append(
242: friday).append(saturday).append(sunday).toString();
243: }
244:
245: public boolean isStartTimeDefault() {
246: return JsfUtil
247: .getLocalizedMessage("section_start_time_default")
248: .equals(startTimeString);
249: }
250:
251: public boolean isEndTimeDefault() {
252: return JsfUtil.getLocalizedMessage("section_end_time_default")
253: .equals(endTimeString);
254: }
255:
256: public boolean isLocationDefault() {
257: return JsfUtil.getLocalizedMessage("section_location_default")
258: .equals(location);
259: }
260: }
|