1 45 package org.openejb.util; 46 47 54 public class HtmlUtilities { 55 56 public static final String ANCHOR_NAME_TYPE = "name"; 57 58 public static final String ANCHOR_HREF_TYPE = "href"; 59 60 private HtmlUtilities() {} 62 63 82 public static String createAnchor(String value, String display, String type) { 83 if (!(ANCHOR_HREF_TYPE.equals(type) || ANCHOR_NAME_TYPE.equals(type))) { 85 throw new IllegalArgumentException ("The type argument must be either \"name\" or \"href\""); 86 } 87 88 return new StringBuffer (100) 89 .append("<a ") 90 .append(type) 91 .append("=\"") 92 .append(value) 93 .append("\">") 94 .append(display) 95 .append("</a>") 96 .toString(); 97 } 98 99 110 public static String createSelectFormField(String name, String onChange) { 111 StringBuffer temp = new StringBuffer (60).append("<select name=\"").append(name); 112 113 if (onChange != null) { 114 temp.append("\" onChange=\"").append(onChange); 115 } 116 117 return temp.append("\">").toString(); 118 } 119 120 132 public static String createSelectOption(String value, String display, boolean selected) { 133 StringBuffer temp = new StringBuffer (65).append("<option value=\"").append(value).append("\""); 134 135 if (selected) { 136 temp.append(" selected"); 137 } 138 139 return temp.append(">").append(display).append("</option>").toString(); 140 } 141 142 155 public static String createTextFormField(String name, String value, int size, int maxLength) { 156 return createInputFormField("text", name, value, size, maxLength, null, null, null, null, false, false, false); 157 } 158 159 171 public static String createFileFormField(String name, String value, int size) { 172 return createInputFormField("file", name, value, size, 0, null, null, null, null, false, false, false); 173 } 174 175 186 public static String createHiddenFormField(String name, String value) { 187 return createInputFormField("hidden", name, value, 0, 0, null, null, null, null, false, false, false); 188 } 189 190 201 public static String createSubmitFormButton(String name, String value) { 202 return createInputFormField("submit", name, value, 0, 0, null, null, null, null, false, false, false); 203 } 204 205 221 public static String createInputFormField( 222 String type, 223 String name, 224 String value, 225 int size, 226 int maxLength, 227 String onFocus, 228 String onBlur, 229 String onChange, 230 String onClick, 231 boolean checked, 232 boolean disabled, 233 boolean readOnly) { 234 235 StringBuffer temp = 236 new StringBuffer (150) 237 .append("<input type=\"") 238 .append(type) 239 .append("\" name=\"") 240 .append(name) 241 .append("\" value=\"") 242 .append(value) 243 .append("\""); 244 245 if (size > 0) { 246 temp.append(" size=\"").append(size).append("\""); 247 } 248 if (maxLength > 0) { 249 temp.append(" maxlength=\"").append(maxLength).append("\""); 250 } 251 if (onFocus != null) { 252 temp.append(" onfocus=\"").append(onFocus).append("\""); 253 } 254 if (onBlur != null) { 255 temp.append(" onblur=\"").append(onBlur).append("\""); 256 } 257 if (onChange != null) { 258 temp.append(" onchange=\"").append(onChange).append("\""); 259 } 260 if (onClick != null) { 261 temp.append(" onclick=\"").append(onClick).append("\""); 262 } 263 if (checked) { 264 temp.append(" checked"); 265 } 266 if (disabled) { 267 temp.append(" disabled"); 268 } 269 if (readOnly) { 270 temp.append(" readonly"); 271 } 272 273 return temp.append(">").toString(); 274 } 275 276 293 public static String createTextArea( 294 String name, 295 String content, 296 int rows, 297 int columns, 298 String onFocus, 299 String onBlur, 300 String onChange) { 301 StringBuffer temp = new StringBuffer (50); 302 temp.append("<textarea name=\"").append(name).append("\" rows=\"").append(rows).append("\" cols=\"").append( 303 columns).append( 304 "\""); 305 306 if (onFocus != null) { 307 temp.append(" onfocus=\"").append(onFocus).append("\""); 308 } 309 if (onBlur != null) { 310 temp.append(" onblur=\"").append(onBlur).append("\""); 311 } 312 if (onChange != null) { 313 temp.append(" onchange=\"").append(onChange).append("\""); 314 } 315 316 return temp.append(">").append(content).append("</textarea>").toString(); 317 } 318 } 319 | Popular Tags |