langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/StringContent.java
changeset 7614 cfadc977ca75
child 14260 727a84636f12
equal deleted inserted replaced
7336:3fd30668e9b5 7614:cfadc977ca75
       
     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  */
       
    25 
       
    26 package com.sun.tools.doclets.formats.html.markup;
       
    27 
       
    28 import com.sun.tools.doclets.internal.toolkit.Content;
       
    29 import com.sun.tools.doclets.internal.toolkit.util.*;
       
    30 
       
    31 /**
       
    32  * Class for generating string content for HTML tags of javadoc output.
       
    33  *
       
    34  * @author Bhavesh Patel
       
    35  */
       
    36 public class StringContent extends Content{
       
    37 
       
    38     private StringBuilder stringContent;
       
    39 
       
    40     /**
       
    41      * Constructor to construct StringContent object.
       
    42      */
       
    43     public StringContent() {
       
    44         stringContent = new StringBuilder();
       
    45     }
       
    46 
       
    47     /**
       
    48      * Constructor to construct StringContent object with some initial content.
       
    49      *
       
    50      * @param initialContent initial content for the object
       
    51      */
       
    52     public StringContent(String initialContent) {
       
    53         stringContent = new StringBuilder(
       
    54                 Util.escapeHtmlChars(nullCheck(initialContent)));
       
    55     }
       
    56 
       
    57     /**
       
    58      * This method is not supported by the class.
       
    59      *
       
    60      * @param content content that needs to be added
       
    61      * @throws DocletAbortException this method will always throw a
       
    62      *                              DocletAbortException because it
       
    63      *                              is not supported.
       
    64      */
       
    65     public void addContent(Content content) {
       
    66         throw new DocletAbortException();
       
    67     }
       
    68 
       
    69     /**
       
    70      * Adds content for the StringContent object.  The method escapes
       
    71      * HTML characters for the string content that is added.
       
    72      *
       
    73      * @param strContent string content to be added
       
    74      */
       
    75     public void addContent(String strContent) {
       
    76         stringContent.append(Util.escapeHtmlChars(nullCheck(strContent)));
       
    77     }
       
    78 
       
    79     /**
       
    80      * {@inheritDoc}
       
    81      */
       
    82     public boolean isEmpty() {
       
    83         return (stringContent.length() == 0);
       
    84     }
       
    85 
       
    86     /**
       
    87      * {@inheritDoc}
       
    88      */
       
    89     public String toString() {
       
    90         return stringContent.toString();
       
    91     }
       
    92 
       
    93     /**
       
    94      * {@inheritDoc}
       
    95      */
       
    96     public void write(StringBuilder contentBuilder) {
       
    97         contentBuilder.append(stringContent);
       
    98     }
       
    99 }