KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > util > Validator


1 /*
2  * Created on Jun 24, 2004
3  *
4  */

5 package com.dotmarketing.util;
6
7 import javax.portlet.ActionRequest;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9
10 import org.apache.struts.Globals;
11 import org.apache.struts.action.ActionForm;
12 import org.apache.struts.action.ActionMapping;
13
14 import com.liferay.portlet.ActionRequestImpl;
15
16
17 /**
18  * @author Maria
19  *
20  */

21 public class Validator {
22     public static boolean validate(ActionRequest request, ActionForm form, ActionMapping mapping) {
23         if ((request == null) || (form == null) || (mapping == null)) {
24             return false;
25         }
26
27         ActionRequestImpl reqImpl = (ActionRequestImpl) request;
28         HttpServletRequest JavaDoc httpReq = reqImpl.getHttpServletRequest();
29         org.apache.struts.action.ActionErrors errors = form.validate(mapping, httpReq);
30
31         if ((errors != null) && !errors.isEmpty()) {
32             
33             request.setAttribute(Globals.ERROR_KEY, errors);
34             return false;
35         }
36
37         return true;
38     }
39
40     public static boolean validate(HttpServletRequest JavaDoc httpReq, ActionForm form, ActionMapping mapping) {
41         if ((httpReq == null) || (form == null) || (mapping == null)) {
42             return false;
43         }
44
45         org.apache.struts.action.ActionErrors errors = form.validate(mapping, httpReq);
46
47         if ((errors != null) && !errors.isEmpty()) {
48             
49             httpReq.setAttribute(Globals.ERROR_KEY, errors);
50             return false;
51         }
52
53         return true;
54     }
55 }
56
Popular Tags