/** * Does nothing if value is null. * * @param name * @param value * @return the XmlStringBuilder */ public XmlStringBuilder attribute(String name, String value) { assert value != null; sb.append(' ').append(name).append("='"); escape(value); sb.append('\''); return this; }
/** * Write the contents of this <code>XmlStringBuilder</code> to a {@link Writer}. This will write * the single parts one-by-one, avoiding allocation of a big continuous memory block holding the * XmlStringBuilder contents. * * @param writer * @throws IOException */ public void write(Writer writer) throws IOException { for (CharSequence csq : sb.getAsList()) { if (csq instanceof XmlStringBuilder) { ((XmlStringBuilder) csq).write(writer); } else { writer.write(csq.toString()); } } }
@Override public String toString() { return sb.toString(); }
@Override public CharSequence subSequence(int start, int end) { return sb.subSequence(start, end); }
@Override public char charAt(int index) { return sb.charAt(index); }
@Override public int length() { return sb.length(); }
@Override public XmlStringBuilder append(char c) { sb.append(c); return this; }
@Override public XmlStringBuilder append(CharSequence csq, int start, int end) { assert csq != null; sb.append(csq, start, end); return this; }
@Override public XmlStringBuilder append(CharSequence csq) { assert csq != null; sb.append(csq); return this; }
public XmlStringBuilder append(XmlStringBuilder xsb) { assert xsb != null; sb.append(xsb.sb); return this; }
public XmlStringBuilder escape(String text) { assert text != null; sb.append(StringUtils.escapeForXML(text)); return this; }
public XmlStringBuilder optBooleanAttribute(String name, boolean bool) { if (bool) { sb.append(' ').append(name).append("='true'"); } return this; }
/** * Add a right angle bracket '>'. * * @return a reference to this object. */ public XmlStringBuilder rightAngleBracket() { sb.append(RIGHT_ANGLE_BRACKET); return this; }
public XmlStringBuilder closeEmptyElement() { sb.append("/>"); return this; }
public XmlStringBuilder closeElement(String name) { sb.append("</").append(name); rightAngleBracket(); return this; }
public XmlStringBuilder halfOpenElement(String name) { assert (StringUtils.isNotEmpty(name)); sb.append('<').append(name); return this; }