1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Thu Oct 10 08:51:55 2013 +0200 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlDocWriter.java Thu Oct 10 10:51:15 2013 -0700 1.3 @@ -30,6 +30,7 @@ 1.4 1.5 import com.sun.javadoc.*; 1.6 import com.sun.tools.doclets.formats.html.ConfigurationImpl; 1.7 +import com.sun.tools.doclets.formats.html.SectionName; 1.8 import com.sun.tools.doclets.internal.toolkit.*; 1.9 import com.sun.tools.doclets.internal.toolkit.util.DocFile; 1.10 import com.sun.tools.doclets.internal.toolkit.util.DocLink; 1.11 @@ -78,7 +79,7 @@ 1.12 } 1.13 1.14 /** 1.15 - * Get Html Hyper Link string. 1.16 + * Get Html Hyper Link Content. 1.17 * 1.18 * @param where Position of the link in the file. Character '#' is not 1.19 * needed. 1.20 @@ -87,7 +88,125 @@ 1.21 */ 1.22 public Content getHyperLink(String where, 1.23 Content label) { 1.24 - return getHyperLink(DocLink.fragment(where), label, "", ""); 1.25 + return getHyperLink(getDocLink(where), label, "", ""); 1.26 + } 1.27 + 1.28 + /** 1.29 + * Get Html Hyper Link Content. 1.30 + * 1.31 + * @param sectionName The section name to which the link will be created. 1.32 + * @param label Tag for the link. 1.33 + * @return a content tree for the hyper link 1.34 + */ 1.35 + public Content getHyperLink(SectionName sectionName, 1.36 + Content label) { 1.37 + return getHyperLink(getDocLink(sectionName), label, "", ""); 1.38 + } 1.39 + 1.40 + /** 1.41 + * Get Html Hyper Link Content. 1.42 + * 1.43 + * @param sectionName The section name combined with where to which the link 1.44 + * will be created. 1.45 + * @param where The fragment combined with sectionName to which the link 1.46 + * will be created. 1.47 + * @param label Tag for the link. 1.48 + * @return a content tree for the hyper link 1.49 + */ 1.50 + public Content getHyperLink(SectionName sectionName, String where, 1.51 + Content label) { 1.52 + return getHyperLink(getDocLink(sectionName, where), label, "", ""); 1.53 + } 1.54 + 1.55 + /** 1.56 + * Get the link. 1.57 + * 1.58 + * @param where Position of the link in the file. 1.59 + * @return a DocLink object for the hyper link 1.60 + */ 1.61 + public DocLink getDocLink(String where) { 1.62 + return DocLink.fragment(getName(where)); 1.63 + } 1.64 + 1.65 + /** 1.66 + * Get the link. 1.67 + * 1.68 + * @param sectionName The section name to which the link will be created. 1.69 + * @return a DocLink object for the hyper link 1.70 + */ 1.71 + public DocLink getDocLink(SectionName sectionName) { 1.72 + return DocLink.fragment(sectionName.getName()); 1.73 + } 1.74 + 1.75 + /** 1.76 + * Get the link. 1.77 + * 1.78 + * @param sectionName The section name combined with where to which the link 1.79 + * will be created. 1.80 + * @param where The fragment combined with sectionName to which the link 1.81 + * will be created. 1.82 + * @return a DocLink object for the hyper link 1.83 + */ 1.84 + public DocLink getDocLink(SectionName sectionName, String where) { 1.85 + return DocLink.fragment(sectionName.getName() + getName(where)); 1.86 + } 1.87 + 1.88 + /** 1.89 + * Convert the name to a valid HTML name. 1.90 + * 1.91 + * @param name the name that needs to be converted to valid HTML name. 1.92 + * @return a valid HTML name string. 1.93 + */ 1.94 + public String getName(String name) { 1.95 + StringBuilder sb = new StringBuilder(); 1.96 + char ch; 1.97 + /* The HTML 4 spec at http://www.w3.org/TR/html4/types.html#h-6.2 mentions 1.98 + * that the name/id should begin with a letter followed by other valid characters. 1.99 + * The HTML 5 spec (draft) is more permissive on names/ids where the only restriction 1.100 + * is that it should be at least one character long and should not contain spaces. 1.101 + * The spec draft is @ http://www.w3.org/html/wg/drafts/html/master/dom.html#the-id-attribute. 1.102 + * 1.103 + * For HTML 4, we need to check for non-characters at the beginning of the name and 1.104 + * substitute it accordingly, "_" and "$" can appear at the beginning of a member name. 1.105 + * The method substitutes "$" with "Z:Z:D" and will prefix "_" with "Z:Z". 1.106 + */ 1.107 + for (int i = 0; i < name.length(); i++) { 1.108 + ch = name.charAt(i); 1.109 + switch (ch) { 1.110 + case '(': 1.111 + case ')': 1.112 + case '<': 1.113 + case '>': 1.114 + case ',': 1.115 + sb.append('-'); 1.116 + break; 1.117 + case ' ': 1.118 + case '[': 1.119 + break; 1.120 + case ']': 1.121 + sb.append(":A"); 1.122 + break; 1.123 + // Any appearance of $ needs to be substituted with ":D" and not with hyphen 1.124 + // since a field name "P$$ and a method P(), both valid member names, can end 1.125 + // up as "P--". A member name beginning with $ needs to be substituted with 1.126 + // "Z:Z:D". 1.127 + case '$': 1.128 + if (i == 0) 1.129 + sb.append("Z:Z"); 1.130 + sb.append(":D"); 1.131 + break; 1.132 + // A member name beginning with _ needs to be prefixed with "Z:Z" since valid anchor 1.133 + // names can only begin with a letter. 1.134 + case '_': 1.135 + if (i == 0) 1.136 + sb.append("Z:Z"); 1.137 + sb.append(ch); 1.138 + break; 1.139 + default: 1.140 + sb.append(ch); 1.141 + } 1.142 + } 1.143 + return sb.toString(); 1.144 } 1.145 1.146 /**