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  
22  package org.zilverline.web;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  import org.springframework.validation.Errors;
28  import org.springframework.validation.Validator;
29  
30  import org.zilverline.service.CollectionManager;
31  
32  /***
33   * JavaBean <code>Validator</code> for <code>IndexDefaultsController</code>.
34   * 
35   * @author Michael Franken
36   * @version $Revision: 1.2 $
37   */
38  public class IndexDefaultsValidator implements Validator {
39      /*** logger for Commons logging. */
40      private static Log log = LogFactory.getLog(IndexDefaultsValidator.class);
41  
42      /***
43       * @see org.springframework.validation.Validator#supports(java.lang.Class)
44       */
45      public boolean supports(Class clazz) {
46          return CollectionManager.class.isAssignableFrom(clazz);
47      }
48  
49      /***
50       * Validator for CollectionManager. Validates the part on the indexDefaultsController: priority, mergeFactor, etc.
51       * 
52       * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
53       */
54      public void validate(Object obj, Errors errors) {
55          CollectionManager manager = (CollectionManager) obj;
56          if (manager.getPriority() != null) {
57              if (manager.getPriority().intValue() < 1 || manager.getPriority().intValue() > 10) {
58                  errors.rejectValue("priority", null, new Object[] { manager.getPriority() },
59                      "must be a positive number between 1 and 10.");
60              }
61          }
62          if (manager.getMergeFactor() != null) {
63              if (manager.getMergeFactor().intValue() < 0) {
64                  errors.rejectValue("mergeFactor", "error.notapositivenumber", new Object[] { manager.getMergeFactor() },
65                      "must be a positive number.");
66              }
67          }
68          if (manager.getMaxMergeDocs() != null) {
69              if (manager.getMaxMergeDocs().intValue() < 0) {
70                  errors.rejectValue("maxMergeDocs", "error.notapositivenumber", new Object[] { manager.getMaxMergeDocs() },
71                      "must be a positive number.");
72              }
73          }
74          if (manager.getMinMergeDocs() != null) {
75              if (manager.getMinMergeDocs().intValue() < 0) {
76                  errors.rejectValue("minMergeDocs", "error.notapositivenumber", new Object[] { manager.getMinMergeDocs() },
77                      "must be a positive number.");
78              }
79          }
80      }
81  }