src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/DocType.java
changeset 47848 6b1311fbbaba
parent 47216 71c04702a3d5
child 53562 0d9dee001667
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/DocType.java	Thu Nov 16 15:06:17 2017 -0800
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/DocType.java	Thu Nov 16 15:12:13 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,14 +25,8 @@
 
 package jdk.javadoc.internal.doclets.formats.html.markup;
 
-import java.io.IOException;
-import java.io.Writer;
-
-import jdk.javadoc.internal.doclets.toolkit.Content;
-import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
-
 /**
- * Class for generating document type for HTML pages of javadoc output.
+ *  Supported DOCTYPE declarations.
  *
  *  <p><b>This is NOT part of any supported API.
  *  If you write code that depends on this, you do so at your own risk.
@@ -41,67 +35,22 @@
  *
  * @author Bhavesh Patel
  */
-public class DocType extends Content {
-
-    private String docType;
-
-    public static final DocType TRANSITIONAL =
-            new DocType("Transitional", "http://www.w3.org/TR/html4/loose.dtd");
-
-    public static final DocType HTML5 = new DocType();
+public enum DocType {
+    HTML4_TRANSITIONAL("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
+            + "\"http://www.w3.org/TR/html4/loose.dtd\">"),
+    HTML5("<!DOCTYPE HTML>");
 
-    /**
-     * Constructor to construct a DocType object.
-     *
-     * @param type the doctype to be added
-     * @param dtd the dtd of the doctype
-     */
-    private DocType(String type, String dtd) {
-        docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 " + type +
-                "//EN\" \"" + dtd + "\">" + DocletConstants.NL;
-    }
+    public final String text;
 
-    /**
-     * Constructor to construct a DocType object.
-     */
-    private DocType() {
-        docType = "<!DOCTYPE HTML>" + DocletConstants.NL;
+    DocType(String text) {
+        this.text = text;
     }
 
-    /**
-     * This method is not supported by the class.
-     *
-     * @param content content that needs to be added
-     * @throws UnsupportedOperationException always
-     */
-    public void addContent(Content content) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * This method is not supported by the class.
-     *
-     * @param stringContent string content that needs to be added
-     * @throws UnsupportedOperationException always
-     */
-    @Override
-    public void addContent(CharSequence stringContent) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public boolean isEmpty() {
-        return (docType.length() == 0);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean write(Writer out, boolean atNewline) throws IOException {
-        out.write(docType);
-        return true; // guaranteed by constructor
+    public static DocType forVersion(HtmlVersion v) {
+        switch (v) {
+            case HTML4: return HTML4_TRANSITIONAL;
+            case HTML5: return HTML5;
+            default: throw new IllegalArgumentException();
+        }
     }
 }