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.ShortValidator; 23 import org.apache.turbine.services.intake.xmlmodel.XmlField; 24 25 32 public class ShortField 33 extends Field 34 { 35 42 public ShortField(XmlField field, Group group) 43 throws IntakeException 44 { 45 super(field, group); 46 } 47 48 53 public void setDefaultValue(String prop) 54 { 55 defaultValue = null; 56 57 if (prop == null) 58 { 59 return; 60 } 61 62 defaultValue = new Short (prop); 63 } 64 65 73 public void setEmptyValue(String prop) 74 { 75 emptyValue = null; 76 77 if (prop == null) 78 { 79 return; 80 } 81 82 emptyValue = new Short (prop); 83 } 84 85 95 protected Object getSafeEmptyValue() 96 { 97 if (isMultiValued) 98 { 99 return new short[0]; 100 } 101 else 102 { 103 return (null == getEmptyValue()) 104 ? new Short ((short) 0) : getEmptyValue(); 105 } 106 } 107 108 113 protected String getDefaultValidator() 114 { 115 return ShortValidator.class.getName(); 116 } 117 118 121 protected void doSetValue() 122 { 123 if (isMultiValued) 124 { 125 String [] inputs = parser.getStrings(getKey()); 126 short[] values = new short[inputs.length]; 127 for (int i = 0; i < inputs.length; i++) 128 { 129 values[i] = StringUtils.isNotEmpty(inputs[i]) 130 ? new Short (inputs[i]).shortValue() 131 : ((Short ) getEmptyValue()).shortValue(); 132 } 133 setTestValue(values); 134 } 135 else 136 { 137 String val = parser.getString(getKey()); 138 setTestValue(StringUtils.isNotEmpty(val) 139 ? new Short (val) : (Short ) getEmptyValue()); 140 } 141 } 142 143 } 144 | Popular Tags |