1 /**
2 * Copyright 2005-2012 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
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.rice.krad.datadictionary.validation.constraint;
17
18 import org.kuali.rice.krad.datadictionary.validator.ErrorReport;
19 import org.kuali.rice.krad.datadictionary.validator.TracerToken;
20
21 import java.util.ArrayList;
22
23 /**
24 * This is a constraint that limits attribute values to some subset of valid characters or to match a particular regular expression.
25 *
26 * For example:
27 * - To limit to both upper and lower-case letters, value can be set to "[A-Za-z]*"
28 * - To limit to any character except carriage returns and line feeds, value can be set to "[^\n\r]*"
29 *
30 * @author Kuali Rice Team (rice.collab@kuali.org)
31 */
32 public class ValidCharactersConstraint extends BaseConstraint {
33
34 protected String value;
35
36 /**
37 * The Java based regex for valid characters
38 * This value should include the ^ and $ symbols if needed
39 * @return the value
40 */
41 public String getValue() {
42 return value;
43 }
44
45 /**
46 * @param value the value to set
47 */
48 public void setValue(String value) {
49 this.value = value;
50 }
51
52 /**
53 * Validates different requirements of component compiling a series of reports detailing information on errors
54 * found in the component. Used by the RiceDictionaryValidator.
55 *
56 * @param tracer Record of component's location
57 * @param parser Set of tools for parsing the xml files which were used to create the component
58 * @return A list of ErrorReports detailing errors found within the component and referenced within it
59 */
60 @Override
61 public ArrayList<ErrorReport> completeValidation(TracerToken tracer){
62 ArrayList<ErrorReport> reports=new ArrayList<ErrorReport>();
63 tracer.addBean("ValidCharacterConstraint", getMessageKey());
64
65 if(getValue()==null){
66 ErrorReport error = new ErrorReport(ErrorReport.WARNING);
67 error.setValidationFailed("GetValue should return something");
68 error.setBeanLocation(tracer.getBeanLocation());
69 error.addCurrentValue("getValue ="+getValue());
70 reports.add(error);
71 }
72
73 reports.addAll(super.completeValidation(tracer.getCopy()));
74
75 return reports;
76 }
77 }