KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > form > PublishPublicationForm


1 package org.nextime.ion.backoffice.form;
2
3 import java.text.SimpleDateFormat JavaDoc;
4 import java.util.Date JavaDoc;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7
8 import org.apache.struts.action.ActionError;
9 import org.apache.struts.action.ActionErrors;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionMapping;
12
13 public class PublishPublicationForm extends ActionForm {
14
15     private String JavaDoc type;
16     private String JavaDoc dateBegin;
17     private String JavaDoc dateEnd;
18
19     /**
20      * @see org.apache.struts.action.ActionForm#validate(ActionMapping, HttpServletRequest)
21      */

22     public ActionErrors myValidate(HttpServletRequest JavaDoc request) {
23         ActionErrors errors = new ActionErrors();
24         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc("dd/MM/yyyy");
25         if (getType() == null) {
26             ActionError error = new ActionError("error.general.missingField");
27             errors.add("type", error);
28         } else {
29             if (getType().equals("P_D")) {
30                 Date JavaDoc dateBegin = null;
31                 Date JavaDoc dateEnd = null;
32                 try {
33                     dateBegin = formatter.parse(getDateBegin());
34                 } catch (Exception JavaDoc e) {
35                     ActionError error =
36                         new ActionError("error.general.badDate");
37                     errors.add("date", error);
38                 }
39                 if (dateBegin != null) {
40                     try {
41                         dateEnd = formatter.parse(getDateEnd());
42                     } catch (Exception JavaDoc e) {
43                         ActionError error =
44                             new ActionError("error.general.badDate");
45                         errors.add("date", error);
46                     }
47                 }
48                 if (dateBegin != null && dateEnd != null) {
49                     if (dateEnd.before(dateBegin)) {
50                         ActionError error =
51                             new ActionError("error.publishPublication.badEnd");
52                         errors.add("date", error);
53                     }
54                 }
55             }
56         }
57         return errors;
58     }
59
60     /**
61      * @see org.apache.struts.action.ActionForm#reset(ActionMapping, HttpServletRequest)
62      */

63     public void reset(ActionMapping arg0, HttpServletRequest JavaDoc arg1) {
64         setType(null);
65         setDateBegin(null);
66         setDateEnd(null);
67     }
68
69     /**
70      * Returns the dateBegin.
71      * @return String
72      */

73     public String JavaDoc getDateBegin() {
74         return dateBegin;
75     }
76
77     /**
78      * Returns the dateEnd.
79      * @return String
80      */

81     public String JavaDoc getDateEnd() {
82         return dateEnd;
83     }
84
85     /**
86      * Returns the type.
87      * @return String
88      */

89     public String JavaDoc getType() {
90         return type;
91     }
92
93     /**
94      * Sets the dateBegin.
95      * @param dateBegin The dateBegin to set
96      */

97     public void setDateBegin(String JavaDoc dateBegin) {
98         this.dateBegin = dateBegin;
99     }
100
101     /**
102      * Sets the dateEnd.
103      * @param dateEnd The dateEnd to set
104      */

105     public void setDateEnd(String JavaDoc dateEnd) {
106         this.dateEnd = dateEnd;
107     }
108
109     /**
110      * Sets the type.
111      * @param type The type to set
112      */

113     public void setType(String JavaDoc type) {
114         this.type = type;
115     }
116
117 }
118
Popular Tags