KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.nextime.ion.backoffice.form;
2
3 import java.util.Enumeration JavaDoc;
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5
6 import org.apache.regexp.RE;
7 import org.apache.struts.action.ActionError;
8 import org.apache.struts.action.ActionErrors;
9 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionMapping;
11 import org.nextime.ion.backoffice.bean.PropertyBean;
12 import org.nextime.ion.backoffice.bean.SectionTypes;
13 import org.nextime.ion.backoffice.bean.TypeBean;
14
15 public class EditSectionForm extends ActionForm {
16
17     private String JavaDoc name;
18     private String JavaDoc template;
19     private String JavaDoc status;
20     private String JavaDoc workflow;
21
22     /**
23      * @see org.apache.struts.action.ActionForm#validate(ActionMapping, HttpServletRequest)
24      */

25     public ActionErrors myValidate(HttpServletRequest JavaDoc request) {
26         ActionErrors errors = new ActionErrors();
27         if (getTemplate() == null || "".equals(getTemplate())) {
28             ActionError error =
29                 new ActionError("error.editSection.templateMissing");
30             errors.add("template", error);
31         }
32         // validate metadata
33
try {
34             Enumeration JavaDoc names = request.getParameterNames();
35             // dangerous ?
36
TypeBean type = SectionTypes.getSectionBean(null, getTemplate(), request);
37             while (names.hasMoreElements()) {
38                 String JavaDoc name = names.nextElement() + "";
39                 if (name.startsWith("META_")) {
40                     String JavaDoc tname = name.substring(5);
41                     String JavaDoc value = request.getParameter(name);
42                     PropertyBean prop = type.getProperty(tname);
43                     if ("".equals(value.trim())) {
44                         if ("true".equalsIgnoreCase(prop.getRequired())) {
45                             ActionError error =
46                                 new ActionError("error.editSection.propertyMissing");
47                             errors.add("META_" + tname, error);
48                         }
49                     } else {
50                         if (prop.getRegexp() != null) {
51                             RE re = new RE(prop.getRegexp());
52                             if (!re.match(value)) {
53                                 ActionError error =
54                                     new ActionError("error.editSection.propertyMalformed", prop.getErrorMessage());
55                                 errors.add("META_" + tname, error);
56                             }
57                         }
58                     }
59                 }
60             }
61         } catch (Exception JavaDoc e) {
62             e.printStackTrace();
63         }
64         return errors;
65     }
66
67     /**
68      * @see org.apache.struts.action.ActionForm#reset(ActionMapping, HttpServletRequest)
69      */

70     public void reset(ActionMapping arg0, HttpServletRequest JavaDoc arg1) {
71         setName(null);
72         setTemplate(null);
73         setStatus(null);
74         setWorkflow(null);
75     }
76
77     /**
78      * Returns the name.
79      * @return String
80      */

81     public String JavaDoc getName() {
82         return name;
83     }
84
85     /**
86      * Returns the template.
87      * @return String
88      */

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

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

105     public void setTemplate(String JavaDoc template) {
106         this.template = template;
107     }
108
109     /**
110      * Returns the status.
111      * @return String
112      */

113     public String JavaDoc getStatus() {
114         return status;
115     }
116
117     /**
118      * Sets the status.
119      * @param status The status to set
120      */

121     public void setStatus(String JavaDoc status) {
122         this.status = status;
123     }
124
125     /**
126      * Returns the workflow.
127      * @return String
128      */

129     public String JavaDoc getWorkflow() {
130         return workflow;
131     }
132
133     /**
134      * Sets the workflow.
135      * @param workflow The workflow to set
136      */

137     public void setWorkflow(String JavaDoc workflow) {
138         this.workflow = workflow;
139     }
140
141 }
142
Popular Tags