01: /**********************************************************************************
02: * $URL: $
03: * $Id: $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2006,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: **********************************************************************************/package org.sakaiproject.poll.tool.validators;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.springframework.validation.Errors;
25: import org.springframework.validation.Validator;
26: import org.sakaiproject.poll.logic.PollListManager;
27: import org.sakaiproject.poll.logic.PollVoteManager;
28: import org.sakaiproject.poll.model.Option;
29: import org.sakaiproject.tool.api.ToolManager;
30:
31: import uk.org.ponder.messageutil.MessageLocator;
32: import uk.org.ponder.messageutil.TargettedMessageList;
33:
34: public class OptionValidator implements Validator {
35:
36: /** Logger for this class and subclasses */
37: protected final Log logger = LogFactory.getLog(getClass());
38: private MessageLocator messageLocator;
39: private TargettedMessageList tml = new TargettedMessageList();
40: private PollVoteManager pollVoteManager;
41: private PollListManager manager;
42: public String submissionStatus;
43:
44: public void setPollListManager(PollListManager manager) {
45: this .manager = manager;
46: }
47:
48: public void setPollVoteManager(PollVoteManager pvm) {
49: this .pollVoteManager = pvm;
50: }
51:
52: public void setMessageLocator(MessageLocator messageLocator) {
53:
54: this .messageLocator = messageLocator;
55: }
56:
57: private ToolManager toolManager;
58:
59: public void setToolManager(ToolManager toolManager) {
60: this .toolManager = toolManager;
61: }
62:
63: public boolean supports(Class clazz) {
64: // TODO Auto-generated method stub
65: return clazz.equals(Option.class);
66: }
67:
68: public void validate(Object obj, Errors errors) {
69:
70: Option option = (Option) obj;
71:
72: logger.debug("validating Option with id:" + option.getId());
73: if (option.getStatus() != null
74: && (option.getStatus().equals("cancel") || option
75: .getStatus().equals("delete")))
76: return;
77:
78: if (option.getOptionText() == null
79: || option.getOptionText().length() == 0) {
80: logger.error("OptionText is empty!");
81: errors.reject("option_empty", "option empty");
82: return;
83: }
84:
85: }
86:
87: }
|