提交 61138f12 编写于 作者: J jjg

8011668: Allow HTMLWriter.getResource to take Content args

Reviewed-by: darcy
上级 54d9304d
...@@ -160,8 +160,9 @@ public class AbstractIndexWriter extends HtmlDocletWriter { ...@@ -160,8 +160,9 @@ public class AbstractIndexWriter extends HtmlDocletWriter {
protected void addClassInfo(ClassDoc cd, Content contentTree) { protected void addClassInfo(ClassDoc cd, Content contentTree) {
contentTree.addContent(getResource("doclet.in", contentTree.addContent(getResource("doclet.in",
Util.getTypeName(configuration, cd, false), Util.getTypeName(configuration, cd, false),
getPackageLinkString(cd.containingPackage(), getPackageLink(cd.containingPackage(),
Util.escapeHtmlChars(Util.getPackageName(cd.containingPackage())), false))); Util.getPackageName(cd.containingPackage()))
));
} }
/** /**
......
...@@ -331,11 +331,10 @@ public class ClassUseWriter extends SubWriterHolderWriter { ...@@ -331,11 +331,10 @@ public class ClassUseWriter extends SubWriterHolderWriter {
for (Iterator<PackageDoc> it = pkgSet.iterator(); it.hasNext();) { for (Iterator<PackageDoc> it = pkgSet.iterator(); it.hasNext();) {
PackageDoc pkg = it.next(); PackageDoc pkg = it.next();
Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(pkg.name())); Content li = HtmlTree.LI(HtmlStyle.blockList, getMarkerAnchor(pkg.name()));
Content link = new RawHtml( Content link = getResource("doclet.ClassUse_Uses.of.0.in.1",
configuration.getText("doclet.ClassUse_Uses.of.0.in.1",
getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER, getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_USE_HEADER,
classdoc)).toString(), classdoc)),
getPackageLinkString(pkg, Util.escapeHtmlChars(Util.getPackageName(pkg)), false))); getPackageLink(pkg, Util.getPackageName(pkg)));
Content heading = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, link); Content heading = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING, link);
li.addContent(heading); li.addContent(heading);
addClassUse(pkg, li); addClassUse(pkg, li);
......
...@@ -31,6 +31,7 @@ import java.util.*; ...@@ -31,6 +31,7 @@ import java.util.*;
import javax.tools.JavaFileManager; import javax.tools.JavaFileManager;
import com.sun.javadoc.*; 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.*;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
import com.sun.tools.doclint.DocLint; import com.sun.tools.doclint.DocLint;
...@@ -562,4 +563,9 @@ public class ConfigurationImpl extends Configuration { ...@@ -562,4 +563,9 @@ public class ConfigurationImpl extends Configuration {
} }
return true; return true;
} }
@Override
public Content getContentForResource() {
return new ContentBuilder();
}
} }
...@@ -121,7 +121,7 @@ public class FrameOutputWriter extends HtmlDocletWriter { ...@@ -121,7 +121,7 @@ public class FrameOutputWriter extends HtmlDocletWriter {
getResource("doclet.Frame_Alert")); getResource("doclet.Frame_Alert"));
noframes.addContent(noframesHead); noframes.addContent(noframesHead);
Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message", Content p = HtmlTree.P(getResource("doclet.Frame_Warning_Message",
getHyperLinkString(configuration.topFile, getHyperLink(configuration.topFile,
configuration.getText("doclet.Non_Frame_Version")))); configuration.getText("doclet.Non_Frame_Version"))));
noframes.addContent(p); noframes.addContent(p);
contentTree.addContent(noframes); contentTree.addContent(noframes);
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -113,7 +113,7 @@ public class HelpWriter extends HtmlDocletWriter { ...@@ -113,7 +113,7 @@ public class HelpWriter extends HtmlDocletWriter {
getResource("doclet.Overview")); getResource("doclet.Overview"));
Content liOverview = HtmlTree.LI(HtmlStyle.blockList, overviewHeading); Content liOverview = HtmlTree.LI(HtmlStyle.blockList, overviewHeading);
Content line3 = getResource("doclet.Help_line_3", Content line3 = getResource("doclet.Help_line_3",
getHyperLinkString(DocPaths.OVERVIEW_SUMMARY, getHyperLink(DocPaths.OVERVIEW_SUMMARY,
configuration.getText("doclet.Overview"))); configuration.getText("doclet.Overview")));
Content overviewPara = HtmlTree.P(line3); Content overviewPara = HtmlTree.P(line3);
liOverview.addContent(overviewPara); liOverview.addContent(overviewPara);
...@@ -234,8 +234,9 @@ public class HelpWriter extends HtmlDocletWriter { ...@@ -234,8 +234,9 @@ public class HelpWriter extends HtmlDocletWriter {
getResource("doclet.Help_line_16")); getResource("doclet.Help_line_16"));
Content liTree = HtmlTree.LI(HtmlStyle.blockList, treeHead); Content liTree = HtmlTree.LI(HtmlStyle.blockList, treeHead);
Content line17 = getResource("doclet.Help_line_17_with_tree_link", Content line17 = getResource("doclet.Help_line_17_with_tree_link",
getHyperLinkString(DocPaths.OVERVIEW_TREE, getHyperLink(DocPaths.OVERVIEW_TREE,
configuration.getText("doclet.Class_Hierarchy"))); configuration.getText("doclet.Class_Hierarchy")),
HtmlTree.CODE(new StringContent("java.lang.Object")));
Content treePara = HtmlTree.P(line17); Content treePara = HtmlTree.P(line17);
liTree.addContent(treePara); liTree.addContent(treePara);
HtmlTree tul = new HtmlTree(HtmlTag.UL); HtmlTree tul = new HtmlTree(HtmlTag.UL);
...@@ -252,19 +253,19 @@ public class HelpWriter extends HtmlDocletWriter { ...@@ -252,19 +253,19 @@ public class HelpWriter extends HtmlDocletWriter {
getResource("doclet.Deprecated_API")); getResource("doclet.Deprecated_API"));
Content liDeprecated = HtmlTree.LI(HtmlStyle.blockList, dHead); Content liDeprecated = HtmlTree.LI(HtmlStyle.blockList, dHead);
Content line20 = getResource("doclet.Help_line_20_with_deprecated_api_link", Content line20 = getResource("doclet.Help_line_20_with_deprecated_api_link",
getHyperLinkString(DocPaths.DEPRECATED_LIST, getHyperLink(DocPaths.DEPRECATED_LIST,
configuration.getText("doclet.Deprecated_API"))); configuration.getText("doclet.Deprecated_API")));
Content dPara = HtmlTree.P(line20); Content dPara = HtmlTree.P(line20);
liDeprecated.addContent(dPara); liDeprecated.addContent(dPara);
ul.addContent(liDeprecated); ul.addContent(liDeprecated);
} }
if (configuration.createindex) { if (configuration.createindex) {
String indexlink; Content indexlink;
if (configuration.splitindex) { 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")); configuration.getText("doclet.Index"));
} else { } else {
indexlink = getHyperLinkString(DocPaths.INDEX_ALL, indexlink = getHyperLink(DocPaths.INDEX_ALL,
configuration.getText("doclet.Index")); configuration.getText("doclet.Index"));
} }
Content indexHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, Content indexHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
...@@ -293,7 +294,7 @@ public class HelpWriter extends HtmlDocletWriter { ...@@ -293,7 +294,7 @@ public class HelpWriter extends HtmlDocletWriter {
getResource("doclet.All_Classes")); getResource("doclet.All_Classes"));
Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead); Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead);
Content line27 = getResource("doclet.Help_line_27", Content line27 = getResource("doclet.Help_line_27",
getHyperLinkString(DocPaths.ALLCLASSES_NOFRAME, getHyperLink(DocPaths.ALLCLASSES_NOFRAME,
configuration.getText("doclet.All_Classes"))); configuration.getText("doclet.All_Classes")));
Content allclassesPara = HtmlTree.P(line27); Content allclassesPara = HtmlTree.P(line27);
liAllClasses.addContent(allclassesPara); liAllClasses.addContent(allclassesPara);
...@@ -309,7 +310,7 @@ public class HelpWriter extends HtmlDocletWriter { ...@@ -309,7 +310,7 @@ public class HelpWriter extends HtmlDocletWriter {
getResource("doclet.Constants_Summary")); getResource("doclet.Constants_Summary"));
Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead); Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead);
Content line29 = getResource("doclet.Help_line_29", Content line29 = getResource("doclet.Help_line_29",
getHyperLinkString(DocPaths.CONSTANT_VALUES, getHyperLink(DocPaths.CONSTANT_VALUES,
configuration.getText("doclet.Constants_Summary"))); configuration.getText("doclet.Constants_Summary")));
Content constPara = HtmlTree.P(line29); Content constPara = HtmlTree.P(line29);
liConst.addContent(constPara); liConst.addContent(constPara);
......
...@@ -1042,6 +1042,17 @@ public class HtmlDocletWriter extends HtmlDocWriter { ...@@ -1042,6 +1042,17 @@ public class HtmlDocletWriter extends HtmlDocWriter {
} }
} }
/**
* 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, String label) {
return getPackageLink(pkg, new StringContent(label));
}
/** /**
* Return the link to the given package. * Return the link to the given package.
* *
......
...@@ -115,7 +115,7 @@ public class PackageTreeWriter extends AbstractTreeWriter { ...@@ -115,7 +115,7 @@ public class PackageTreeWriter extends AbstractTreeWriter {
protected void generatePackageTreeFile() throws IOException { protected void generatePackageTreeFile() throws IOException {
Content body = getPackageTreeHeader(); Content body = getPackageTreeHeader();
Content headContent = getResource("doclet.Hierarchy_For_Package", Content headContent = getResource("doclet.Hierarchy_For_Package",
Util.escapeHtmlChars(Util.getPackageName(packagedoc))); Util.getPackageName(packagedoc));
Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
HtmlStyle.title, headContent); HtmlStyle.title, headContent);
Content div = HtmlTree.DIV(HtmlStyle.header, heading); Content div = HtmlTree.DIV(HtmlStyle.header, heading);
......
...@@ -81,6 +81,7 @@ public class ContentBuilder extends Content { ...@@ -81,6 +81,7 @@ public class ContentBuilder extends Content {
return true; return true;
} }
@Override
public int charCount() { public int charCount() {
int n = 0; int n = 0;
for (Content c : contents) for (Content c : contents)
......
...@@ -82,6 +82,10 @@ public abstract class HtmlDocWriter extends HtmlWriter { ...@@ -82,6 +82,10 @@ public abstract class HtmlDocWriter extends HtmlWriter {
return getHyperLinkString(link, label, false, "", "", ""); 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) { public String getHyperLinkString(DocLink link, String label) {
return getHyperLinkString(link, label, false, "", "", ""); return getHyperLinkString(link, label, false, "", "", "");
} }
...@@ -184,6 +188,13 @@ public abstract class HtmlDocWriter extends HtmlWriter { ...@@ -184,6 +188,13 @@ public abstract class HtmlDocWriter extends HtmlWriter {
return retlink.toString(); 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, public Content getHyperLink(DocLink link,
Content label, boolean strong, Content label, boolean strong,
String stylename, String title, String target) { String stylename, String title, String target) {
...@@ -282,20 +293,6 @@ public abstract class HtmlDocWriter extends HtmlWriter { ...@@ -282,20 +293,6 @@ public abstract class HtmlDocWriter extends HtmlWriter {
write(htmlDocument); 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() { protected String getGeneratedByString() {
Calendar calendar = new GregorianCalendar(TimeZone.getDefault()); Calendar calendar = new GregorianCalendar(TimeZone.getDefault());
Date today = calendar.getTime(); Date today = calendar.getTime();
......
...@@ -27,6 +27,8 @@ package com.sun.tools.doclets.formats.html.markup; ...@@ -27,6 +27,8 @@ package com.sun.tools.doclets.formats.html.markup;
import java.io.*; import java.io.*;
import java.util.*; 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.*;
import com.sun.tools.doclets.internal.toolkit.util.*; import com.sun.tools.doclets.internal.toolkit.util.*;
...@@ -252,30 +254,30 @@ public class HtmlWriter { ...@@ -252,30 +254,30 @@ public class HtmlWriter {
* @return a content tree for the text * @return a content tree for the text
*/ */
public Content getResource(String key) { public Content getResource(String key) {
return new StringContent(configuration.getText(key)); return configuration.getResource(key);
} }
/** /**
* Get the configuration string as a content. * Get the configuration string as a content.
* *
* @param key the key to look for in the configuration file * @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 * @return a content tree for the text
*/ */
public Content getResource(String key, String a1) { public Content getResource(String key, Object o) {
return new RawHtml(configuration.getText(key, a1)); return configuration.getResource(key, o);
} }
/** /**
* Get the configuration string as a content. * Get the configuration string as a content.
* *
* @param key the key to look for in the configuration file * @param key the key to look for in the configuration file
* @param a1 string argument added to configuration text * @param o1 string or content argument added to configuration text
* @param a2 string argument added to configuration text * @param o2 string or content argument added to configuration text
* @return a content tree for the text * @return a content tree for the text
*/ */
public Content getResource(String key, String a1, String a2) { public Content getResource(String key, Object o0, Object o1) {
return new RawHtml(configuration.getText(key, a1, a2)); return configuration.getResource(key, o0, o1);
} }
/** /**
......
...@@ -132,7 +132,7 @@ doclet.Help_line_13=Each summary entry contains the first sentence from the deta ...@@ -132,7 +132,7 @@ doclet.Help_line_13=Each summary entry contains the first sentence from the deta
doclet.Help_line_14=Use 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_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_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_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_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. 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.
......
...@@ -27,6 +27,8 @@ package com.sun.tools.doclets.internal.toolkit; ...@@ -27,6 +27,8 @@ package com.sun.tools.doclets.internal.toolkit;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.javac.sym.Profiles; import com.sun.tools.javac.sym.Profiles;
...@@ -825,6 +827,82 @@ public abstract class Configuration { ...@@ -825,6 +827,82 @@ public abstract class Configuration {
} }
} }
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 * Return true if the ClassDoc element is getting documented, depending upon
* -nodeprecated option and the deprecation information. Return true if * -nodeprecated option and the deprecation information. Return true if
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册