8011668: Allow HTMLWriter.getResource to take Content args
authorjjg
Tue, 14 May 2013 10:14:53 -0700
changeset 17563 e8ddeb9bd17c
parent 17562 c84f1d7fa11d
child 17564 c329fe11193d
8011668: Allow HTMLWriter.getResource to take Content args Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java
langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties
langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -160,8 +160,9 @@
     protected void addClassInfo(ClassDoc cd, Content contentTree) {
         contentTree.addContent(getResource("doclet.in",
                 Util.getTypeName(configuration, cd, false),
-                getPackageLinkString(cd.containingPackage(),
-                Util.escapeHtmlChars(Util.getPackageName(cd.containingPackage())), false)));
+                getPackageLink(cd.containingPackage(),
+                    Util.getPackageName(cd.containingPackage()))
+                ));
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -331,11 +331,10 @@
         for (Iterator<PackageDoc> it = pkgSet.iterator(); it.hasNext();) {
             PackageDoc pkg = it.next();
             Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(pkg.name()));
-            Content link = new RawHtml(
-                    configuration.getText("doclet.ClassUse_Uses.of.0.in.1",
+            Content link = getResource("doclet.ClassUse_Uses.of.0.in.1",
                     getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER,
-                    classdoc)).toString(),
-                    getPackageLinkString(pkg, Util.escapeHtmlChars(Util.getPackageName(pkg)), false)));
+                    classdoc)),
+                    getPackageLink(pkg, Util.getPackageName(pkg)));
             Content heading = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, link);
             li.addContent(heading);
             addClassUse(pkg, li);
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Tue May 14 10:14:53 2013 -0700
@@ -31,6 +31,7 @@
 import javax.tools.JavaFileManager;
 
 import com.sun.javadoc.*;
+import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
 import com.sun.tools.doclets.internal.toolkit.*;
 import com.sun.tools.doclets.internal.toolkit.util.*;
 import com.sun.tools.doclint.DocLint;
@@ -562,4 +563,9 @@
         }
         return true;
     }
+
+    @Override
+    public Content getContentForResource() {
+        return new ContentBuilder();
+    }
 }
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -121,7 +121,7 @@
                 getResource("doclet.Frame_Alert"));
         noframes.addContent(noframesHead);
         Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message",
-                getHyperLinkString(configuration.topFile,
+                getHyperLink(configuration.topFile,
                 configuration.getText("doclet.Non_Frame_Version"))));
         noframes.addContent(p);
         contentTree.addContent(noframes);
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, 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
@@ -113,7 +113,7 @@
                 getResource("doclet.Overview"));
             Content liOverview = HtmlTree.LI(HtmlStyle.blockList, overviewHeading);
             Content line3 = getResource("doclet.Help_line_3",
-                    getHyperLinkString(DocPaths.OVERVIEW_SUMMARY,
+                    getHyperLink(DocPaths.OVERVIEW_SUMMARY,
                     configuration.getText("doclet.Overview")));
             Content overviewPara = HtmlTree.P(line3);
             liOverview.addContent(overviewPara);
@@ -234,8 +234,9 @@
                     getResource("doclet.Help_line_16"));
             Content liTree = HtmlTree.LI(HtmlStyle.blockList, treeHead);
             Content line17 = getResource("doclet.Help_line_17_with_tree_link",
-                    getHyperLinkString(DocPaths.OVERVIEW_TREE,
-                    configuration.getText("doclet.Class_Hierarchy")));
+                    getHyperLink(DocPaths.OVERVIEW_TREE,
+                    configuration.getText("doclet.Class_Hierarchy")),
+                    HtmlTree.CODE(new StringContent("java.lang.Object")));
             Content treePara = HtmlTree.P(line17);
             liTree.addContent(treePara);
             HtmlTree tul = new HtmlTree(HtmlTag.UL);
@@ -252,19 +253,19 @@
                     getResource("doclet.Deprecated_API"));
             Content liDeprecated = HtmlTree.LI(HtmlStyle.blockList, dHead);
             Content line20 = getResource("doclet.Help_line_20_with_deprecated_api_link",
-                    getHyperLinkString(DocPaths.DEPRECATED_LIST,
+                    getHyperLink(DocPaths.DEPRECATED_LIST,
                     configuration.getText("doclet.Deprecated_API")));
             Content dPara = HtmlTree.P(line20);
             liDeprecated.addContent(dPara);
             ul.addContent(liDeprecated);
         }
         if (configuration.createindex) {
-            String indexlink;
+            Content indexlink;
             if (configuration.splitindex) {
-                indexlink = getHyperLinkString(DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1)),
+                indexlink = getHyperLink(DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1)),
                         configuration.getText("doclet.Index"));
             } else {
-                indexlink = getHyperLinkString(DocPaths.INDEX_ALL,
+                indexlink = getHyperLink(DocPaths.INDEX_ALL,
                         configuration.getText("doclet.Index"));
             }
             Content indexHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
@@ -293,7 +294,7 @@
                 getResource("doclet.All_Classes"));
         Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead);
         Content line27 = getResource("doclet.Help_line_27",
-                getHyperLinkString(DocPaths.ALLCLASSES_NOFRAME,
+                getHyperLink(DocPaths.ALLCLASSES_NOFRAME,
                 configuration.getText("doclet.All_Classes")));
         Content allclassesPara = HtmlTree.P(line27);
         liAllClasses.addContent(allclassesPara);
@@ -309,7 +310,7 @@
                 getResource("doclet.Constants_Summary"));
         Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead);
         Content line29 = getResource("doclet.Help_line_29",
-                getHyperLinkString(DocPaths.CONSTANT_VALUES,
+                getHyperLink(DocPaths.CONSTANT_VALUES,
                 configuration.getText("doclet.Constants_Summary")));
         Content constPara = HtmlTree.P(line29);
         liConst.addContent(constPara);
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -1049,6 +1049,17 @@
      * @param label the label for the link.
      * @return a content tree for the package link.
      */
+    public Content getPackageLink(PackageDoc pkg, String label) {
+        return getPackageLink(pkg, new StringContent(label));
+    }
+
+    /**
+     * Return the link to the given package.
+     *
+     * @param pkg the package to link to.
+     * @param label the label for the link.
+     * @return a content tree for the package link.
+     */
     public Content getPackageLink(PackageDoc pkg, Content label) {
         boolean included = pkg != null && pkg.isIncluded();
         if (! included) {
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -115,7 +115,7 @@
     protected void generatePackageTreeFile() throws IOException {
         Content body = getPackageTreeHeader();
         Content headContent = getResource("doclet.Hierarchy_For_Package",
-                Util.escapeHtmlChars(Util.getPackageName(packagedoc)));
+                Util.getPackageName(packagedoc));
         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
                 HtmlStyle.title, headContent);
         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java	Tue May 14 10:14:53 2013 -0700
@@ -81,6 +81,7 @@
         return true;
     }
 
+    @Override
     public int charCount() {
         int n = 0;
         for (Content c : contents)
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -82,6 +82,10 @@
         return getHyperLinkString(link, label, false, "", "", "");
     }
 
+    public Content getHyperLink(DocPath link, String label) {
+        return getHyperLink(link, new StringContent(label), false, "", "", "");
+    }
+
     public String getHyperLinkString(DocLink link, String label) {
         return getHyperLinkString(link, label, false, "", "", "");
     }
@@ -184,6 +188,13 @@
         return retlink.toString();
     }
 
+    public Content getHyperLink(DocPath link,
+                               Content label, boolean strong,
+                               String stylename, String title, String target) {
+        return getHyperLink(new DocLink(link), label, strong,
+                stylename, title, target);
+    }
+
     public Content getHyperLink(DocLink link,
                                Content label, boolean strong,
                                String stylename, String title, String target) {
@@ -282,20 +293,6 @@
         write(htmlDocument);
     }
 
-    /**
-     * Print the appropriate spaces to format the class tree in the class page.
-     *
-     * @param len   Number of spaces.
-     */
-    public String spaces(int len) {
-        String space = "";
-
-        for (int i = 0; i < len; i++) {
-            space += " ";
-        }
-        return space;
-    }
-
     protected String getGeneratedByString() {
         Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
         Date today = calendar.getTime();
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Tue May 14 10:14:53 2013 -0700
@@ -27,6 +27,8 @@
 
 import java.io.*;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import com.sun.tools.doclets.internal.toolkit.*;
 import com.sun.tools.doclets.internal.toolkit.util.*;
@@ -252,30 +254,30 @@
      * @return a content tree for the text
      */
     public Content getResource(String key) {
-        return new StringContent(configuration.getText(key));
+        return configuration.getResource(key);
     }
 
     /**
      * Get the configuration string as a content.
      *
      * @param key the key to look for in the configuration file
-     * @param a1 string argument added to configuration text
+     * @param o   string or content argument added to configuration text
      * @return a content tree for the text
      */
-    public Content getResource(String key, String a1) {
-        return new RawHtml(configuration.getText(key, a1));
+    public Content getResource(String key, Object o) {
+        return configuration.getResource(key, o);
     }
 
     /**
      * Get the configuration string as a content.
      *
      * @param key the key to look for in the configuration file
-     * @param a1 string argument added to configuration text
-     * @param a2 string argument added to configuration text
+     * @param o1  string or content argument added to configuration text
+     * @param o2  string or content argument added to configuration text
      * @return a content tree for the text
      */
-    public Content getResource(String key, String a1, String a2) {
-        return new RawHtml(configuration.getText(key, a1, a2));
+    public Content getResource(String key, Object o0, Object o1) {
+        return configuration.getResource(key, o0, o1);
     }
 
     /**
--- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Tue May 14 10:14:53 2013 -0700
@@ -132,7 +132,7 @@
 doclet.Help_line_14=Use
 doclet.Help_line_15=Each documented package, class and interface has its own Use page.  This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A.  You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
 doclet.Help_line_16=Tree (Class Hierarchy)
-doclet.Help_line_17_with_tree_link=There is a {0} page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with <code>java.lang.Object</code>. The interfaces do not inherit from <code>java.lang.Object</code>.
+doclet.Help_line_17_with_tree_link=There is a {0} page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with {1}. The interfaces do not inherit from {1}.
 doclet.Help_line_18=When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
 doclet.Help_line_19=When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
 doclet.Help_line_20_with_deprecated_api_link=The {0} page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
--- a/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Tue May 14 10:14:53 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Tue May 14 10:14:53 2013 -0700
@@ -27,6 +27,8 @@
 
 import java.io.*;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import com.sun.javadoc.*;
 import com.sun.tools.javac.sym.Profiles;
@@ -825,6 +827,82 @@
         }
     }
 
+    public abstract Content getContentForResource();
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @return a content tree for the text
+     */
+    public Content getResource(String key) {
+        Content c = getContentForResource();
+        c.addContent(getText(key));
+        return c;
+    }
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @param o   string or content argument added to configuration text
+     * @return a content tree for the text
+     */
+    public Content getResource(String key, Object o) {
+        return getResource(key, o, null, null);
+    }
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @param o   string or content argument added to configuration text
+     * @return a content tree for the text
+     */
+    public Content getResource(String key, Object o1, Object o2) {
+        return getResource(key, o1, o2, null);
+    }
+
+    /**
+     * Get the configuration string as a content.
+     *
+     * @param key the key to look for in the configuration file
+     * @param o1  string or content argument added to configuration text
+     * @param o2  string or content argument added to configuration text
+     * @return a content tree for the text
+     */
+    public Content getResource(String key, Object o0, Object o1, Object o2) {
+        Content c = getContentForResource();
+        Pattern p = Pattern.compile("\\{([012])\\}");
+        String text = getText(key);
+        Matcher m = p.matcher(text);
+        int start = 0;
+        while (m.find(start)) {
+            c.addContent(text.substring(start, m.start()));
+
+            Object o = null;
+            switch (m.group(1).charAt(0)) {
+                case '0': o = o0; break;
+                case '1': o = o1; break;
+                case '2': o = o2; break;
+            }
+
+            if (o == null) {
+                c.addContent("{" + m.group(1) + "}");
+            } else if (o instanceof String) {
+                c.addContent((String) o);
+            } else if (o instanceof Content) {
+                c.addContent((Content) o);
+            }
+
+            start = m.end();
+        }
+
+        c.addContent(text.substring(start));
+        return c;
+    }
+
+
     /**
      * Return true if the ClassDoc element is getting documented, depending upon
      * -nodeprecated option and the deprecation information. Return true if