View Javadoc

1   /*
2    * Copyright 2003-2004 Michael Franken, Zilverline.
3    *
4    * The contents of this file, or the files included with this file, are subject to
5    * the current version of ZILVERLINE Collaborative Source License for the
6    * Zilverline Search Engine (the "License"); You may not use this file except in
7    * compliance with the License.
8    *
9    * You may obtain a copy of the License at
10   *
11   *     http://www.zilverline.org.
12   *
13   * See the License for the rights, obligations and
14   * limitations governing use of the contents of the file.
15   *
16   * The Original and Upgraded Code is the Zilverline Search Engine. The developer of
17   * the Original and Upgraded Code is Michael Franken. Michael Franken owns the
18   * copyrights in the portions it created. All Rights Reserved.
19   *
20   */
21  package org.zilverline.web;
22  
23  import java.io.File;
24  
25  import org.springframework.validation.Errors;
26  import org.springframework.validation.ValidationUtils;
27  import org.springframework.validation.Validator;
28  
29  import org.zilverline.core.FileSystemCollection;
30  
31  /***
32   * <code>Validator</code> for <code>Collection</code> forms.
33   * 
34   * @author Michael Franken
35   */
36  public class CollectionValidator implements Validator {
37  
38      public boolean supports(Class clazz) {
39          return FileSystemCollection.class.isAssignableFrom(clazz);
40      }
41  
42      public void validate(Object obj, Errors errors) {
43          FileSystemCollection collection = (FileSystemCollection) obj;
44          ValidationUtils.rejectIfEmpty(errors, "name", "error.required", "required");
45          ValidationUtils.rejectIfEmpty(errors, "contentDir", "error.required", "required");
46          File thisFile = (File) errors.getFieldValue("contentDir");
47          if (thisFile == null || !thisFile.isDirectory()) {
48              errors.rejectValue("contentDir", "error.dirnoexist", "directory does not exist");
49          }
50  
51      }
52  
53  }