1 21 package au.id.jericho.lib.html; 22 23 import java.util.*; 24 25 136 public final class FormControlType { 137 private String formControlTypeId; 138 private String elementName; 139 private boolean hasPredefinedValue; 140 private boolean submit; 141 142 private static final HashMap ID_MAP=new HashMap(16,1.0F); private static final HashMap INPUT_ELEMENT_TYPE_MAP=new HashMap(11,1.0F); 145 159 public static final FormControlType BUTTON=new FormControlType("button",Tag.BUTTON,true,true).register(); 160 161 174 public static final FormControlType CHECKBOX=new FormControlType("checkbox",Tag.INPUT,true,false).register(); 175 176 205 public static final FormControlType FILE=new FormControlType("file",Tag.INPUT,false,false).register(); 206 207 222 public static final FormControlType HIDDEN=new FormControlType("hidden",Tag.INPUT,false,false).register(); 223 224 255 public static final FormControlType IMAGE=new FormControlType("image",Tag.INPUT,true,true).register(); 256 257 272 public static final FormControlType PASSWORD=new FormControlType("password",Tag.INPUT,false,false).register(); 273 274 287 public static final FormControlType RADIO=new FormControlType("radio",Tag.INPUT,true,false).register(); 288 289 324 public static final FormControlType SELECT_MULTIPLE=new FormControlType("select_multiple",Tag.SELECT,true,false).register(); 325 326 356 public static final FormControlType SELECT_SINGLE=new FormControlType("select_single",Tag.SELECT,true,false).register(); 357 358 373 public static final FormControlType SUBMIT=new FormControlType("submit",Tag.INPUT,true,true).register(); 374 375 390 public static final FormControlType TEXT=new FormControlType("text",Tag.INPUT,false,false).register(); 391 392 406 public static final FormControlType TEXTAREA=new FormControlType("textarea",Tag.TEXTAREA,false,false).register(); 407 408 private FormControlType(final String formControlTypeId, final String elementName, final boolean hasPredefinedValue, final boolean submit) { 409 this.formControlTypeId=formControlTypeId; 410 this.elementName=elementName; 411 this.hasPredefinedValue=hasPredefinedValue; 412 this.submit=submit; 413 } 414 415 private FormControlType register() { 416 ID_MAP.put(formControlTypeId,this); 417 if (elementName==Tag.INPUT) INPUT_ELEMENT_TYPE_MAP.put(formControlTypeId,this); 418 return this; 419 } 420 421 425 public String getElementName() { 426 return elementName; 427 } 428 429 450 public boolean hasPredefinedValue() { 451 return hasPredefinedValue; 452 } 453 454 461 public boolean isSubmit() { 462 return submit; 463 } 464 465 474 public String getTagName() { 475 return elementName; 476 } 477 478 488 public boolean isPredefinedValue() { 489 return hasPredefinedValue; 490 } 491 492 511 public boolean allowsMultipleValues() { 512 return !(this==RADIO || isSubmit()); 513 } 514 515 528 public String getFormControlTypeId() { 529 return formControlTypeId; 530 } 531 532 542 public static FormControlType get(final String formControlTypeId) { 543 return (FormControlType)ID_MAP.get(formControlTypeId); 544 } 545 546 559 public String [] getAdditionalSubmitNames(final String name) { 560 if (this!=IMAGE) return null; 561 final String [] names=new String [2]; 562 names[0]=name+".x"; 563 names[1]=name+".y"; 564 return names; 565 } 566 567 580 public static boolean isPotentialControl(final String tagName) { 581 return tagName.equalsIgnoreCase(Tag.INPUT) || tagName.equalsIgnoreCase(Tag.TEXTAREA) || tagName.equalsIgnoreCase(Tag.BUTTON) || tagName.equalsIgnoreCase(Tag.SELECT); 582 } 583 584 588 public String toString() { 589 return formControlTypeId; 590 } 591 592 static FormControlType getFromInputElementType(final String typeAttributeValue) { 593 return (FormControlType)INPUT_ELEMENT_TYPE_MAP.get(typeAttributeValue); 594 } 595 } 596 | Popular Tags |