1 package org.apache.fulcrum.intake.model; 2 3 56 57 import org.apache.fulcrum.intake.xmlmodel.XmlField; 58 import org.apache.log4j.Category; 59 60 65 public class IntegerField 66 extends Field 67 { 68 69 Category category = Category.getInstance(getClass().getName()); 70 71 public IntegerField(XmlField field, Group group) 72 throws Exception 73 { 74 super(field, group); 75 } 76 77 82 protected void setDefaultValue(String prop) 83 { 84 defaultValue = null; 85 86 if (prop == null) 87 { 88 return; 89 } 90 91 try 92 { 93 defaultValue = new Integer (prop); 94 } 95 catch (Exception e) 96 { 97 category.error("Could not convert " 98 + prop + " into an Integer. (" 99 + name + ")"); 100 } 101 } 102 103 108 protected String getDefaultValidator() 109 { 110 return "org.apache.fulcrum.intake.validator.IntegerValidator"; 111 } 112 113 116 protected void doSetValue() 117 { 118 if ( isMultiValued ) 119 { 120 String [] ss = pp.getStrings(getKey()); 121 try 122 { 123 Integer [] values = new Integer [ss.length]; 124 for (int i=0; i<ss.length; i++) 125 { 126 if (ss[i] != null && ss[i].length() > 0) 127 { 128 values[i] = new Integer (ss[i]); 129 } 130 } 131 setTestValue(values); 132 } 133 catch (ClassCastException e) 134 { 135 int[] ival = new int[ss.length]; 136 for (int i=0; i<ss.length; i++) 137 { 138 if (ss[i] != null && ss[i].length() > 0) 139 { 140 ival[i] = Integer.parseInt(ss[i]); 141 } 142 } 143 setTestValue(ival); 144 } 145 } 146 else 147 { 148 String s = pp.getString(getKey()); 149 if (s != null && s.length() > 0) 150 { 151 setTestValue(new Integer (s)); 152 } 153 else 154 { 155 set_flag = false; 156 } 157 } 158 } 159 } 160 | Popular Tags |