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 raw HTML content to be added to HTML pages 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@1737: public class RawHtml extends Content { bpatel@766: bpatel@766: private String rawHtmlContent; bpatel@766: bpatel@766: public static final Content nbsp = new RawHtml(" "); bpatel@766: bpatel@766: /** bpatel@766: * Constructor to construct a RawHtml object. bpatel@766: * bpatel@766: * @param rawHtml raw HTML text to be added bpatel@766: */ bpatel@766: public RawHtml(String rawHtml) { bpatel@766: rawHtmlContent = nullCheck(rawHtml); 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: */ bpatel@766: public void addContent(Content content) { bpatel@766: throw new DocletAbortException(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * This method is not supported by the class. bpatel@766: * bpatel@766: * @param stringContent string 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: */ bpatel@766: public void addContent(String stringContent) { bpatel@766: throw new DocletAbortException(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public boolean isEmpty() { bpatel@766: return rawHtmlContent.isEmpty(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ jjg@1737: @Override jjg@1364: public String toString() { jjg@1364: return rawHtmlContent; jjg@1364: } jjg@1364: jjg@1737: private enum State { TEXT, ENTITY, TAG, STRING }; jjg@1737: jjg@1737: @Override jjg@1737: public int charCount() { jjg@1741: return charCount(rawHtmlContent); jjg@1741: } jjg@1741: jjg@1741: static int charCount(String htmlText) { jjg@1737: State state = State.TEXT; jjg@1737: int count = 0; jjg@1741: for (int i = 0; i < htmlText.length(); i++) { jjg@1741: char c = htmlText.charAt(i); jjg@1737: switch (state) { jjg@1737: case TEXT: jjg@1737: switch (c) { jjg@1737: case '<': jjg@1737: state = State.TAG; jjg@1737: break; jjg@1737: case '&': jjg@1737: state = State.ENTITY; jjg@1737: count++; jjg@1737: break; jjg@1737: default: jjg@1737: count++; jjg@1737: } jjg@1737: break; jjg@1737: jjg@1737: case ENTITY: jjg@1737: if (!Character.isLetterOrDigit(c)) jjg@1737: state = State.TEXT; jjg@1737: break; jjg@1737: jjg@1737: case TAG: jjg@1737: switch (c) { jjg@1737: case '"': jjg@1737: state = State.STRING; jjg@1737: break; jjg@1737: case '>': jjg@1737: state = State.TEXT; jjg@1737: break; jjg@1737: } jjg@1737: break; jjg@1737: jjg@1737: case STRING: jjg@1737: switch (c) { jjg@1737: case '"': jjg@1737: state = State.TAG; jjg@1737: break; jjg@1737: } jjg@1737: } jjg@1737: } jjg@1737: return count; jjg@1737: } jjg@1737: jjg@1364: /** jjg@1364: * {@inheritDoc} jjg@1364: */ jjg@1364: @Override jjg@1364: public boolean write(Writer out, boolean atNewline) throws IOException { jjg@1364: out.write(rawHtmlContent); jjg@1364: return rawHtmlContent.endsWith(DocletConstants.NL); bpatel@766: } bpatel@766: }