KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > util > ValidationUtils


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package info.jtrac.util;
18
19 import org.springframework.validation.Errors;
20 import org.springframework.webflow.execution.RequestContext;
21
22 /**
23  * Helper class that improves on the Spring ValidationUtils
24  * for inserting error messages for form object fields
25  * into the view "errors" object
26  */

27 public class ValidationUtils {
28     
29     public static final String JavaDoc ERROR_EMPTY_CODE = "error.empty";
30     public static final String JavaDoc ERROR_EMPTY_MSG = "Value Required";
31     
32     public static void rejectIfEmpty(Errors errors, String JavaDoc... names) {
33         for (String JavaDoc name : names) {
34             org.springframework.validation.ValidationUtils.rejectIfEmpty(errors, name, ERROR_EMPTY_CODE);
35         }
36     }
37     
38     public static String JavaDoc getParameter(RequestContext context, String JavaDoc name) {
39         String JavaDoc value = (String JavaDoc) context.getRequestParameters().get(name);
40         if (value == null || value.trim().equals("")) {
41             return null;
42         }
43         return value.trim();
44     }
45     
46     public static boolean isAllUpperCase(String JavaDoc input) {
47         if (input == null) {
48             return false;
49         }
50         return input.matches("[A-Z0-9]+");
51     }
52     
53     public static boolean isAllLowerCase(String JavaDoc input) {
54         if (input == null) {
55             return false;
56         }
57         return input.matches("[a-z0-9]+");
58     }
59     
60     /**
61      * Only letters are allowed, not even numbers
62      * and CamelCase with dash as word separator
63      */

64     public static boolean isCamelDashCase(String JavaDoc input) {
65         if (input == null) {
66             return false;
67         }
68         return input.matches("[A-Z][a-z]+(-[A-Z][a-z]+)*");
69     }
70     
71     
72 }
73
Popular Tags