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.StringValidator; 23 import org.apache.turbine.services.intake.xmlmodel.XmlField; 24 25 33 public class StringField 34 extends Field 35 { 36 37 44 public StringField(XmlField field, Group group) 45 throws IntakeException 46 { 47 super(field, group); 48 } 49 50 55 protected String getDefaultValidator() 56 { 57 return StringValidator.class.getName(); 58 } 59 60 65 public void setDefaultValue(String prop) 66 { 67 defaultValue = prop; 68 } 69 70 78 public void setEmptyValue(String prop) 79 { 80 emptyValue = prop; 81 } 82 83 86 protected void doSetValue() 87 { 88 if (isMultiValued) 89 { 90 String [] ss = parser.getStrings(getKey()); 91 String [] sval = new String [ss.length]; 92 for (int i = 0; i < ss.length; i++) 93 { 94 sval[i] = (StringUtils.isNotEmpty(ss[i])) ? ss[i] : (String ) getEmptyValue(); 95 } 96 setTestValue(sval); 97 } 98 else 99 { 100 String val = parser.getString(getKey()); 101 setTestValue(StringUtils.isNotEmpty(val) ? val : (String ) getEmptyValue()); 102 } 103 } 104 105 111 public void setRequired(boolean v, String message) 112 { 113 this.required = v; 114 if (v) 115 { 116 if (isMultiValued) 117 { 118 String [] ss = (String []) getTestValue(); 119 if (ss == null || ss.length == 0) 120 { 121 validFlag = false; 122 this.message = message; 123 } 124 else 125 { 126 boolean set = false; 127 for (int i = 0; i < ss.length; i++) 128 { 129 set |= StringUtils.isNotEmpty(ss[i]); 130 if (set) 131 { 132 break; 133 } 134 } 135 if (!set) 136 { 137 validFlag = false; 138 this.message = message; 139 } 140 } 141 } 142 else 143 { 144 if (!setFlag || StringUtils.isEmpty((String ) getTestValue())) 145 { 146 validFlag = false; 147 this.message = message; 148 } 149 } 150 } 151 } 152 } 153 | Popular Tags |