1 18 package net.sf.uitags.tag.select; 19 20 import javax.servlet.jsp.JspException ; 21 22 import net.sf.uitags.tag.AbstractUiTag; 23 import net.sf.uitags.tagutil.validation.RuntimeValidationException; 24 import net.sf.uitags.tagutil.validation.RuntimeValidator; 25 import net.sf.uitags.util.Template; 26 27 28 35 public class SelectTag extends AbstractUiTag { 36 37 41 44 private static final long serialVersionUID = 100L; 45 46 47 48 52 55 private ShortcutType shortcutType; 56 59 private String applyTo; 60 63 private String applyToName; 64 67 private String injectTo; 68 71 private String injectToName; 72 73 74 78 81 public SelectTag() { 82 super(); 83 } 84 85 86 90 95 public void setType(String val) { 96 this.shortcutType = ShortcutType.findByName(val); 97 } 98 99 104 public void setApplyTo(String val) { 105 this.applyTo = val; 106 } 107 108 113 public void setApplyToName(String val) { 114 this.applyToName = val; 115 } 116 117 122 public void setInjectTo(String val) { 123 this.injectTo = val; 124 } 125 126 131 public void setInjectToName(String val) { 132 this.injectToName = val; 133 } 134 135 136 140 147 public int doStartTag() throws JspException { 148 return EVAL_BODY_INCLUDE; 149 } 150 151 157 public int doEndTag() throws JspException { 158 RuntimeValidator.assertAttributeExclusive( 159 "applyTo", this.applyTo, "applyToName", this.applyToName); 160 RuntimeValidator.assertAttributeExclusive( 161 "injectTo", this.injectTo, "injectToName", this.injectToName); 162 163 RuntimeValidator.assertEitherSpecified( 164 "applyTo", this.applyTo, "applyToName", this.applyToName); 165 RuntimeValidator.assertEitherSpecified( 166 "injectTo", this.injectTo, "injectToName", this.injectToName); 167 168 Template tpl = Template.forName(Template.SELECT); 169 tpl.map("callback", this.shortcutType.getCallbackName()); 170 tpl.map("applyTo", this.applyTo); 171 tpl.map("applyToName", this.applyToName); 172 tpl.map("injectTo", this.injectTo); 173 tpl.map("injectToName", this.injectToName); 174 println(tpl.evalToString()); 175 176 return EVAL_PAGE; 177 } 178 179 180 184 190 private abstract static class ShortcutType { 191 193 196 private static final ShortcutType ALL = new ShortcutType("all") { 197 String getCallbackName() { 198 return "createAllSuite"; 199 } 200 }; 201 202 205 private static final ShortcutType NONE = new ShortcutType("none") { 206 String getCallbackName() { 207 return "createNoneSuite"; 208 } 209 }; 210 211 214 private static final ShortcutType ALL_NONE = new ShortcutType("all-none") { 215 String getCallbackName() { 216 return "createAllNoneSuite"; 217 } 218 }; 219 220 223 private static final ShortcutType NONE_ALL = new ShortcutType("none-all") { 224 String getCallbackName() { 225 return "createNoneAllSuite"; 226 } 227 }; 228 229 232 private static final ShortcutType INVERSE = new ShortcutType("inverse") { 233 String getCallbackName() { 234 return "createInverseSuite"; 235 } 236 }; 237 238 241 private static final ShortcutType RANGE = new ShortcutType("range") { 242 String getCallbackName() { 243 return "createRangeSuite"; 244 } 245 }; 246 247 249 252 private final String name; 253 254 256 261 private ShortcutType(String name) { 262 this.name = name; 263 } 264 265 267 272 abstract String getCallbackName(); 273 274 281 static ShortcutType findByName(String name) { 282 if (name.equals(ALL_NONE.name)) { 283 return ALL_NONE; 284 } 285 else if (name.equals(NONE_ALL.name)) { 286 return NONE_ALL; 287 } 288 else if (name.equals(ALL.name)) { 289 return ALL; 290 } 291 else if (name.equals(NONE.name)) { 292 return NONE; 293 } 294 else if (name.equals(INVERSE.name)) { 295 return INVERSE; 296 } 297 else if (name.equals(RANGE.name)) { 298 return RANGE; 299 } 300 301 throw new RuntimeValidationException("Invalid type: '" + name + "'."); 304 } 305 } 306 } | Popular Tags |