src/share/classes/com/sun/tools/doclets/internal/toolkit/Content.java

Wed, 01 Dec 2010 11:02:38 -0800

author
bpatel
date
Wed, 01 Dec 2010 11:02:38 -0800
changeset 766
90af8d87741f
child 793
ffbf2b2a8611
permissions
-rw-r--r--

6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.internal.toolkit;
    28 import com.sun.tools.doclets.internal.toolkit.util.*;
    30 /**
    31  * A class to create content for javadoc output pages.
    32  *
    33  * @author Bhavesh Patel
    34  */
    35 public abstract class Content {
    37     /**
    38      * Returns a string representation of the content.
    39      *
    40      * @return string representation of the content
    41      */
    42     public String toString() {
    43         StringBuilder contentBuilder = new StringBuilder();
    44         write(contentBuilder);
    45         return contentBuilder.toString();
    46     }
    48     /**
    49      * Adds content to the existing content.
    50      *
    51      * @param content content that needs to be added
    52      */
    53     public abstract void addContent(Content content);
    55     /**
    56      * Adds a string content to the existing content.
    57      *
    58      * @param stringContent the string content to be added
    59      */
    60     public abstract void addContent(String stringContent);
    62     /**
    63      * Writes content to a StringBuilder.
    64      *
    65      */
    66     public abstract void write(StringBuilder contentBuilder);
    68     /**
    69      * Returns true if the content is empty.
    70      *
    71      * @return true if no content to be displayed else return false
    72      */
    73     public abstract boolean isEmpty();
    75     /**
    76      * Returns true if the content is valid.
    77      *
    78      * @return true if the content is valid else return false
    79      */
    80     public boolean isValid() {
    81         return !isEmpty();
    82     }
    84     /**
    85      * Checks for null values.
    86      *
    87      * @param t reference type to check for null values
    88      * @return the reference type if not null or else throws a null pointer exception
    89      */
    90     protected static <T> T nullCheck(T t) {
    91         t.getClass();
    92         return t;
    93     }
    95     /**
    96      * Returns true if the content ends with a newline character. Empty content
    97      * is considered as ending with new line.
    98      *
    99      * @param contentBuilder content to test for newline character at the end
   100      * @return true if the content ends with newline.
   101      */
   102     public boolean endsWithNewLine(StringBuilder contentBuilder) {
   103         return ((contentBuilder.length() == 0) ||
   104                 (contentBuilder.substring(contentBuilder.length() - 1).equals("\n")));
   105     }
   106 }

mercurial