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

Mon, 18 Jul 2016 23:53:12 +0300

author
aefimov
date
Mon, 18 Jul 2016 23:53:12 +0300
changeset 3315
6f0746b6de9f
parent 1985
0e6577980181
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8138725: Add options for Javadoc generation
Reviewed-by: jjg

bpatel@766 1 /*
jjg@1737 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
bpatel@766 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bpatel@766 4 *
bpatel@766 5 * This code is free software; you can redistribute it and/or modify it
bpatel@766 6 * under the terms of the GNU General Public License version 2 only, as
bpatel@766 7 * published by the Free Software Foundation. Oracle designates this
bpatel@766 8 * particular file as subject to the "Classpath" exception as provided
bpatel@766 9 * by Oracle in the LICENSE file that accompanied this code.
bpatel@766 10 *
bpatel@766 11 * This code is distributed in the hope that it will be useful, but WITHOUT
bpatel@766 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bpatel@766 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bpatel@766 14 * version 2 for more details (a copy is included in the LICENSE file that
bpatel@766 15 * accompanied this code).
bpatel@766 16 *
bpatel@766 17 * You should have received a copy of the GNU General Public License version
bpatel@766 18 * 2 along with this work; if not, write to the Free Software Foundation,
bpatel@766 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bpatel@766 20 *
bpatel@766 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bpatel@766 22 * or visit www.oracle.com if you need additional information or have any
bpatel@766 23 * questions.
bpatel@766 24 */
bpatel@766 25
bpatel@766 26 package com.sun.tools.doclets.formats.html.markup;
bpatel@766 27
jjg@1364 28 import java.io.IOException;
jjg@1364 29 import java.io.Writer;
jjg@1364 30
bpatel@766 31 import com.sun.tools.doclets.internal.toolkit.Content;
bpatel@766 32 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@766 33
bpatel@766 34 /**
bpatel@766 35 * Class for generating string content for HTML tags of javadoc output.
bpatel@766 36 *
jjg@1359 37 * <p><b>This is NOT part of any supported API.
jjg@1359 38 * If you write code that depends on this, you do so at your own risk.
jjg@1359 39 * This code and its internal interfaces are subject to change or
jjg@1359 40 * deletion without notice.</b>
jjg@1359 41 *
bpatel@766 42 * @author Bhavesh Patel
bpatel@766 43 */
jjg@1741 44 public class StringContent extends Content {
bpatel@766 45
bpatel@766 46 private StringBuilder stringContent;
bpatel@766 47
bpatel@766 48 /**
bpatel@766 49 * Constructor to construct StringContent object.
bpatel@766 50 */
bpatel@766 51 public StringContent() {
bpatel@766 52 stringContent = new StringBuilder();
bpatel@766 53 }
bpatel@766 54
bpatel@766 55 /**
bpatel@766 56 * Constructor to construct StringContent object with some initial content.
bpatel@766 57 *
bpatel@766 58 * @param initialContent initial content for the object
bpatel@766 59 */
bpatel@766 60 public StringContent(String initialContent) {
jjg@1746 61 stringContent = new StringBuilder();
jjg@1746 62 appendChars(initialContent);
bpatel@766 63 }
bpatel@766 64
bpatel@766 65 /**
bpatel@766 66 * This method is not supported by the class.
bpatel@766 67 *
bpatel@766 68 * @param content content that needs to be added
bpatel@766 69 * @throws DocletAbortException this method will always throw a
bpatel@766 70 * DocletAbortException because it
bpatel@766 71 * is not supported.
bpatel@766 72 */
jjg@1950 73 @Override
bpatel@766 74 public void addContent(Content content) {
jjg@1985 75 throw new DocletAbortException("not supported");
bpatel@766 76 }
bpatel@766 77
bpatel@766 78 /**
bpatel@766 79 * Adds content for the StringContent object. The method escapes
bpatel@766 80 * HTML characters for the string content that is added.
bpatel@766 81 *
bpatel@766 82 * @param strContent string content to be added
bpatel@766 83 */
jjg@1950 84 @Override
bpatel@766 85 public void addContent(String strContent) {
jjg@1746 86 appendChars(strContent);
bpatel@766 87 }
bpatel@766 88
bpatel@766 89 /**
bpatel@766 90 * {@inheritDoc}
bpatel@766 91 */
jjg@1950 92 @Override
bpatel@766 93 public boolean isEmpty() {
bpatel@766 94 return (stringContent.length() == 0);
bpatel@766 95 }
bpatel@766 96
jjg@1950 97 @Override
jjg@1737 98 public int charCount() {
jjg@1741 99 return RawHtml.charCount(stringContent.toString());
jjg@1737 100 }
jjg@1737 101
bpatel@766 102 /**
bpatel@766 103 * {@inheritDoc}
bpatel@766 104 */
jjg@1950 105 @Override
bpatel@766 106 public String toString() {
bpatel@766 107 return stringContent.toString();
bpatel@766 108 }
bpatel@766 109
bpatel@766 110 /**
bpatel@766 111 * {@inheritDoc}
bpatel@766 112 */
jjg@1364 113 @Override
jjg@1364 114 public boolean write(Writer out, boolean atNewline) throws IOException {
jjg@1364 115 String s = stringContent.toString();
jjg@1364 116 out.write(s);
jjg@1364 117 return s.endsWith(DocletConstants.NL);
bpatel@766 118 }
jjg@1746 119
jjg@1746 120 private void appendChars(String s) {
jjg@1746 121 for (int i = 0; i < s.length(); i++) {
jjg@1746 122 char ch = s.charAt(i);
jjg@1746 123 switch (ch) {
jjg@1746 124 case '<': stringContent.append("&lt;"); break;
jjg@1746 125 case '>': stringContent.append("&gt;"); break;
jjg@1746 126 case '&': stringContent.append("&amp;"); break;
jjg@1746 127 default: stringContent.append(ch); break;
jjg@1746 128 }
jjg@1746 129 }
jjg@1746 130 }
bpatel@766 131 }

mercurial