bpatel@766: /* jjg@1359: * Copyright (c) 2010, 2012, 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.internal.toolkit; bpatel@766: bpatel@766: import com.sun.tools.doclets.internal.toolkit.util.*; bpatel@766: bpatel@766: /** bpatel@766: * A class to create content for javadoc output pages. 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: */ bpatel@766: public abstract class Content { bpatel@766: bpatel@766: /** bpatel@766: * Returns a string representation of the content. bpatel@766: * bpatel@766: * @return string representation of the content bpatel@766: */ bpatel@766: public String toString() { bpatel@766: StringBuilder contentBuilder = new StringBuilder(); bpatel@766: write(contentBuilder); bpatel@766: return contentBuilder.toString(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Adds content to the existing content. bpatel@766: * bpatel@766: * @param content content that needs to be added bpatel@766: */ bpatel@766: public abstract void addContent(Content content); bpatel@766: bpatel@766: /** bpatel@766: * Adds a string content to the existing content. bpatel@766: * bpatel@766: * @param stringContent the string content to be added bpatel@766: */ bpatel@766: public abstract void addContent(String stringContent); bpatel@766: bpatel@766: /** bpatel@766: * Writes content to a StringBuilder. bpatel@766: * bpatel@766: */ bpatel@766: public abstract void write(StringBuilder contentBuilder); bpatel@766: bpatel@766: /** bpatel@766: * Returns true if the content is empty. bpatel@766: * bpatel@766: * @return true if no content to be displayed else return false bpatel@766: */ bpatel@766: public abstract boolean isEmpty(); bpatel@766: bpatel@766: /** bpatel@766: * Returns true if the content is valid. bpatel@766: * bpatel@766: * @return true if the content is valid else return false bpatel@766: */ bpatel@766: public boolean isValid() { bpatel@766: return !isEmpty(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Checks for null values. bpatel@766: * bpatel@766: * @param t reference type to check for null values bpatel@766: * @return the reference type if not null or else throws a null pointer exception bpatel@766: */ bpatel@766: protected static T nullCheck(T t) { bpatel@766: t.getClass(); bpatel@766: return t; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Returns true if the content ends with a newline character. Empty content bpatel@766: * is considered as ending with new line. bpatel@766: * bpatel@766: * @param contentBuilder content to test for newline character at the end bpatel@766: * @return true if the content ends with newline. bpatel@766: */ bpatel@819: protected boolean endsWithNewLine(StringBuilder contentBuilder) { bpatel@819: int contentLength = contentBuilder.length(); bpatel@819: if (contentLength == 0) { bpatel@819: return true; bpatel@819: } bpatel@819: int nlLength = DocletConstants.NL.length(); bpatel@819: if (contentLength < nlLength) { bpatel@819: return false; bpatel@819: } bpatel@819: int contentIndex = contentLength - 1; bpatel@819: int nlIndex = nlLength - 1; bpatel@819: while (nlIndex >= 0) { bpatel@819: if (contentBuilder.charAt(contentIndex) != DocletConstants.NL.charAt(nlIndex)) { bpatel@819: return false; bpatel@819: } bpatel@819: contentIndex--; bpatel@819: nlIndex--; bpatel@819: } bpatel@819: return true; bpatel@766: } bpatel@766: }