01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/control/StructuredArtifactDefinitionValidator.java $
03: * $Id: StructuredArtifactDefinitionValidator.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 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.metaobj.shared.control;
21:
22: import org.sakaiproject.metaobj.shared.model.StructuredArtifactDefinitionBean;
23: import org.springframework.validation.Errors;
24: import org.springframework.validation.Validator;
25:
26: /**
27: * Created by IntelliJ IDEA.
28: * User: John Ellis
29: * Date: May 19, 2004
30: * Time: 3:31:16 PM
31: * To change this template use File | Settings | File Templates.
32: */
33: public class StructuredArtifactDefinitionValidator implements Validator {
34:
35: public static final String PICK_SCHEMA_ACTION = "pickSchema";
36: public static final String PICK_TRANSFORM_ACTION = "pickTransform";
37:
38: public boolean supports(Class clazz) {
39: return (StructuredArtifactDefinitionBean.class
40: .isAssignableFrom(clazz));
41: }
42:
43: public void validate(Object obj, Errors errors) {
44: if (obj instanceof StructuredArtifactDefinitionBean) {
45: StructuredArtifactDefinitionBean artifactHome = (StructuredArtifactDefinitionBean) obj;
46:
47: if (PICK_SCHEMA_ACTION.equals(artifactHome
48: .getFilePickerAction())
49: || PICK_TRANSFORM_ACTION.equals(artifactHome
50: .getFilePickerAction())) {
51: return;
52: }
53:
54: if ((artifactHome.getSchemaFile() == null
55: || artifactHome.getSchemaFile().getValue() == null || artifactHome
56: .getSchemaFile().getValue().length() == 0)
57: && artifactHome.getSchema() == null) {
58: errors.rejectValue("schemaFile", "errors.required",
59: "required");
60: }
61: if (artifactHome.getDocumentRoot() == null
62: || artifactHome.getDocumentRoot().length() == 0) {
63: errors.rejectValue("documentRoot", "errors.required",
64: "required");
65: }
66: if (artifactHome.getType() == null
67: || artifactHome.getType().getDescription() == null
68: || artifactHome.getType().getDescription().length() == 0) {
69: errors.rejectValue("description", "errors.required",
70: "required");
71: }
72: }
73: }
74: }
|