src/share/classes/com/sun/tools/doclets/formats/html/markup/StringContent.java

changeset 1746
bd51ca92c013
parent 1741
4c43e51433ba
child 1950
14faef2b51eb
equal deleted inserted replaced
1745:937aa020c667 1746:bd51ca92c013
56 * Constructor to construct StringContent object with some initial content. 56 * Constructor to construct StringContent object with some initial content.
57 * 57 *
58 * @param initialContent initial content for the object 58 * @param initialContent initial content for the object
59 */ 59 */
60 public StringContent(String initialContent) { 60 public StringContent(String initialContent) {
61 stringContent = new StringBuilder( 61 stringContent = new StringBuilder();
62 Util.escapeHtmlChars(nullCheck(initialContent))); 62 appendChars(initialContent);
63 } 63 }
64 64
65 /** 65 /**
66 * This method is not supported by the class. 66 * This method is not supported by the class.
67 * 67 *
79 * HTML characters for the string content that is added. 79 * HTML characters for the string content that is added.
80 * 80 *
81 * @param strContent string content to be added 81 * @param strContent string content to be added
82 */ 82 */
83 public void addContent(String strContent) { 83 public void addContent(String strContent) {
84 stringContent.append(Util.escapeHtmlChars(nullCheck(strContent))); 84 appendChars(strContent);
85 } 85 }
86 86
87 /** 87 /**
88 * {@inheritDoc} 88 * {@inheritDoc}
89 */ 89 */
109 public boolean write(Writer out, boolean atNewline) throws IOException { 109 public boolean write(Writer out, boolean atNewline) throws IOException {
110 String s = stringContent.toString(); 110 String s = stringContent.toString();
111 out.write(s); 111 out.write(s);
112 return s.endsWith(DocletConstants.NL); 112 return s.endsWith(DocletConstants.NL);
113 } 113 }
114
115 private void appendChars(String s) {
116 for (int i = 0; i < s.length(); i++) {
117 char ch = s.charAt(i);
118 switch (ch) {
119 case '<': stringContent.append("&lt;"); break;
120 case '>': stringContent.append("&gt;"); break;
121 case '&': stringContent.append("&amp;"); break;
122 default: stringContent.append(ch); break;
123 }
124 }
125 }
114 } 126 }

mercurial