bpatel@766: /* jjg@1737: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. bpatel@766: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. bpatel@766: * bpatel@766: * This code is free software; you can redistribute it and/or modify it bpatel@766: * under the terms of the GNU General Public License version 2 only, as bpatel@766: * published by the Free Software Foundation. Oracle designates this bpatel@766: * particular file as subject to the "Classpath" exception as provided bpatel@766: * by Oracle in the LICENSE file that accompanied this code. bpatel@766: * bpatel@766: * This code is distributed in the hope that it will be useful, but WITHOUT bpatel@766: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or bpatel@766: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License bpatel@766: * version 2 for more details (a copy is included in the LICENSE file that bpatel@766: * accompanied this code). bpatel@766: * bpatel@766: * You should have received a copy of the GNU General Public License version bpatel@766: * 2 along with this work; if not, write to the Free Software Foundation, bpatel@766: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. bpatel@766: * bpatel@766: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA bpatel@766: * or visit www.oracle.com if you need additional information or have any bpatel@766: * questions. bpatel@766: */ bpatel@766: bpatel@766: package com.sun.tools.doclets.formats.html.markup; bpatel@766: jjg@1364: import java.io.IOException; jjg@1364: import java.io.Writer; jjg@1364: bpatel@766: import com.sun.tools.doclets.internal.toolkit.Content; bpatel@766: import com.sun.tools.doclets.internal.toolkit.util.*; bpatel@766: bpatel@766: /** bpatel@766: * Class for generating string content for HTML tags of javadoc output. bpatel@766: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * bpatel@766: * @author Bhavesh Patel bpatel@766: */ jjg@1741: public class StringContent extends Content { bpatel@766: bpatel@766: private StringBuilder stringContent; bpatel@766: bpatel@766: /** bpatel@766: * Constructor to construct StringContent object. bpatel@766: */ bpatel@766: public StringContent() { bpatel@766: stringContent = new StringBuilder(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Constructor to construct StringContent object with some initial content. bpatel@766: * bpatel@766: * @param initialContent initial content for the object bpatel@766: */ bpatel@766: public StringContent(String initialContent) { jjg@1746: stringContent = new StringBuilder(); jjg@1746: appendChars(initialContent); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * This method is not supported by the class. bpatel@766: * bpatel@766: * @param content content that needs to be added bpatel@766: * @throws DocletAbortException this method will always throw a bpatel@766: * DocletAbortException because it bpatel@766: * is not supported. bpatel@766: */ jjg@1950: @Override bpatel@766: public void addContent(Content content) { bpatel@766: throw new DocletAbortException(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Adds content for the StringContent object. The method escapes bpatel@766: * HTML characters for the string content that is added. bpatel@766: * bpatel@766: * @param strContent string content to be added bpatel@766: */ jjg@1950: @Override bpatel@766: public void addContent(String strContent) { jjg@1746: appendChars(strContent); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ jjg@1950: @Override bpatel@766: public boolean isEmpty() { bpatel@766: return (stringContent.length() == 0); bpatel@766: } bpatel@766: jjg@1950: @Override jjg@1737: public int charCount() { jjg@1741: return RawHtml.charCount(stringContent.toString()); jjg@1737: } jjg@1737: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ jjg@1950: @Override bpatel@766: public String toString() { bpatel@766: return stringContent.toString(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ jjg@1364: @Override jjg@1364: public boolean write(Writer out, boolean atNewline) throws IOException { jjg@1364: String s = stringContent.toString(); jjg@1364: out.write(s); jjg@1364: return s.endsWith(DocletConstants.NL); bpatel@766: } jjg@1746: jjg@1746: private void appendChars(String s) { jjg@1746: for (int i = 0; i < s.length(); i++) { jjg@1746: char ch = s.charAt(i); jjg@1746: switch (ch) { jjg@1746: case '<': stringContent.append("<"); break; jjg@1746: case '>': stringContent.append(">"); break; jjg@1746: case '&': stringContent.append("&"); break; jjg@1746: default: stringContent.append(ch); break; jjg@1746: } jjg@1746: } jjg@1746: } bpatel@766: }