| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.datadictionary.validation.constraint; |
| 17 | |
|
| 18 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
| 19 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 20 | |
import org.kuali.rice.krad.uif.UifConstants; |
| 21 | |
|
| 22 | |
import java.util.ArrayList; |
| 23 | |
import java.util.List; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 0 | public class IntegerPatternConstraint extends ValidDataPatternConstraint{ |
| 31 | |
protected boolean allowNegative; |
| 32 | |
protected boolean onlyNegative; |
| 33 | |
protected boolean omitZero; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
@Override |
| 39 | |
protected String getRegexString() { |
| 40 | 0 | StringBuffer regex = new StringBuffer(); |
| 41 | |
|
| 42 | 0 | if (isAllowNegative() && !onlyNegative) { |
| 43 | 0 | regex.append("((-?"); |
| 44 | |
} |
| 45 | 0 | else if(onlyNegative){ |
| 46 | 0 | regex.append("((-"); |
| 47 | |
} |
| 48 | |
else { |
| 49 | 0 | regex.append("(("); |
| 50 | |
} |
| 51 | 0 | if(omitZero){ |
| 52 | 0 | regex.append("[1-9][0-9]*))"); |
| 53 | |
} |
| 54 | |
else{ |
| 55 | 0 | regex.append("[1-9][0-9]*)|[0]*)"); |
| 56 | |
} |
| 57 | |
|
| 58 | 0 | return regex.toString(); |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
public boolean isAllowNegative() { |
| 65 | 0 | return this.allowNegative; |
| 66 | |
} |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
public void setAllowNegative(boolean allowNegative) { |
| 72 | 0 | this.allowNegative = allowNegative; |
| 73 | 0 | } |
| 74 | |
|
| 75 | |
public boolean isOnlyNegative() { |
| 76 | 0 | return onlyNegative; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
public void setOnlyNegative(boolean onlyNegative) { |
| 84 | 0 | this.onlyNegative = onlyNegative; |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
public boolean isOmitZero() { |
| 88 | 0 | return omitZero; |
| 89 | |
} |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
public void setOmitZero(boolean omitZero) { |
| 96 | 0 | this.omitZero = omitZero; |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public List<String> getValidationMessageParams() { |
| 106 | 0 | if (validationMessageParams == null) { |
| 107 | 0 | validationMessageParams = new ArrayList<String>(); |
| 108 | 0 | ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService(); |
| 109 | 0 | if (allowNegative && !onlyNegative) { |
| 110 | 0 | if(omitZero){ |
| 111 | 0 | validationMessageParams.add(configService |
| 112 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX |
| 113 | |
+ "positiveOrNegative")); |
| 114 | |
} |
| 115 | |
else{ |
| 116 | 0 | validationMessageParams.add(configService |
| 117 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX |
| 118 | |
+ "positiveOrNegativeOrZero")); |
| 119 | |
} |
| 120 | |
} |
| 121 | 0 | else if(onlyNegative){ |
| 122 | 0 | if(omitZero){ |
| 123 | 0 | validationMessageParams.add(configService |
| 124 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negative")); |
| 125 | |
} |
| 126 | |
else{ |
| 127 | 0 | validationMessageParams.add(configService |
| 128 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negativeOrZero")); |
| 129 | |
} |
| 130 | |
} |
| 131 | |
else { |
| 132 | 0 | if(omitZero){ |
| 133 | 0 | validationMessageParams.add(configService |
| 134 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive")); |
| 135 | |
} |
| 136 | |
else{ |
| 137 | 0 | validationMessageParams.add(configService |
| 138 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrZero")); |
| 139 | |
} |
| 140 | |
} |
| 141 | |
} |
| 142 | 0 | return validationMessageParams; |
| 143 | |
} |
| 144 | |
} |