1 /*
   2  * Copyright (c) 2010, 2015, 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 jdk.javadoc.internal.doclets.formats.html.markup;
  27 
  28 import java.io.IOException;
  29 import java.io.Writer;
  30 
  31 import jdk.javadoc.internal.doclets.toolkit.Content;
  32 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException;
  33 import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
  34 
  35 /**
  36  * Class for generating document type for HTML pages of 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 DocType extends Content {
  46 
  47     private String docType;
  48 
  49     public static final DocType TRANSITIONAL =
  50             new DocType("Transitional", "http://www.w3.org/TR/html4/loose.dtd");
  51 
  52     public static final DocType HTML5 = new DocType();
  53 
  54     /**
  55      * Constructor to construct a DocType object.
  56      *
  57      * @param type the doctype to be added
  58      * @param dtd the dtd of the doctype
  59      */
  60     private DocType(String type, String dtd) {
  61         docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " + type +
  62                 "//EN\" \"" + dtd + "\">" + DocletConstants.NL;
  63     }
  64 
  65     /**
  66      * Constructor to construct a DocType object.
  67      */
  68     private DocType() {
  69         docType = "<!DOCTYPE HTML>" + DocletConstants.NL;
  70     }
  71 
  72     /**
  73      * This method is not supported by the class.
  74      *
  75      * @param content content that needs to be added
  76      * @throws DocletAbortException this method will always throw a
  77      *                              DocletAbortException because it
  78      *                              is not supported.
  79      */
  80     public void addContent(Content content) {
  81         throw new DocletAbortException("not supported");
  82     }
  83 
  84     /**
  85      * This method is not supported by the class.
  86      *
  87      * @param stringContent string content that needs to be added
  88      * @throws DocletAbortException this method will always throw a
  89      *                              DocletAbortException because it
  90      *                              is not supported.
  91      */
  92     public void addContent(String stringContent) {
  93         throw new DocletAbortException("not supported");
  94     }
  95 
  96     /**
  97      * {@inheritDoc}
  98      */
  99     public boolean isEmpty() {
 100         return (docType.length() == 0);
 101     }
 102 
 103     /**
 104      * {@inheritDoc}
 105      */
 106     @Override
 107     public boolean write(Writer out, boolean atNewline) throws IOException {
 108         out.write(docType);
 109         return true; // guaranteed by constructor
 110     }
 111 }