< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java

Print this page

        

*** 98,108 **** * @return this object */ public HtmlTree put(HtmlAttr attrName, String attrValue) { if (attrs.isEmpty()) attrs = new LinkedHashMap<>(3); ! attrs.put(nullCheck(attrName), Entity.escapeHtmlChars(attrValue)); return this; } /** * Sets the "title" attribute for this tag. --- 98,108 ---- * @return this object */ public HtmlTree put(HtmlAttr attrName, String attrValue) { if (attrs.isEmpty()) attrs = new LinkedHashMap<>(3); ! attrs.put(nullCheck(attrName), escapeHtmlChars(attrValue)); return this; } /** * Sets the "title" attribute for this tag.
*** 186,195 **** --- 186,224 ---- for (Content c : content) n += c.charCount(); return n; } + /** + * Given a string, escape all special HTML characters and + * return the result. + * + * @param s The string to check. + * @return the original string with all of the HTML characters escaped. + */ + private static String escapeHtmlChars(String s) { + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + switch (ch) { + // only start building a new string if we need to + case '<': case '>': case '&': + StringBuilder sb = new StringBuilder(s.substring(0, i)); + for ( ; i < s.length(); i++) { + ch = s.charAt(i); + switch (ch) { + case '<': sb.append("&lt;"); break; + case '>': sb.append("&gt;"); break; + case '&': sb.append("&amp;"); break; + default: sb.append(ch); break; + } + } + return sb.toString(); + } + } + return s; + } + /* * The sets of ASCII URI characters to be left unencoded. * See "Uniform Resource Identifier (URI): Generic Syntax" * IETF RFC 3986. https://tools.ietf.org/html/rfc3986 */
*** 686,719 **** htmltree.put(HtmlAttr.SRC, nullCheck(src)); return htmltree; } /** ! * Generates a SECTION tag with style class attribute. * - * @param styleClass the style class for the tag * @return an HtmlTree object for the SECTION tag */ ! public static HtmlTree SECTION(HtmlStyle styleClass) { ! HtmlTree htmlTree = new HtmlTree(HtmlTag.SECTION); ! htmlTree.setStyle(styleClass); ! return htmlTree; } /** ! * Generates a SECTION tag with style class attribute and some content. * - * @param styleClass the style class for the tag * @param body content of the section tag * @return an HtmlTree object for the SECTION tag */ ! public static HtmlTree SECTION(HtmlStyle styleClass, Content body) { ! HtmlTree htmlTree = new HtmlTree(HtmlTag.SECTION, nullCheck(body)); ! if (styleClass != null) { ! htmlTree.setStyle(styleClass); ! } ! return htmlTree; } /** * Generates a SMALL tag with some content. * --- 715,744 ---- htmltree.put(HtmlAttr.SRC, nullCheck(src)); return htmltree; } /** ! * Generates a SECTION tag with role attribute. * * @return an HtmlTree object for the SECTION tag */ ! public static HtmlTree SECTION() { ! HtmlTree htmltree = new HtmlTree(HtmlTag.SECTION); ! htmltree.setRole(Role.REGION); ! return htmltree; } /** ! * Generates a SECTION tag with role attribute and some content. * * @param body content of the section tag * @return an HtmlTree object for the SECTION tag */ ! public static HtmlTree SECTION(Content body) { ! HtmlTree htmltree = new HtmlTree(HtmlTag.SECTION, nullCheck(body)); ! htmltree.setRole(Role.REGION); ! return htmltree; } /** * Generates a SMALL tag with some content. *
< prev index next >