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

Tue, 18 Jun 2013 20:56:04 -0700

author
mfang
date
Tue, 18 Jun 2013 20:56:04 -0700
changeset 1841
792c40d5185a
parent 1741
4c43e51433ba
child 1985
0e6577980181
permissions
-rw-r--r--

8015657: jdk8 l10n resource file translation update 3
Reviewed-by: yhuang

     1 /*
     2  * Copyright (c) 2010, 2013, 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 java.io.IOException;
    29 import java.io.StringWriter;
    30 import java.io.Writer;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 /**
    35  * A class to create content for javadoc output pages.
    36  *
    37  *  <p><b>This is NOT part of any supported API.
    38  *  If you write code that depends on this, you do so at your own risk.
    39  *  This code and its internal interfaces are subject to change or
    40  *  deletion without notice.</b>
    41  *
    42  * @author Bhavesh Patel
    43  */
    44 public abstract class Content {
    46     /**
    47      * Returns a string representation of the content.
    48      *
    49      * @return string representation of the content
    50      */
    51     @Override
    52     public String toString() {
    53         StringWriter out = new StringWriter();
    54         try {
    55             write(out, true);
    56         } catch (IOException e) {
    57             // cannot happen from StringWriter
    58             throw new DocletAbortException();
    59         }
    60         return out.toString();
    61     }
    63     /**
    64      * Adds content to the existing content.
    65      *
    66      * @param content content that needs to be added
    67      */
    68     public abstract void addContent(Content content);
    70     /**
    71      * Adds a string content to the existing content.
    72      *
    73      * @param stringContent the string content to be added
    74      */
    75     public abstract void addContent(String stringContent);
    77     /**
    78      * Writes content to a writer.
    79      *
    80      */
    81     public abstract boolean write(Writer writer, boolean atNewline) throws IOException ;
    83     /**
    84      * Returns true if the content is empty.
    85      *
    86      * @return true if no content to be displayed else return false
    87      */
    88     public abstract boolean isEmpty();
    90     /**
    91      * Returns true if the content is valid.
    92      *
    93      * @return true if the content is valid else return false
    94      */
    95     public boolean isValid() {
    96         return !isEmpty();
    97     }
    99     /**
   100      * Return the number of characters of plain text content in this object
   101      * (optional operation.)
   102      * @return the number of characters of plain text content in this
   103      */
   104     public int charCount() {
   105         return 0;
   106     }
   108     /**
   109      * Checks for null values.
   110      *
   111      * @param t reference type to check for null values
   112      * @return the reference type if not null or else throws a null pointer exception
   113      */
   114     protected static <T> T nullCheck(T t) {
   115         t.getClass();
   116         return t;
   117     }
   118 }

mercurial