/** * Writes the contents of the {@linkplain #getMap() map} as HTML attribute name/value pairs to the specified <code>Writer</code>. * <p> * This is equivalent to {@link #appendTo(Appendable) appendTo}<code>(writer)</code>. * * @param writer the destination <code>java.io.Writer</code> for the output. * @throws IOException if an I/O exception occurs. * @see Attributes#generateHTML(Map attributesMap) */ public void writeTo(final Writer writer) throws IOException { Attributes.appendHTML(writer,map); }
/** * Appends the contents of the {@linkplain #getMap() map} as HTML attribute name/value pairs to the specified <code>Appendable</code> object. * <p> * Each attribute is preceded by a single space, and all values are * {@linkplain CharacterReference#encode(CharSequence) encoded} and enclosed in double quotes. * * @param appendable the destination <code>java.lang.Appendable</code> object for the output. * @throws IOException if an I/O exception occurs. * @see Attributes#generateHTML(Map attributesMap) */ public void appendTo(final Appendable appendable) throws IOException { Attributes.appendHTML(appendable,map); }
/** * Returns the contents of the specified {@linkplain #populateMap(Map,boolean) attributes map} as HTML attribute name/value pairs. * <p> * Each attribute (including the first) is preceded by a single space, and all values are * {@linkplain CharacterReference#encode(CharSequence) encoded} and enclosed in double quotes. * <p> * The map keys must be of type <code>String</code> and values must be objects that implement the <code>CharSequence</code> interface. * <p> * A <code>null</code> value represents an attribute with no value. * * @param attributesMap a map containing attribute name/value pairs. * @return the contents of the specified {@linkplain #populateMap(Map,boolean) attributes map} as HTML attribute name/value pairs. * @see StartTag#generateHTML(String tagName, Map attributesMap, boolean emptyElementTag) */ public static String generateHTML(final Map<String,String> attributesMap) { final StringBuilder sb=new StringBuilder(); try {appendHTML(sb,attributesMap);} catch (IOException ex) {} // IOException never occurs in StringWriter return sb.toString(); }
sb.append('<').append(tagName); try { Attributes.appendHTML(sb,attributesMap); } catch (IOException ex) {throw new RuntimeException(ex);} // never happens if (emptyElementTag)