1 18 package net.sf.uitags.tag.shift; 19 20 import javax.servlet.jsp.JspException ; 21 22 import net.sf.uitags.tag.AbstractUiTag; 23 import net.sf.uitags.tagutil.TaglibProperties; 24 import net.sf.uitags.tagutil.validation.RuntimeValidationException; 25 import net.sf.uitags.tagutil.validation.RuntimeValidator; 26 import net.sf.uitags.util.Template; 27 28 29 37 public class ShiftTag extends AbstractUiTag { 38 39 43 46 private static final long serialVersionUID = 100L; 47 48 49 50 54 57 private ShortcutType shortcutType; 58 61 private String applyTo; 62 65 private String applyToName; 66 69 private String injectTo; 70 73 private String injectToName; 74 75 76 77 81 84 public ShiftTag() { 85 super(); 86 } 87 88 89 90 94 99 public void setType(String val) { 100 this.shortcutType = ShortcutType.findByName(val); 101 } 102 103 108 public void setApplyTo(String val) { 109 this.applyTo = val; 110 } 111 112 117 public void setApplyToName(String val) { 118 this.applyToName = val; 119 } 120 121 126 public void setInjectTo(String val) { 127 this.injectTo = val; 128 } 129 130 135 public void setInjectToName(String val) { 136 this.injectToName = val; 137 } 138 139 140 141 145 152 public int doStartTag() throws JspException { 153 return EVAL_BODY_INCLUDE; 154 } 155 156 162 public int doEndTag() throws JspException { 163 RuntimeValidator.assertAttributeExclusive( 164 "applyTo", this.applyTo, "applyToName", this.applyToName); 165 RuntimeValidator.assertAttributeExclusive( 166 "injectTo", this.injectTo, "injectToName", this.injectToName); 167 168 RuntimeValidator.assertEitherSpecified( 169 "applyTo", this.applyTo, "applyToName", this.applyToName); 170 RuntimeValidator.assertEitherSpecified( 171 "injectTo", this.injectTo, "injectToName", this.injectToName); 172 173 Template tpl = Template.forName(Template.SHIFT); 174 tpl.map("callback", this.shortcutType.getCallbackName()); 175 tpl.map("applyTo", this.applyTo); 176 tpl.map("applyToName", this.applyToName); 177 tpl.map("injectTo", this.injectTo); 178 tpl.map("injectToName", this.injectToName); 179 println(tpl.evalToString()); 180 181 return EVAL_PAGE; 182 } 183 184 185 186 190 196 private abstract static class ShortcutType { 197 199 202 private static final ShortcutType UP = new ShortcutType("up") { 203 String getCallbackName() { 204 return "createUpSuite"; 205 } 206 }; 207 208 211 private static final ShortcutType DOWN = new ShortcutType("down") { 212 String getCallbackName() { 213 return "createDownSuite"; 214 } 215 }; 216 217 220 private static final ShortcutType FIRST = new ShortcutType("first") { 221 String getCallbackName() { 222 return "createFirstSuite"; 223 } 224 }; 225 226 229 private static final ShortcutType LAST = new ShortcutType("last") { 230 String getCallbackName() { 231 return "createLastSuite"; 232 } 233 }; 234 235 237 240 private final String name; 241 242 244 249 private ShortcutType(String name) { 250 this.name = name; 251 } 252 253 255 260 abstract String getCallbackName(); 261 262 269 static ShortcutType findByName(String name) { 270 if (name.equals(UP.name)) { 271 return UP; 272 } 273 else if (name.equals(DOWN.name)) { 274 return DOWN; 275 } 276 else if (name.equals(FIRST.name)) { 277 return FIRST; 278 } 279 else if (name.equals(LAST.name)) { 280 return LAST; 281 } 282 283 throw new RuntimeValidationException("Invalid type: '" + name + "'."); 286 } 287 } 288 } | Popular Tags |