01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/glossary/tool/src/java/org/theospi/portfolio/help/control/GlossaryEntryValidator.java $
03: * $Id: GlossaryEntryValidator.java 22293 2007-03-07 20:46:53Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2007 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/
21:
22: /**
23: *
24: */package org.theospi.portfolio.help.control;
25:
26: import org.springframework.validation.Errors;
27: import org.theospi.portfolio.help.model.GlossaryEntry;
28: import org.theospi.utils.mvc.impl.ValidatorBase;
29:
30: /**
31: * @author chrismaurer
32: *
33: */
34: public class GlossaryEntryValidator extends ValidatorBase {
35:
36: public boolean supports(Class clazz) {
37: if (GlossaryEntry.class.isAssignableFrom(clazz))
38: return true;
39: else
40: return false;
41: }
42:
43: /* (non-Javadoc)
44: * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
45: */
46: public void validate(Object obj, Errors errors) {
47: GlossaryEntry entry = (GlossaryEntry) obj;
48: if (entry.getTerm() == null || entry.getTerm().equals("")) {
49: errors.rejectValue("term", "error.required", "required");
50: }
51: if (entry.getTerm() != null && entry.getTerm().length() > 255) {
52: errors.rejectValue("description", "error.lengthExceded",
53: new Object[] { "255" },
54: "Value must be less than {0} characters");
55: }
56: if (entry.getDescription() == null
57: || entry.getDescription().equals("")) {
58: errors.rejectValue("description", "error.required",
59: "required");
60: }
61: if (entry.getDescription() != null
62: && entry.getDescription().length() > 255) {
63: errors.rejectValue("description", "error.lengthExceded",
64: new Object[] { "255" },
65: "Value must be less than {0} characters");
66: }
67: if (entry.getLongDescription() == null
68: || entry.getLongDescription().equals("")) {
69: errors.rejectValue("longDescription", "error.required",
70: "required");
71: }
72: //TODO Should there be a length check on the long description?
73:
74: }
75:
76: }
|