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

Fri, 07 Jun 2013 16:12:04 -0700

author
bpatel
date
Fri, 07 Jun 2013 16:12:04 -0700
changeset 1835
536cad596942
parent 1741
4c43e51433ba
child 1985
0e6577980181
permissions
-rw-r--r--

8015997: Additional improvement in Javadoc framing
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 raw HTML content to be added to HTML pages 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@1737 44 public class RawHtml extends Content {
bpatel@766 45
bpatel@766 46 private String rawHtmlContent;
bpatel@766 47
bpatel@766 48 public static final Content nbsp = new RawHtml("&nbsp;");
bpatel@766 49
bpatel@766 50 /**
bpatel@766 51 * Constructor to construct a RawHtml object.
bpatel@766 52 *
bpatel@766 53 * @param rawHtml raw HTML text to be added
bpatel@766 54 */
bpatel@766 55 public RawHtml(String rawHtml) {
bpatel@766 56 rawHtmlContent = nullCheck(rawHtml);
bpatel@766 57 }
bpatel@766 58
bpatel@766 59 /**
bpatel@766 60 * This method is not supported by the class.
bpatel@766 61 *
bpatel@766 62 * @param content content that needs to be added
bpatel@766 63 * @throws DocletAbortException this method will always throw a
bpatel@766 64 * DocletAbortException because it
bpatel@766 65 * is not supported.
bpatel@766 66 */
bpatel@766 67 public void addContent(Content content) {
bpatel@766 68 throw new DocletAbortException();
bpatel@766 69 }
bpatel@766 70
bpatel@766 71 /**
bpatel@766 72 * This method is not supported by the class.
bpatel@766 73 *
bpatel@766 74 * @param stringContent string content that needs to be added
bpatel@766 75 * @throws DocletAbortException this method will always throw a
bpatel@766 76 * DocletAbortException because it
bpatel@766 77 * is not supported.
bpatel@766 78 */
bpatel@766 79 public void addContent(String stringContent) {
bpatel@766 80 throw new DocletAbortException();
bpatel@766 81 }
bpatel@766 82
bpatel@766 83 /**
bpatel@766 84 * {@inheritDoc}
bpatel@766 85 */
bpatel@766 86 public boolean isEmpty() {
bpatel@766 87 return rawHtmlContent.isEmpty();
bpatel@766 88 }
bpatel@766 89
bpatel@766 90 /**
bpatel@766 91 * {@inheritDoc}
bpatel@766 92 */
jjg@1737 93 @Override
jjg@1364 94 public String toString() {
jjg@1364 95 return rawHtmlContent;
jjg@1364 96 }
jjg@1364 97
jjg@1737 98 private enum State { TEXT, ENTITY, TAG, STRING };
jjg@1737 99
jjg@1737 100 @Override
jjg@1737 101 public int charCount() {
jjg@1741 102 return charCount(rawHtmlContent);
jjg@1741 103 }
jjg@1741 104
jjg@1741 105 static int charCount(String htmlText) {
jjg@1737 106 State state = State.TEXT;
jjg@1737 107 int count = 0;
jjg@1741 108 for (int i = 0; i < htmlText.length(); i++) {
jjg@1741 109 char c = htmlText.charAt(i);
jjg@1737 110 switch (state) {
jjg@1737 111 case TEXT:
jjg@1737 112 switch (c) {
jjg@1737 113 case '<':
jjg@1737 114 state = State.TAG;
jjg@1737 115 break;
jjg@1737 116 case '&':
jjg@1737 117 state = State.ENTITY;
jjg@1737 118 count++;
jjg@1737 119 break;
jjg@1737 120 default:
jjg@1737 121 count++;
jjg@1737 122 }
jjg@1737 123 break;
jjg@1737 124
jjg@1737 125 case ENTITY:
jjg@1737 126 if (!Character.isLetterOrDigit(c))
jjg@1737 127 state = State.TEXT;
jjg@1737 128 break;
jjg@1737 129
jjg@1737 130 case TAG:
jjg@1737 131 switch (c) {
jjg@1737 132 case '"':
jjg@1737 133 state = State.STRING;
jjg@1737 134 break;
jjg@1737 135 case '>':
jjg@1737 136 state = State.TEXT;
jjg@1737 137 break;
jjg@1737 138 }
jjg@1737 139 break;
jjg@1737 140
jjg@1737 141 case STRING:
jjg@1737 142 switch (c) {
jjg@1737 143 case '"':
jjg@1737 144 state = State.TAG;
jjg@1737 145 break;
jjg@1737 146 }
jjg@1737 147 }
jjg@1737 148 }
jjg@1737 149 return count;
jjg@1737 150 }
jjg@1737 151
jjg@1364 152 /**
jjg@1364 153 * {@inheritDoc}
jjg@1364 154 */
jjg@1364 155 @Override
jjg@1364 156 public boolean write(Writer out, boolean atNewline) throws IOException {
jjg@1364 157 out.write(rawHtmlContent);
jjg@1364 158 return rawHtmlContent.endsWith(DocletConstants.NL);
bpatel@766 159 }
bpatel@766 160 }

mercurial