/** * Adds a attribute. For quick and dirty mode, the attribute will be appended to the StringBuffer given in * constructor. Please note: The attribute will be ignored, if the value is null; * * @param name Name of the attribute. * @param value The value of the attribute. Null value are allowed. Those attributes will be ignored. */ public void addAttribute(String name, String value) { if (value == null) { // Do nothing return; } if (stringBuffer != null) { stringBuffer.append(" "); stringBuffer.append(name); stringBuffer.append("=\""); stringBuffer.append(value); stringBuffer.append("\""); } else { attrs.add(new KeyValueBean<String, String>(name, value)); } }
/** Gets the start tag. The attributes added before will be ignored in quick and dirty mode. */ public String getStartTag() { StringBuffer buf = new StringBuffer(); buf.append("<"); buf.append(name); buf.append(">"); if (attrs != null && attrs.size() > 0) { for (KeyValueBean<String, String> prop : attrs) { buf.append(" "); buf.append(prop.getKey()); buf.append("=\""); buf.append(prop.getValue()); buf.append("\""); } } return buf.toString(); }
/** Gets the request string. The attributes added before will be ignored in quick and dirty mode. */ public String getRequestString() { StringBuffer buf = new StringBuffer(); buf.append(url); boolean first = true; if (attrs != null) { for (KeyValueBean<String, String> prop : attrs) { if (first == true) { buf.append("?"); first = false; } else { buf.append("&"); } buf.append(prop.getKey()); buf.append("="); buf.append(HtmlHelper.encodeUrl(prop.getValue().toString())); } } return buf.toString(); } }
/** * Adds a parameter. For quick and dirty mode, the attribute will be appended to the StringBuffer given in * constructor. Please note: The attribute will be ignored, if the value is null; * * @param name Name of the attribute. * @param value The value of the attribute. Null value are allowed. Those attributes will be ignored. */ public void addAttribute(String name, String value) { if (value == null) { // Do nothing return; } if (stringBuffer != null) { if (this.firstAttribute == true) { stringBuffer.append("?"); this.firstAttribute = false; } else { stringBuffer.append("&"); } stringBuffer.append(name); stringBuffer.append(HtmlHelper.encodeUrl(value)); } else { attrs.add(new KeyValueBean<String, String>(name, value)); } }