/** * Returns encoded HTML text. */ public String getTextValue() { if (encodedText == null) { encodedText = HtmlEncoder.text(nodeValue); } return encodedText; }
/** * Renders attribute. */ protected void renderAttribute(final Node node, final Attribute attribute, final Appendable appendable) throws IOException { String name = resolveAttributeName(node, attribute); String value = attribute.getValue(); appendable.append(name); if (value != null) { appendable.append('='); appendable.append('\"'); appendable.append(HtmlEncoder.attributeDoubleQuoted(value)); appendable.append('\"'); } }
/** * Encodes attribute value that will be double quoted. * In this case, only these entities are encoded: * <ul> * <li><code>&</code> with <code>&amp;</code></li> * <li><code>"</code> with <code>&quot;</code></li> * <li><code>& </code></li> * </ul> */ public static String attributeDoubleQuoted(final CharSequence value) { return encode(value, ATTR_DQ, LEN); }
@Test void testEncodeText() { String html = "< & \" ' > \r\n \n \t"; assertEquals("< & \" ' > \r\n \n \t", HtmlEncoder.text(html)); assertEquals("< & " ' > \r\n \n \t", HtmlEncoder.xml(html)); html = ""; assertEquals("", HtmlEncoder.text(html)); assertEquals("", HtmlEncoder.text(null)); }
@Test void testEncodeAttribute() { String html = "< & \" ' > \r\n \n \t"; assertEquals("< & " ' > \r\n \n \t", HtmlEncoder.attributeDoubleQuoted(html)); assertEquals("< & \" ' > \r\n \n \t", HtmlEncoder.attributeSingleQuoted(html)); }
@Override public void text(final CharSequence text) { try { appendable.append(HtmlEncoder.text(text)); } catch (IOException ioex) { throw new LagartoException(ioex); } }
private void appendTo(final Appendable out) { try { out.append(type.getStartString()); out.append(name); if (attributesCount > 0) { for (int i = 0; i < attributesCount; i++) { out.append(' '); out.append(attrNames[i]); final CharSequence value = attrValues[i]; if (value != null) { out.append('=').append('"'); out.append(HtmlEncoder.attributeDoubleQuoted(value)); out.append('"'); } } } out.append(type.getEndString()); } catch (IOException ioex) { throw new LagartoException(ioex); } }
/** * Encodes a string to HTML-safe text. The following characters are replaced: * <ul> * <li><code>&</code> with <code>&amp;</code></li> * <li><code><</code> with <code>&lt;</code></li> * <li><code>></code> with <code>&gt;</code></li> * <li><code>\u00A0</code> with <code> </code></li> * </ul> */ public static String text(final CharSequence text) { return encode(text, TEXT, LEN); }
out.print(HtmlEncoder.text(message)); } catch (IOException ioex) {
/** * Renders attribute. */ protected void renderAttribute(final Node node, final Attribute attribute, final Appendable appendable) throws IOException { String name = resolveAttributeName(node, attribute); String value = attribute.getValue(); appendable.append(name); if (value != null) { appendable.append('='); appendable.append('\"'); appendable.append(HtmlEncoder.attributeDoubleQuoted(value)); appendable.append('\"'); } }
/** * Encodes XML string. In XML there are only 5 predefined character entities. */ public static String xml(final CharSequence text) { return encode(text, TEXT_XML, LEN_XML); }
private void appendTo(final Appendable out) { try { out.append(type.getStartString()); out.append(name); if (attributesCount > 0) { for (int i = 0; i < attributesCount; i++) { out.append(' '); out.append(attrNames[i]); final CharSequence value = attrValues[i]; if (value != null) { out.append('=').append('"'); out.append(HtmlEncoder.attributeDoubleQuoted(value)); out.append('"'); } } } out.append(type.getEndString()); } catch (IOException ioex) { throw new LagartoException(ioex); } }
/** * Encodes attribute value that will be single quoted. * In this case, only two entities are encoded: * <ul> * <li><code>&</code> with <code>&amp;</code></li> * <li><code>'</code> with <code>&#39;</code></li> * <li><code>& </code></li> * </ul> */ public static String attributeSingleQuoted(final CharSequence value) { return encode(value, ATTR_SQ, LEN); }
/** * Returns encoded HTML text. */ public String getTextValue() { if (encodedText == null) { encodedText = HtmlEncoder.text(nodeValue); } return encodedText; }
/** * Encodes XML string. In XML there are only 5 predefined character entities. */ public static String xml(final CharSequence text) { return encode(text, TEXT_XML, LEN_XML); }
@Override public void text(final CharSequence text) { try { appendable.append(HtmlEncoder.text(text)); } catch (IOException ioex) { throw new LagartoException(ioex); } }
/** * Encodes attribute value that will be single quoted. * In this case, only two entities are encoded: * <ul> * <li><code>&</code> with <code>&amp;</code></li> * <li><code>'</code> with <code>&#39;</code></li> * <li><code>& </code></li> * </ul> */ public static String attributeSingleQuoted(final CharSequence value) { return encode(value, ATTR_SQ, LEN); }
out.print(HtmlEncoder.text(message)); } catch (IOException ioex) {
/** * Encodes attribute value that will be double quoted. * In this case, only these entities are encoded: * <ul> * <li><code>&</code> with <code>&amp;</code></li> * <li><code>"</code> with <code>&quot;</code></li> * <li><code>& </code></li> * </ul> */ public static String attributeDoubleQuoted(final CharSequence value) { return encode(value, ATTR_DQ, LEN); }