Fri, 26 Oct 2012 13:10:56 -0700
8001219: Clean up use of URLs in javadoc Extern class
Reviewed-by: darcy
1.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Thu Oct 25 13:33:27 2012 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Fri Oct 26 13:10:56 2012 -0700 1.3 @@ -408,11 +408,11 @@ 1.4 group.checkPackageGroups(os[1], os[2]); 1.5 } else if (opt.equals("-link")) { 1.6 String url = os[1]; 1.7 - extern.url(url, url, root, false); 1.8 + extern.link(url, url, root, false); 1.9 } else if (opt.equals("-linkoffline")) { 1.10 String url = os[1]; 1.11 String pkglisturl = os[2]; 1.12 - extern.url(url, pkglisturl, root, true); 1.13 + extern.link(url, pkglisturl, root, true); 1.14 } 1.15 } 1.16 if (sourcepath.length() == 0) {
2.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Thu Oct 25 13:33:27 2012 -0700 2.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Fri Oct 26 13:10:56 2012 -0700 2.3 @@ -167,17 +167,38 @@ 2.4 * @param pkglisturl This can be another URL for "package-list" or ordinary 2.5 * file. 2.6 * @param reporter The <code>DocErrorReporter</code> used to report errors. 2.7 - * @param linkoffline True if -linkoffline isused and false if -link is used. 2.8 + * @param linkoffline True if -linkoffline is used and false if -link is used. 2.9 */ 2.10 - public boolean url(String url, String pkglisturl, 2.11 + public boolean link(String url, String pkglisturl, 2.12 DocErrorReporter reporter, boolean linkoffline) { 2.13 this.linkoffline = linkoffline; 2.14 - String errMsg = composeExternPackageList(url, pkglisturl); 2.15 - if (errMsg != null) { 2.16 - reporter.printWarning(errMsg); 2.17 + try { 2.18 + url = adjustEndFileSeparator(url); 2.19 + if (isUrl(pkglisturl)) { 2.20 + readPackageListFromURL(url, toURL(pkglisturl)); 2.21 + } else { 2.22 + readPackageListFromFile(url, new File(pkglisturl)); 2.23 + } 2.24 + return true; 2.25 + } catch (Fault f) { 2.26 + reporter.printWarning(f.getMessage()); 2.27 return false; 2.28 - } else { 2.29 - return true; 2.30 + } 2.31 + } 2.32 + 2.33 + private URL toURL(String url) throws Fault { 2.34 + try { 2.35 + return new URL(url); 2.36 + } catch (MalformedURLException e) { 2.37 + throw new Fault(configuration.getText("doclet.MalformedURL", url), e); 2.38 + } 2.39 + } 2.40 + 2.41 + private class Fault extends Exception { 2.42 + private static final long serialVersionUID = 0; 2.43 + 2.44 + Fault(String msg, Exception cause) { 2.45 + super(msg, cause); 2.46 } 2.47 } 2.48 2.49 @@ -194,31 +215,10 @@ 2.50 } 2.51 2.52 /** 2.53 - * Adjusts the end file separator if it is missing from the URL or the 2.54 - * directory path and depending upon the URL or file path, fetch or 2.55 - * read the "package-list" file. 2.56 - * 2.57 - * @param urlOrDirPath URL or the directory path. 2.58 - * @param pkgListUrlOrDirPath URL or directory path for the "package-list" file or the "package-list" 2.59 - * file itself. 2.60 - */ 2.61 - private String composeExternPackageList(String urlOrDirPath, String pkgListUrlOrDirPath) { 2.62 - urlOrDirPath = adjustEndFileSeparator(urlOrDirPath); 2.63 - pkgListUrlOrDirPath = adjustEndFileSeparator(pkgListUrlOrDirPath); 2.64 - return isUrl(pkgListUrlOrDirPath) ? 2.65 - fetchURLComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath) : 2.66 - readFileComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath); 2.67 - } 2.68 - 2.69 - /** 2.70 * If the URL or Directory path is missing end file separator, add that. 2.71 */ 2.72 private String adjustEndFileSeparator(String url) { 2.73 - String filesep = "/"; 2.74 - if (!url.endsWith(filesep)) { 2.75 - url += filesep; 2.76 - } 2.77 - return url; 2.78 + return url.endsWith("/") ? url : url + '/'; 2.79 } 2.80 2.81 /** 2.82 @@ -227,17 +227,18 @@ 2.83 * @param urlpath Path to the packages. 2.84 * @param pkglisturlpath URL or the path to the "package-list" file. 2.85 */ 2.86 - private String fetchURLComposeExternPackageList(String urlpath, 2.87 - String pkglisturlpath) { 2.88 - String link = pkglisturlpath + "package-list"; 2.89 + private void readPackageListFromURL(String urlpath, URL pkglisturlpath) 2.90 + throws Fault { 2.91 try { 2.92 - readPackageList((new URL(link)).openStream(), urlpath, false); 2.93 + URL link = pkglisturlpath.toURI().resolve(DocPaths.PACKAGE_LIST.getPath()).toURL(); 2.94 + readPackageList(link.openStream(), urlpath, false); 2.95 + } catch (URISyntaxException exc) { 2.96 + throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc); 2.97 } catch (MalformedURLException exc) { 2.98 - return configuration.getText("doclet.MalformedURL", link); 2.99 + throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc); 2.100 } catch (IOException exc) { 2.101 - return configuration.getText("doclet.URL_error", link); 2.102 + throw new Fault(configuration.getText("doclet.URL_error", pkglisturlpath.toString()), exc); 2.103 } 2.104 - return null; 2.105 } 2.106 2.107 /** 2.108 @@ -246,27 +247,22 @@ 2.109 * @param path URL or directory path to the packages. 2.110 * @param pkgListPath Path to the local "package-list" file. 2.111 */ 2.112 - private String readFileComposeExternPackageList(String path, 2.113 - String pkgListPath) { 2.114 - 2.115 - String link = pkgListPath + "package-list"; 2.116 - if (! ((new File(pkgListPath)).isAbsolute() || linkoffline)){ 2.117 - link = configuration.destDirName + link; 2.118 + private void readPackageListFromFile(String path, File pkgListPath) 2.119 + throws Fault { 2.120 + File file = new File(pkgListPath, "package-list"); 2.121 + if (! (file.isAbsolute() || linkoffline)){ 2.122 + file = new File(configuration.destDirName, file.getPath()); 2.123 } 2.124 try { 2.125 - File file = new File(link); 2.126 if (file.exists() && file.canRead()) { 2.127 readPackageList(new FileInputStream(file), path, 2.128 ! ((new File(path)).isAbsolute() || isUrl(path))); 2.129 } else { 2.130 - return configuration.getText("doclet.File_error", link); 2.131 + throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null); 2.132 } 2.133 - } catch (FileNotFoundException exc) { 2.134 - return configuration.getText("doclet.File_error", link); 2.135 } catch (IOException exc) { 2.136 - return configuration.getText("doclet.File_error", link); 2.137 + throw new Fault(configuration.getText("doclet.File_error", file.getPath()), exc); 2.138 } 2.139 - return null; 2.140 } 2.141 2.142 /**