KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > validation > admin > ProjectValidator


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.web.validation.admin;
21
22 import org.openi.project.Module;
23 import org.openi.project.Project;
24 import org.springframework.validation.Errors;
25 import org.springframework.validation.ValidationUtils;
26 import org.springframework.validation.Validator;
27 import java.util.List JavaDoc;
28
29
30 /**
31  * @author Uddhab Pant <br>
32  * @version $Revision: 1.8 $ $Date: 2006/04/12 00:39:12 $ <br>
33  *
34  * Validates project form.
35  *
36  */

37 public class ProjectValidator implements Validator {
38     /**
39      * Return whether or not this object can validate objects
40      * of the given class.
41      * @param _class Class
42      * @return boolean
43      */

44     public boolean supports(Class JavaDoc _class) {
45         return Project.class.isAssignableFrom(_class);
46     }
47
48     /**
49      * Validate an object, which must be of a class for which
50      * the supports() method returned true.
51      *
52      * @param object Object
53      * @param errors Errors
54      */

55     public void validate(Object JavaDoc object, Errors errors) {
56         Project project = (Project) object;
57
58         // project name is required
59
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "projectName",
60             "required.message");
61         // logo url is required
62
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "logoUrl",
63             "required.message");
64
65         // either splash image or splash page is required.
66
if (((project.getSplashImageUrl() == null)
67                 || (project.getSplashImageUrl().trim() == ""))
68                 && ((project.getSplashPage() == null)
69                 || (project.getSplashPage().trim() == ""))) {
70             errors.rejectValue("splashPage", "splash.required.message",
71                 "splash.required.message");
72         }
73
74         // atleast one module is required.
75
List JavaDoc modules = project.getModules();
76         int i;
77
78         for (i = modules.size() - 1; i >= 0; i--) {
79             Module module = (Module) modules.get(i);
80
81             if (module.getFolderName() != "") {
82                 break;
83             }
84         }
85
86         if (i < 0) {
87             errors.rejectValue("modules", "module.required.message",
88                 "module.required.message");
89         }
90
91         // default category is 'General'
92
if ((project.getCategory() == null)
93                 || (project.getCategory().trim() == "")) {
94             project.setCategory("General");
95         }
96     }
97 }
98
Popular Tags