8011668: Allow HTMLWriter.getResource to take Content args

Tue, 14 May 2013 10:14:53 -0700

author
jjg
date
Tue, 14 May 2013 10:14:53 -0700
changeset 1740
ce4f0769b4b2
parent 1739
e6c5b5ee9fac
child 1741
4c43e51433ba

8011668: Allow HTMLWriter.getResource to take Content args
Reviewed-by: darcy

src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java	Tue May 14 10:14:53 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/AbstractIndexWriter.java	Tue May 14 10:14:53 2013 -0700
     1.3 @@ -160,8 +160,9 @@
     1.4      protected void addClassInfo(ClassDoc cd, Content contentTree) {
     1.5          contentTree.addContent(getResource("doclet.in",
     1.6                  Util.getTypeName(configuration, cd, false),
     1.7 -                getPackageLinkString(cd.containingPackage(),
     1.8 -                Util.escapeHtmlChars(Util.getPackageName(cd.containingPackage())), false)));
     1.9 +                getPackageLink(cd.containingPackage(),
    1.10 +                    Util.getPackageName(cd.containingPackage()))
    1.11 +                ));
    1.12      }
    1.13  
    1.14      /**
     2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Tue May 14 10:14:53 2013 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java	Tue May 14 10:14:53 2013 -0700
     2.3 @@ -331,11 +331,10 @@
     2.4          for (Iterator<PackageDoc> it = pkgSet.iterator(); it.hasNext();) {
     2.5              PackageDoc pkg = it.next();
     2.6              Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(pkg.name()));
     2.7 -            Content link = new RawHtml(
     2.8 -                    configuration.getText("doclet.ClassUse_Uses.of.0.in.1",
     2.9 +            Content link = getResource("doclet.ClassUse_Uses.of.0.in.1",
    2.10                      getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER,
    2.11 -                    classdoc)).toString(),
    2.12 -                    getPackageLinkString(pkg, Util.escapeHtmlChars(Util.getPackageName(pkg)), false)));
    2.13 +                    classdoc)),
    2.14 +                    getPackageLink(pkg, Util.getPackageName(pkg)));
    2.15              Content heading = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, link);
    2.16              li.addContent(heading);
    2.17              addClassUse(pkg, li);
     3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Tue May 14 10:14:53 2013 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Tue May 14 10:14:53 2013 -0700
     3.3 @@ -31,6 +31,7 @@
     3.4  import javax.tools.JavaFileManager;
     3.5  
     3.6  import com.sun.javadoc.*;
     3.7 +import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
     3.8  import com.sun.tools.doclets.internal.toolkit.*;
     3.9  import com.sun.tools.doclets.internal.toolkit.util.*;
    3.10  import com.sun.tools.doclint.DocLint;
    3.11 @@ -562,4 +563,9 @@
    3.12          }
    3.13          return true;
    3.14      }
    3.15 +
    3.16 +    @Override
    3.17 +    public Content getContentForResource() {
    3.18 +        return new ContentBuilder();
    3.19 +    }
    3.20  }
     4.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Tue May 14 10:14:53 2013 -0700
     4.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/FrameOutputWriter.java	Tue May 14 10:14:53 2013 -0700
     4.3 @@ -121,7 +121,7 @@
     4.4                  getResource("doclet.Frame_Alert"));
     4.5          noframes.addContent(noframesHead);
     4.6          Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message",
     4.7 -                getHyperLinkString(configuration.topFile,
     4.8 +                getHyperLink(configuration.topFile,
     4.9                  configuration.getText("doclet.Non_Frame_Version"))));
    4.10          noframes.addContent(p);
    4.11          contentTree.addContent(noframes);
     5.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java	Tue May 14 10:14:53 2013 -0700
     5.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java	Tue May 14 10:14:53 2013 -0700
     5.3 @@ -1,5 +1,5 @@
     5.4  /*
     5.5 - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     5.6 + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
     5.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.8   *
     5.9   * This code is free software; you can redistribute it and/or modify it
    5.10 @@ -113,7 +113,7 @@
    5.11                  getResource("doclet.Overview"));
    5.12              Content liOverview = HtmlTree.LI(HtmlStyle.blockList, overviewHeading);
    5.13              Content line3 = getResource("doclet.Help_line_3",
    5.14 -                    getHyperLinkString(DocPaths.OVERVIEW_SUMMARY,
    5.15 +                    getHyperLink(DocPaths.OVERVIEW_SUMMARY,
    5.16                      configuration.getText("doclet.Overview")));
    5.17              Content overviewPara = HtmlTree.P(line3);
    5.18              liOverview.addContent(overviewPara);
    5.19 @@ -234,8 +234,9 @@
    5.20                      getResource("doclet.Help_line_16"));
    5.21              Content liTree = HtmlTree.LI(HtmlStyle.blockList, treeHead);
    5.22              Content line17 = getResource("doclet.Help_line_17_with_tree_link",
    5.23 -                    getHyperLinkString(DocPaths.OVERVIEW_TREE,
    5.24 -                    configuration.getText("doclet.Class_Hierarchy")));
    5.25 +                    getHyperLink(DocPaths.OVERVIEW_TREE,
    5.26 +                    configuration.getText("doclet.Class_Hierarchy")),
    5.27 +                    HtmlTree.CODE(new StringContent("java.lang.Object")));
    5.28              Content treePara = HtmlTree.P(line17);
    5.29              liTree.addContent(treePara);
    5.30              HtmlTree tul = new HtmlTree(HtmlTag.UL);
    5.31 @@ -252,19 +253,19 @@
    5.32                      getResource("doclet.Deprecated_API"));
    5.33              Content liDeprecated = HtmlTree.LI(HtmlStyle.blockList, dHead);
    5.34              Content line20 = getResource("doclet.Help_line_20_with_deprecated_api_link",
    5.35 -                    getHyperLinkString(DocPaths.DEPRECATED_LIST,
    5.36 +                    getHyperLink(DocPaths.DEPRECATED_LIST,
    5.37                      configuration.getText("doclet.Deprecated_API")));
    5.38              Content dPara = HtmlTree.P(line20);
    5.39              liDeprecated.addContent(dPara);
    5.40              ul.addContent(liDeprecated);
    5.41          }
    5.42          if (configuration.createindex) {
    5.43 -            String indexlink;
    5.44 +            Content indexlink;
    5.45              if (configuration.splitindex) {
    5.46 -                indexlink = getHyperLinkString(DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1)),
    5.47 +                indexlink = getHyperLink(DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1)),
    5.48                          configuration.getText("doclet.Index"));
    5.49              } else {
    5.50 -                indexlink = getHyperLinkString(DocPaths.INDEX_ALL,
    5.51 +                indexlink = getHyperLink(DocPaths.INDEX_ALL,
    5.52                          configuration.getText("doclet.Index"));
    5.53              }
    5.54              Content indexHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
    5.55 @@ -293,7 +294,7 @@
    5.56                  getResource("doclet.All_Classes"));
    5.57          Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead);
    5.58          Content line27 = getResource("doclet.Help_line_27",
    5.59 -                getHyperLinkString(DocPaths.ALLCLASSES_NOFRAME,
    5.60 +                getHyperLink(DocPaths.ALLCLASSES_NOFRAME,
    5.61                  configuration.getText("doclet.All_Classes")));
    5.62          Content allclassesPara = HtmlTree.P(line27);
    5.63          liAllClasses.addContent(allclassesPara);
    5.64 @@ -309,7 +310,7 @@
    5.65                  getResource("doclet.Constants_Summary"));
    5.66          Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead);
    5.67          Content line29 = getResource("doclet.Help_line_29",
    5.68 -                getHyperLinkString(DocPaths.CONSTANT_VALUES,
    5.69 +                getHyperLink(DocPaths.CONSTANT_VALUES,
    5.70                  configuration.getText("doclet.Constants_Summary")));
    5.71          Content constPara = HtmlTree.P(line29);
    5.72          liConst.addContent(constPara);
     6.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 10:14:53 2013 -0700
     6.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue May 14 10:14:53 2013 -0700
     6.3 @@ -1049,6 +1049,17 @@
     6.4       * @param label the label for the link.
     6.5       * @return a content tree for the package link.
     6.6       */
     6.7 +    public Content getPackageLink(PackageDoc pkg, String label) {
     6.8 +        return getPackageLink(pkg, new StringContent(label));
     6.9 +    }
    6.10 +
    6.11 +    /**
    6.12 +     * Return the link to the given package.
    6.13 +     *
    6.14 +     * @param pkg the package to link to.
    6.15 +     * @param label the label for the link.
    6.16 +     * @return a content tree for the package link.
    6.17 +     */
    6.18      public Content getPackageLink(PackageDoc pkg, Content label) {
    6.19          boolean included = pkg != null && pkg.isIncluded();
    6.20          if (! included) {
     7.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Tue May 14 10:14:53 2013 -0700
     7.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/PackageTreeWriter.java	Tue May 14 10:14:53 2013 -0700
     7.3 @@ -115,7 +115,7 @@
     7.4      protected void generatePackageTreeFile() throws IOException {
     7.5          Content body = getPackageTreeHeader();
     7.6          Content headContent = getResource("doclet.Hierarchy_For_Package",
     7.7 -                Util.escapeHtmlChars(Util.getPackageName(packagedoc)));
     7.8 +                Util.getPackageName(packagedoc));
     7.9          Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
    7.10                  HtmlStyle.title, headContent);
    7.11          Content div = HtmlTree.DIV(HtmlStyle.header, heading);
     8.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java	Tue May 14 10:14:53 2013 -0700
     8.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/ContentBuilder.java	Tue May 14 10:14:53 2013 -0700
     8.3 @@ -81,6 +81,7 @@
     8.4          return true;
     8.5      }
     8.6  
     8.7 +    @Override
     8.8      public int charCount() {
     8.9          int n = 0;
    8.10          for (Content c : contents)
     9.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Tue May 14 10:14:53 2013 -0700
     9.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java	Tue May 14 10:14:53 2013 -0700
     9.3 @@ -82,6 +82,10 @@
     9.4          return getHyperLinkString(link, label, false, "", "", "");
     9.5      }
     9.6  
     9.7 +    public Content getHyperLink(DocPath link, String label) {
     9.8 +        return getHyperLink(link, new StringContent(label), false, "", "", "");
     9.9 +    }
    9.10 +
    9.11      public String getHyperLinkString(DocLink link, String label) {
    9.12          return getHyperLinkString(link, label, false, "", "", "");
    9.13      }
    9.14 @@ -184,6 +188,13 @@
    9.15          return retlink.toString();
    9.16      }
    9.17  
    9.18 +    public Content getHyperLink(DocPath link,
    9.19 +                               Content label, boolean strong,
    9.20 +                               String stylename, String title, String target) {
    9.21 +        return getHyperLink(new DocLink(link), label, strong,
    9.22 +                stylename, title, target);
    9.23 +    }
    9.24 +
    9.25      public Content getHyperLink(DocLink link,
    9.26                                 Content label, boolean strong,
    9.27                                 String stylename, String title, String target) {
    9.28 @@ -282,20 +293,6 @@
    9.29          write(htmlDocument);
    9.30      }
    9.31  
    9.32 -    /**
    9.33 -     * Print the appropriate spaces to format the class tree in the class page.
    9.34 -     *
    9.35 -     * @param len   Number of spaces.
    9.36 -     */
    9.37 -    public String spaces(int len) {
    9.38 -        String space = "";
    9.39 -
    9.40 -        for (int i = 0; i < len; i++) {
    9.41 -            space += " ";
    9.42 -        }
    9.43 -        return space;
    9.44 -    }
    9.45 -
    9.46      protected String getGeneratedByString() {
    9.47          Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
    9.48          Date today = calendar.getTime();
    10.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Tue May 14 10:14:53 2013 -0700
    10.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java	Tue May 14 10:14:53 2013 -0700
    10.3 @@ -27,6 +27,8 @@
    10.4  
    10.5  import java.io.*;
    10.6  import java.util.*;
    10.7 +import java.util.regex.Matcher;
    10.8 +import java.util.regex.Pattern;
    10.9  
   10.10  import com.sun.tools.doclets.internal.toolkit.*;
   10.11  import com.sun.tools.doclets.internal.toolkit.util.*;
   10.12 @@ -252,30 +254,30 @@
   10.13       * @return a content tree for the text
   10.14       */
   10.15      public Content getResource(String key) {
   10.16 -        return new StringContent(configuration.getText(key));
   10.17 +        return configuration.getResource(key);
   10.18      }
   10.19  
   10.20      /**
   10.21       * Get the configuration string as a content.
   10.22       *
   10.23       * @param key the key to look for in the configuration file
   10.24 -     * @param a1 string argument added to configuration text
   10.25 +     * @param o   string or content argument added to configuration text
   10.26       * @return a content tree for the text
   10.27       */
   10.28 -    public Content getResource(String key, String a1) {
   10.29 -        return new RawHtml(configuration.getText(key, a1));
   10.30 +    public Content getResource(String key, Object o) {
   10.31 +        return configuration.getResource(key, o);
   10.32      }
   10.33  
   10.34      /**
   10.35       * Get the configuration string as a content.
   10.36       *
   10.37       * @param key the key to look for in the configuration file
   10.38 -     * @param a1 string argument added to configuration text
   10.39 -     * @param a2 string argument added to configuration text
   10.40 +     * @param o1  string or content argument added to configuration text
   10.41 +     * @param o2  string or content argument added to configuration text
   10.42       * @return a content tree for the text
   10.43       */
   10.44 -    public Content getResource(String key, String a1, String a2) {
   10.45 -        return new RawHtml(configuration.getText(key, a1, a2));
   10.46 +    public Content getResource(String key, Object o0, Object o1) {
   10.47 +        return configuration.getResource(key, o0, o1);
   10.48      }
   10.49  
   10.50      /**
    11.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Tue May 14 10:14:53 2013 -0700
    11.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties	Tue May 14 10:14:53 2013 -0700
    11.3 @@ -132,7 +132,7 @@
    11.4  doclet.Help_line_14=Use
    11.5  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.
    11.6  doclet.Help_line_16=Tree (Class Hierarchy)
    11.7 -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>.
    11.8 +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}.
    11.9  doclet.Help_line_18=When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
   11.10  doclet.Help_line_19=When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
   11.11  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.
    12.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Tue May 14 10:14:53 2013 -0700
    12.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Tue May 14 10:14:53 2013 -0700
    12.3 @@ -27,6 +27,8 @@
    12.4  
    12.5  import java.io.*;
    12.6  import java.util.*;
    12.7 +import java.util.regex.Matcher;
    12.8 +import java.util.regex.Pattern;
    12.9  
   12.10  import com.sun.javadoc.*;
   12.11  import com.sun.tools.javac.sym.Profiles;
   12.12 @@ -825,6 +827,82 @@
   12.13          }
   12.14      }
   12.15  
   12.16 +    public abstract Content getContentForResource();
   12.17 +
   12.18 +    /**
   12.19 +     * Get the configuration string as a content.
   12.20 +     *
   12.21 +     * @param key the key to look for in the configuration file
   12.22 +     * @return a content tree for the text
   12.23 +     */
   12.24 +    public Content getResource(String key) {
   12.25 +        Content c = getContentForResource();
   12.26 +        c.addContent(getText(key));
   12.27 +        return c;
   12.28 +    }
   12.29 +
   12.30 +    /**
   12.31 +     * Get the configuration string as a content.
   12.32 +     *
   12.33 +     * @param key the key to look for in the configuration file
   12.34 +     * @param o   string or content argument added to configuration text
   12.35 +     * @return a content tree for the text
   12.36 +     */
   12.37 +    public Content getResource(String key, Object o) {
   12.38 +        return getResource(key, o, null, null);
   12.39 +    }
   12.40 +
   12.41 +    /**
   12.42 +     * Get the configuration string as a content.
   12.43 +     *
   12.44 +     * @param key the key to look for in the configuration file
   12.45 +     * @param o   string or content argument added to configuration text
   12.46 +     * @return a content tree for the text
   12.47 +     */
   12.48 +    public Content getResource(String key, Object o1, Object o2) {
   12.49 +        return getResource(key, o1, o2, null);
   12.50 +    }
   12.51 +
   12.52 +    /**
   12.53 +     * Get the configuration string as a content.
   12.54 +     *
   12.55 +     * @param key the key to look for in the configuration file
   12.56 +     * @param o1  string or content argument added to configuration text
   12.57 +     * @param o2  string or content argument added to configuration text
   12.58 +     * @return a content tree for the text
   12.59 +     */
   12.60 +    public Content getResource(String key, Object o0, Object o1, Object o2) {
   12.61 +        Content c = getContentForResource();
   12.62 +        Pattern p = Pattern.compile("\\{([012])\\}");
   12.63 +        String text = getText(key);
   12.64 +        Matcher m = p.matcher(text);
   12.65 +        int start = 0;
   12.66 +        while (m.find(start)) {
   12.67 +            c.addContent(text.substring(start, m.start()));
   12.68 +
   12.69 +            Object o = null;
   12.70 +            switch (m.group(1).charAt(0)) {
   12.71 +                case '0': o = o0; break;
   12.72 +                case '1': o = o1; break;
   12.73 +                case '2': o = o2; break;
   12.74 +            }
   12.75 +
   12.76 +            if (o == null) {
   12.77 +                c.addContent("{" + m.group(1) + "}");
   12.78 +            } else if (o instanceof String) {
   12.79 +                c.addContent((String) o);
   12.80 +            } else if (o instanceof Content) {
   12.81 +                c.addContent((Content) o);
   12.82 +            }
   12.83 +
   12.84 +            start = m.end();
   12.85 +        }
   12.86 +
   12.87 +        c.addContent(text.substring(start));
   12.88 +        return c;
   12.89 +    }
   12.90 +
   12.91 +
   12.92      /**
   12.93       * Return true if the ClassDoc element is getting documented, depending upon
   12.94       * -nodeprecated option and the deprecation information. Return true if

mercurial