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