e.g. Calendar Search Help
You must enter a value before pressing Search
xplanner

Class: com.technoetic.xplanner.forms.AggregateTimesheetForm   ©

 OK to copy?
001 package com.technoetic.xplanner.forms;
002 
003 import com.technoetic.xplanner.domain.virtual.Timesheet;
004 import org.apache.struts.Globals;
005 import org.apache.struts.action.ActionError;
006 import org.apache.struts.action.ActionErrors;
007 import org.apache.struts.action.ActionMapping;
008 
009 import javax.servlet.http.HttpServletRequest;
010 import java.text.ParseException;
011 import java.text.SimpleDateFormat;
012 import java.util.ArrayList;
013 import java.util.Calendar;
014 import java.util.Collection;
015 import java.util.Date;
016 
017 public class AggregateTimesheetForm
018         extends AbstractEditorForm {
019 
020     private java.util.Date startDate;
021     private String startDateString;
022     private java.util.Date endDate;
023     private String endDateString;
024     private SimpleDateFormat dateFormat;
025     private Timesheet timesheet;
026     private Collection allPeople;
027     private String[] selectedPeople;
028 
029     public ActionErrors validate(ActionMapping mapping,
030             HttpServletRequest request) {
031         ActionErrors errors = new ActionErrors();
032 
033         if (this.dateFormat == null) {
034             String format = getResources(request).getMessage("format.date");
035             dateFormat = new SimpleDateFormat(format);
036         }
037 
038         Date startDate = null;
039         if (isPresent(this.startDateString)) {
040             try {
041                 startDate = dateFormat.parse(this.startDateString);
042                 this.setStartDate(startDate);
043             } catch (ParseException ex) {
044                 errors.add(ActionErrors.GLOBAL_ERROR,
045                         new ActionError("timesheet.error.unparsable_date"));
046                 request.setAttribute(Globals.ERROR_KEY, errors);
047                 return errors;
048             }
049         }
050 
051         Date endDate = null;
052         if (isPresent(this.endDateString)) {
053             try {
054                 endDate = dateFormat.parse(this.endDateString);
055                 this.setEndDate(endDate);
056             } catch (ParseException ex) {
057                 errors.add(ActionErrors.GLOBAL_ERROR,
058                         new ActionError("timesheet.error.unparsable_date"));
059                 request.setAttribute(Globals.ERROR_KEY, errors);
060                 return errors;
061             }
062         }
063 
064         return errors;
065     }
066 
067     public void reset(ActionMapping mapping, HttpServletRequest request) {
068         super.reset(mapping, request);
069         this.endDate = this.getWeekEndDate();
070         this.startDate = this.getWeekStartDate();
071         this.timesheet = new Timesheet(this.startDate, this.endDate);
072         this.allPeople = new ArrayList();
073         this.selectedPeople = new String[]{};
074     }
075 
076     public java.util.Date getStartDate() {
077         return startDate;
078     }
079 
080     public void setStartDate(java.util.Date startDate) {
081         this.startDate = startDate;
082     }
083 
084     public String getStartDateString() {
085         if (dateFormat == null) {
Rate086             return this.getStartDate().toString();
087         }
088         return dateFormat.format(this.getStartDate());
089     }
090 
091     public void setStartDateString(String start) {
092         this.startDateString = start;
093     }
094 
095     public Date getEndDate() {
096         return endDate;
097     }
098 
099     public void setEndDate(Date endDate) {
100         this.endDate = endDate;
101     }
102 
103     public String getEndDateString() {
104         if (dateFormat == null) {
Rate105             return this.getEndDate().toString();
106         }
107         return dateFormat.format(this.getEndDate());
108     }
109 
110     public void setEndDateString(String end) {
111         this.endDateString = end;
112     }
113 
114     public Timesheet getTimesheet() {
115         return timesheet;
116     }
117 
118     public void setTimesheet(Timesheet timesheet) {
119         this.timesheet = timesheet;
120     }
121 
122     private Date getWeekEndDate() {
123         Calendar cal = Calendar.getInstance();
124         cal.set(Calendar.HOUR, 0);
125         cal.set(Calendar.MINUTE, 0);
126         cal.set(Calendar.SECOND, 0);
127         cal.set(Calendar.MILLISECOND, 0);
128         int weekday = cal.get(Calendar.DAY_OF_WEEK);
129         cal.add(Calendar.DATE, 7 - weekday);
130         return cal.getTime();
131     }
132 
133     private Date getWeekStartDate() {
134         Calendar cal = Calendar.getInstance();
135         cal.set(Calendar.HOUR, 0);
136         cal.set(Calendar.MINUTE, 0);
137         cal.set(Calendar.SECOND, 0);
138         cal.set(Calendar.MILLISECOND, 0);
139         int weekday = cal.get(Calendar.DAY_OF_WEEK);
140         cal.add(Calendar.DATE, -weekday + 1);
141         return cal.getTime();
142     }
143 
144     private boolean isPresent(String value) {
145         return value != null && !value.equals("") && !value.equals("null");
146     }
147 
148     public void setDateFormat(SimpleDateFormat format) {
149         this.dateFormat = format;
150     }
151 
152     public SimpleDateFormat getDateFormat() {
153         return this.dateFormat;
154     }
155 
156     public Collection getAllPeople() {
157         return allPeople;
158     }
159 
160     public void setAllPeople(Collection allPeople) {
161         this.allPeople = allPeople;
162     }
163 
164     public String[] getSelectedPeople() {
165         return selectedPeople;
166     }
167 
168     public void setSelectedPeople(String[] selectedPeople) {
169         this.selectedPeople = selectedPeople;
170     }
171 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
86 0% of 0
105 0% of 0