1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import org.xml.sax.Attributes ; 41 42 import java.util.Map ; 43 import java.util.HashMap ; 44 45 51 public final class InputElementFactory implements IElementFactory { 52 53 54 public static final InputElementFactory instance = new InputElementFactory(); 55 56 57 private InputElementFactory() { 58 } 59 60 69 public HtmlElement createElement( 70 final HtmlPage page, final String tagName, 71 final Attributes attributes) { 72 73 String type = null; 74 if(attributes != null) { 75 type = attributes.getValue("type"); 76 } 77 if(type == null) { 78 type = ""; 79 } 80 else { 81 type = type.toLowerCase(); 82 } 83 84 final Map attributeMap = new HashMap (); 85 if(attributes != null) { 86 for(int i=0; i < attributes.getLength(); i++) { 87 attributeMap.put(attributes.getLocalName(i), attributes.getValue(i)); 88 } 89 } 90 91 final HtmlInput result; 92 if( type.length() == 0 ) { 93 attributeMap.put("type", "text"); 97 result = new HtmlTextInput(page, attributeMap); 98 } 99 else if( type.equals("submit") ) { 100 result = new HtmlSubmitInput(page, attributeMap); 101 } 102 else if( type.equals("checkbox")) { 103 result = new HtmlCheckBoxInput(page, attributeMap); 104 } 105 else if( type.equals("radio")) { 106 result = new HtmlRadioButtonInput(page, attributeMap); 107 } 108 else if( type.equals("text")) { 109 result = new HtmlTextInput(page, attributeMap); 110 } 111 else if( type.equals("hidden")) { 112 result = new HtmlHiddenInput(page, attributeMap); 113 } 114 else if( type.equals("password")) { 115 result = new HtmlPasswordInput(page, attributeMap); 116 } 117 else if( type.equals("image")) { 118 result = new HtmlImageInput(page, attributeMap); 119 } 120 else if( type.equals("reset")) { 121 result = new HtmlResetInput(page, attributeMap); 122 } 123 else if( type.equals("button")) { 124 result = new HtmlButtonInput(page, attributeMap); 125 } 126 else if( type.equals("file")) { 127 result = new HtmlFileInput(page, attributeMap); 128 } 129 else { 130 throw new IllegalArgumentException ("Unexpected input type ["+type+"]"); 131 } 132 return result; 133 } 134 } 135 | Popular Tags |