001: package hero.struts.forms;
002:
003: import javax.servlet.http.HttpServletRequest;
004: import org.apache.struts.action.ActionError;
005: import org.apache.struts.action.ActionErrors;
006: import org.apache.struts.action.ActionForm;
007: import org.apache.struts.action.ActionMapping;
008:
009: /**
010: * Form bean for the Hook. This form has the following fields,
011: * with default values in square brackets:
012: * <ul>
013: * <li><b>name</b> - The name of the hook. [REQUIRED]
014: * <li><b>event</b> - The event for this hook. [REQUIRED]
015: * <li><b>type</b> - The hook type [REQUIRED]
016: * </ul>
017: *
018: * @author Miguel Valdes Faura
019: * @version $Revision: 1.1 $ $Date: 2004/07/30 14:57:57 $
020: */
021:
022: public final class HookForm extends ActionForm {
023:
024: // =================================================== Instance Variables
025:
026: /**
027: * The hook name
028: */
029: private String name = null;
030:
031: /**
032: * The hook event
033: */
034:
035: private String event = null;
036:
037: /**
038: * The hook type
039: */
040:
041: private String type = null;
042:
043: /**
044: * The hook value
045: */
046: private String value = null;
047:
048: // =========================================================== Properties
049:
050: /**
051: * Return the hook name
052: */
053: public String getName() {
054:
055: return (this .name);
056:
057: }
058:
059: /**
060: * Set the hook name
061: *
062: */
063: public void setName(String name) {
064:
065: this .name = name;
066:
067: }
068:
069: /**
070: * Return the hook event
071: */
072: public String getEvent() {
073:
074: return (this .event);
075:
076: }
077:
078: /**
079: * Set the hook event
080: *
081: */
082: public void setEvent(String event) {
083:
084: this .event = event;
085:
086: }
087:
088: /**
089: * Return the hook type
090: */
091: public String getType() {
092:
093: return (this .type);
094:
095: }
096:
097: /**
098: * Set the hook type
099: *
100: */
101: public void setType(String type) {
102:
103: this .type = type;
104:
105: }
106:
107: /**
108: * Return the hook value
109: */
110: public String getValue() {
111:
112: return (this .value);
113:
114: }
115:
116: /**
117: * Set the hook value
118: *
119: */
120: public void setValue(String value) {
121:
122: this .value = value;
123: }
124:
125: // --------------------------------------------------------- Public Methods
126:
127: /**
128: * Reset all properties to their default values.
129: *
130: * @param mapping The mapping used to select this instance
131: * @param request The servlet request we are processing
132: */
133: public void reset(ActionMapping mapping, HttpServletRequest request) {
134:
135: this .name = null;
136: this .event = null;
137: this .type = null;
138: this .value = null;
139: }
140:
141: /**
142: * Validate the properties that have been set from this HTTP request,
143: * and return an <code>ActionErrors</code> object that encapsulates any
144: * validation errors that have been found. If no errors are found, return
145: * <code>null</code> or an <code>ActionErrors</code> object with no
146: * recorded error messages.
147: *
148: * @param mapping The mapping used to select this instance
149: * @param request The servlet request we are processing
150: */
151: public ActionErrors validate(ActionMapping mapping,
152: HttpServletRequest request) {
153:
154: ActionErrors errors = new ActionErrors();
155:
156: if (name == null || name.length() == 0)
157: errors.add("name", new ActionError("error.name.required"));
158: if (event == null || event.length() == 0)
159: errors
160: .add("event", new ActionError(
161: "error.event.required"));
162: if (type == null || type.length() == 0)
163: errors.add("type", new ActionError("error.type.required"));
164:
165: return (errors);
166:
167: }
168: }
|