提交 9fa48065 编写于 作者: J jjg

8001219: Clean up use of URLs in javadoc Extern class

Reviewed-by: darcy
上级 8311b51d
......@@ -408,11 +408,11 @@ public abstract class Configuration {
group.checkPackageGroups(os[1], os[2]);
} else if (opt.equals("-link")) {
String url = os[1];
extern.url(url, url, root, false);
extern.link(url, url, root, false);
} else if (opt.equals("-linkoffline")) {
String url = os[1];
String pkglisturl = os[2];
extern.url(url, pkglisturl, root, true);
extern.link(url, pkglisturl, root, true);
}
}
if (sourcepath.length() == 0) {
......
......@@ -167,17 +167,38 @@ public class Extern {
* @param pkglisturl This can be another URL for "package-list" or ordinary
* file.
* @param reporter The <code>DocErrorReporter</code> used to report errors.
* @param linkoffline True if -linkoffline isused and false if -link is used.
* @param linkoffline True if -linkoffline is used and false if -link is used.
*/
public boolean url(String url, String pkglisturl,
public boolean link(String url, String pkglisturl,
DocErrorReporter reporter, boolean linkoffline) {
this.linkoffline = linkoffline;
String errMsg = composeExternPackageList(url, pkglisturl);
if (errMsg != null) {
reporter.printWarning(errMsg);
return false;
} else {
try {
url = adjustEndFileSeparator(url);
if (isUrl(pkglisturl)) {
readPackageListFromURL(url, toURL(pkglisturl));
} else {
readPackageListFromFile(url, new File(pkglisturl));
}
return true;
} catch (Fault f) {
reporter.printWarning(f.getMessage());
return false;
}
}
private URL toURL(String url) throws Fault {
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new Fault(configuration.getText("doclet.MalformedURL", url), e);
}
}
private class Fault extends Exception {
private static final long serialVersionUID = 0;
Fault(String msg, Exception cause) {
super(msg, cause);
}
}
......@@ -193,32 +214,11 @@ public class Extern {
return packageToItemMap.get(pkgName);
}
/**
* Adjusts the end file separator if it is missing from the URL or the
* directory path and depending upon the URL or file path, fetch or
* read the "package-list" file.
*
* @param urlOrDirPath URL or the directory path.
* @param pkgListUrlOrDirPath URL or directory path for the "package-list" file or the "package-list"
* file itself.
*/
private String composeExternPackageList(String urlOrDirPath, String pkgListUrlOrDirPath) {
urlOrDirPath = adjustEndFileSeparator(urlOrDirPath);
pkgListUrlOrDirPath = adjustEndFileSeparator(pkgListUrlOrDirPath);
return isUrl(pkgListUrlOrDirPath) ?
fetchURLComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath) :
readFileComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath);
}
/**
* If the URL or Directory path is missing end file separator, add that.
*/
private String adjustEndFileSeparator(String url) {
String filesep = "/";
if (!url.endsWith(filesep)) {
url += filesep;
}
return url;
return url.endsWith("/") ? url : url + '/';
}
/**
......@@ -227,17 +227,18 @@ public class Extern {
* @param urlpath Path to the packages.
* @param pkglisturlpath URL or the path to the "package-list" file.
*/
private String fetchURLComposeExternPackageList(String urlpath,
String pkglisturlpath) {
String link = pkglisturlpath + "package-list";
private void readPackageListFromURL(String urlpath, URL pkglisturlpath)
throws Fault {
try {
readPackageList((new URL(link)).openStream(), urlpath, false);
URL link = pkglisturlpath.toURI().resolve(DocPaths.PACKAGE_LIST.getPath()).toURL();
readPackageList(link.openStream(), urlpath, false);
} catch (URISyntaxException exc) {
throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc);
} catch (MalformedURLException exc) {
return configuration.getText("doclet.MalformedURL", link);
throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc);
} catch (IOException exc) {
return configuration.getText("doclet.URL_error", link);
throw new Fault(configuration.getText("doclet.URL_error", pkglisturlpath.toString()), exc);
}
return null;
}
/**
......@@ -246,27 +247,22 @@ public class Extern {
* @param path URL or directory path to the packages.
* @param pkgListPath Path to the local "package-list" file.
*/
private String readFileComposeExternPackageList(String path,
String pkgListPath) {
String link = pkgListPath + "package-list";
if (! ((new File(pkgListPath)).isAbsolute() || linkoffline)){
link = configuration.destDirName + link;
private void readPackageListFromFile(String path, File pkgListPath)
throws Fault {
File file = new File(pkgListPath, "package-list");
if (! (file.isAbsolute() || linkoffline)){
file = new File(configuration.destDirName, file.getPath());
}
try {
File file = new File(link);
if (file.exists() && file.canRead()) {
readPackageList(new FileInputStream(file), path,
! ((new File(path)).isAbsolute() || isUrl(path)));
} else {
return configuration.getText("doclet.File_error", link);
throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null);
}
} catch (FileNotFoundException exc) {
return configuration.getText("doclet.File_error", link);
} catch (IOException exc) {
return configuration.getText("doclet.File_error", link);
throw new Fault(configuration.getText("doclet.File_error", file.getPath()), exc);
}
return null;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册