KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > util > validators > ProperNounValidator


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.util.validators;
25
26
27 /**
28  * <todo>
29  * Time is running out, the illusion fades away...
30  * This package will be refactored/extended after iteration 1.
31  * - move to com.holigrow.yoda.util.validators ?
32  * - interfaces + factory
33  * - constructor madness (setXXX instead of N constructors?)
34  * - more validators
35  * - more fun
36  * </todo>
37  *
38  * Egennamn...
39  *
40  * @@author <a HREF="meat_for_the_butcher@@yahoo.com">Patrik Nyborg</a>
41  */

42 public class ProperNounValidator extends StringValidator {
43   // --- [Constants] -----------------------------------------------------------
44

45   // perl5 patterns
46
private static final String JavaDoc SEPARATOR = "(\\s+|-)";
47   private static final String JavaDoc PROPER_NOUN_PART = "(\\w+'?\\w+)"; // <todo>"\w" allows "_" - incorrect</todo>
48
private static final String JavaDoc PROPER_NOUN_PATTERN = "^" + PROPER_NOUN_PART + "(" + SEPARATOR + PROPER_NOUN_PART + ")*$";
49
50   // error codes
51
private static final String JavaDoc INVALID_PROPER_NOUN_ERROR_CODE = "305";
52
53
54
55   // --- [Attributes] ----------------------------------------------------------
56
// --- [Static] --------------------------------------------------------------
57
// --- [Constructors] --------------------------------------------------------
58

59   /**
60    * <todo>remove?</todo>
61    */

62   public ProperNounValidator(String JavaDoc fieldName) {
63     this(fieldName, true);
64   }
65
66   /**
67    * <todo>remove?</todo>
68    */

69   public ProperNounValidator(String JavaDoc fieldName, boolean isRequired) {
70     super(fieldName, isRequired);
71     initializePattern(PROPER_NOUN_PATTERN, INVALID_PROPER_NOUN_ERROR_CODE);
72   }
73
74   /**
75    *
76    */

77   public ProperNounValidator(String JavaDoc fieldName, boolean isRequired, int upperLengthLimit) {
78     super(fieldName, isRequired, upperLengthLimit);
79     initializePattern(PROPER_NOUN_PATTERN, INVALID_PROPER_NOUN_ERROR_CODE);
80   }
81
82
83
84   // --- [Public] --------------------------------------------------------------
85
// --- [X implementation] ----------------------------------------------------
86
// --- [X Overrides] ---------------------------------------------------------
87
// --- [Package protected] ---------------------------------------------------
88
// --- [Private] -------------------------------------------------------------
89
// --- [Protected] -----------------------------------------------------------
90
// --- [Inner classes] -------------------------------------------------------
91
}
Popular Tags