01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.datadictionary.validation;
17:
18: import java.io.Serializable;
19: import java.util.regex.Matcher;
20: import java.util.regex.Pattern;
21:
22: import org.apache.log4j.Logger;
23: import org.kuali.core.datadictionary.exporter.ExportMap;
24:
25: /**
26: * Abstraction of the regular expressions used to validate attribute values.
27: *
28: *
29: */
30: abstract public class ValidationPattern implements Serializable {
31: private static final Logger LOG = Logger
32: .getLogger(ValidationPattern.class);
33:
34: /**
35: * @return regular expression Pattern generated by the individual ValidationPattern subclass
36: */
37: abstract public Pattern getRegexPattern();
38:
39: /**
40: * @return String version of regular expression base, suitable for modification with length-specifiers and used internally by
41: * getRegexPattern
42: */
43: abstract protected String getRegexString();
44:
45: /**
46: * @return true if the given String matches this pattern
47: */
48: public boolean matches(String input) {
49: Pattern p = getRegexPattern();
50: LOG.debug("matching '" + input + "' against pattern '"
51: + p.pattern() + "'");
52:
53: Matcher m = p.matcher(input);
54:
55: return m.matches();
56: }
57:
58: /**
59: * @return XML describing the subclass instance
60: */
61: abstract public String getPatternXml();
62:
63: /**
64: * @return ExportMap describing the subclass instance
65: */
66: abstract public ExportMap buildExportMap(String exportKey);
67: }
|