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  */
  25 
  26 package com.sun.tools.doclets.formats.html.markup;
  27 
  28 import java.io.IOException;
  29 import java.io.Writer;
  30 import java.util.*;
  31 
  32 import com.sun.tools.doclets.internal.toolkit.Content;
  33 import com.sun.tools.doclets.internal.toolkit.util.*;
  34 
  35 /**
  36  * Class for generating an HTML document for javadoc output.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  *
  43  * @author Bhavesh Patel
  44  */
  45 public class HtmlDocument extends Content {
  46 
  47     private List<Content> docContent = Collections.<Content>emptyList();
  48 
  49     /**
  50      * Constructor to construct an HTML document.
  51      *
  52      * @param docType document type for the HTML document
  53      * @param docComment comment for the document
  54      * @param htmlTree HTML tree of the document
  55      */
  56     public HtmlDocument(Content docType, Content docComment, Content htmlTree) {
  57         docContent = new ArrayList<>();
  58         addContent(nullCheck(docType));
  59         addContent(nullCheck(docComment));
  60         addContent(nullCheck(htmlTree));
  61     }
  62 
  63     /**
  64      * Constructor to construct an HTML document.
  65      *
  66      * @param docType document type for the HTML document
  67      * @param htmlTree HTML tree of the document
  68      */
  69     public HtmlDocument(Content docType, Content htmlTree) {
  70         docContent = new ArrayList<>();
  71         addContent(nullCheck(docType));
  72         addContent(nullCheck(htmlTree));
  73     }
  74 
  75     /**
  76      * Adds content for the HTML document.
  77      *
  78      * @param htmlContent html content to be added
  79      */
  80     public final void addContent(Content htmlContent) {
  81         if (htmlContent.isValid())
  82             docContent.add(htmlContent);
  83     }
  84 
  85     /**
  86      * This method is not supported by the class.
  87      *
  88      * @param stringContent string content that needs to be added
  89      * @throws DocletAbortException this method will always throw a
  90      *                              DocletAbortException because it
  91      *                              is not supported.
  92      */
  93     public void addContent(String stringContent) {
  94         throw new DocletAbortException("not supported");
  95     }
  96 
  97     /**
  98      * {@inheritDoc}
  99      */
 100     public boolean isEmpty() {
 101         return (docContent.isEmpty());
 102     }
 103 
 104     /**
 105      * {@inheritDoc}
 106      */
 107     public boolean write(Writer out,  boolean atNewline) throws IOException {
 108         for (Content c : docContent)
 109             atNewline = c.write(out, atNewline);
 110         return atNewline;
 111     }
 112 }