1 package org.apache.turbine.services.intake.model; 2 3 18 19 import org.apache.commons.lang.StringUtils; 20 21 import org.apache.turbine.services.intake.IntakeException; 22 import org.apache.turbine.services.intake.validator.IntegerValidator; 23 import org.apache.turbine.services.intake.xmlmodel.XmlField; 24 25 33 public class IntegerField 34 extends Field 35 { 36 37 44 public IntegerField(XmlField field, Group group) 45 throws IntakeException 46 { 47 super(field, group); 48 } 49 50 55 public void setDefaultValue(String prop) 56 { 57 defaultValue = null; 58 59 if (prop == null) 60 { 61 return; 62 } 63 64 defaultValue = new Integer (prop); 65 } 66 67 75 public void setEmptyValue(String prop) 76 { 77 emptyValue = null; 78 79 if (prop == null) 80 { 81 return; 82 } 83 84 emptyValue = new Integer (prop); 85 } 86 87 97 protected Object getSafeEmptyValue() 98 { 99 if (isMultiValued) 100 { 101 return new int[0]; 102 } 103 else 104 { 105 return (null == getEmptyValue()) 106 ? new Integer (0) : getEmptyValue(); 107 } 108 } 109 110 115 protected String getDefaultValidator() 116 { 117 return IntegerValidator.class.getName(); 118 } 119 120 123 protected void doSetValue() 124 { 125 if (isMultiValued) 126 { 127 String [] inputs = parser.getStrings(getKey()); 128 int[] values = new int[inputs.length]; 129 for (int i = 0; i < inputs.length; i++) 130 { 131 values[i] = StringUtils.isNotEmpty(inputs[i]) 132 ? new Integer (inputs[i]).intValue() 133 : ((Integer ) getEmptyValue()).intValue(); 134 } 135 setTestValue(values); 136 } 137 else 138 { 139 String val = parser.getString(getKey()); 140 setTestValue(StringUtils.isNotEmpty(val) ? new Integer (val) : (Integer ) getEmptyValue()); 141 } 142 } 143 144 } 145 | Popular Tags |