src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java

changeset 1376
217c265158fe
parent 1373
4a1c57a1c410
child 1383
b980e8e6aabf
     1.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java	Thu Oct 25 13:33:27 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java	Fri Oct 26 13:10:56 2012 -0700
     1.3 @@ -167,17 +167,38 @@
     1.4       * @param pkglisturl This can be another URL for "package-list" or ordinary
     1.5       *                   file.
     1.6       * @param reporter   The <code>DocErrorReporter</code> used to report errors.
     1.7 -     * @param linkoffline True if -linkoffline isused and false if -link is used.
     1.8 +     * @param linkoffline True if -linkoffline is used and false if -link is used.
     1.9       */
    1.10 -    public boolean url(String url, String pkglisturl,
    1.11 +    public boolean link(String url, String pkglisturl,
    1.12                                DocErrorReporter reporter, boolean linkoffline) {
    1.13          this.linkoffline = linkoffline;
    1.14 -        String errMsg = composeExternPackageList(url, pkglisturl);
    1.15 -        if (errMsg != null) {
    1.16 -            reporter.printWarning(errMsg);
    1.17 +        try {
    1.18 +            url = adjustEndFileSeparator(url);
    1.19 +            if (isUrl(pkglisturl)) {
    1.20 +                readPackageListFromURL(url, toURL(pkglisturl));
    1.21 +            } else {
    1.22 +                readPackageListFromFile(url, new File(pkglisturl));
    1.23 +            }
    1.24 +            return true;
    1.25 +        } catch (Fault f) {
    1.26 +            reporter.printWarning(f.getMessage());
    1.27              return false;
    1.28 -        } else {
    1.29 -            return true;
    1.30 +        }
    1.31 +    }
    1.32 +
    1.33 +    private URL toURL(String url) throws Fault {
    1.34 +        try {
    1.35 +            return new URL(url);
    1.36 +        } catch (MalformedURLException e) {
    1.37 +            throw new Fault(configuration.getText("doclet.MalformedURL", url), e);
    1.38 +        }
    1.39 +    }
    1.40 +
    1.41 +    private class Fault extends Exception {
    1.42 +        private static final long serialVersionUID = 0;
    1.43 +
    1.44 +        Fault(String msg, Exception cause) {
    1.45 +            super(msg, cause);
    1.46          }
    1.47      }
    1.48  
    1.49 @@ -194,31 +215,10 @@
    1.50      }
    1.51  
    1.52      /**
    1.53 -     * Adjusts the end file separator if it is missing from the URL or the
    1.54 -     * directory path and depending upon the URL or file path, fetch or
    1.55 -     * read the "package-list" file.
    1.56 -     *
    1.57 -     * @param urlOrDirPath        URL or the directory path.
    1.58 -     * @param pkgListUrlOrDirPath URL or directory path for the "package-list" file or the "package-list"
    1.59 -     * file itself.
    1.60 -     */
    1.61 -    private String composeExternPackageList(String urlOrDirPath, String pkgListUrlOrDirPath) {
    1.62 -        urlOrDirPath = adjustEndFileSeparator(urlOrDirPath);
    1.63 -        pkgListUrlOrDirPath = adjustEndFileSeparator(pkgListUrlOrDirPath);
    1.64 -        return isUrl(pkgListUrlOrDirPath) ?
    1.65 -            fetchURLComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath) :
    1.66 -            readFileComposeExternPackageList(urlOrDirPath, pkgListUrlOrDirPath);
    1.67 -    }
    1.68 -
    1.69 -    /**
    1.70       * If the URL or Directory path is missing end file separator, add that.
    1.71       */
    1.72      private String adjustEndFileSeparator(String url) {
    1.73 -        String filesep = "/";
    1.74 -        if (!url.endsWith(filesep)) {
    1.75 -            url += filesep;
    1.76 -        }
    1.77 -        return url;
    1.78 +        return url.endsWith("/") ? url : url + '/';
    1.79      }
    1.80  
    1.81      /**
    1.82 @@ -227,17 +227,18 @@
    1.83       * @param urlpath        Path to the packages.
    1.84       * @param pkglisturlpath URL or the path to the "package-list" file.
    1.85       */
    1.86 -    private String fetchURLComposeExternPackageList(String urlpath,
    1.87 -                                                   String pkglisturlpath) {
    1.88 -        String link = pkglisturlpath + "package-list";
    1.89 +    private void readPackageListFromURL(String urlpath, URL pkglisturlpath)
    1.90 +            throws Fault {
    1.91          try {
    1.92 -            readPackageList((new URL(link)).openStream(), urlpath, false);
    1.93 +            URL link = pkglisturlpath.toURI().resolve(DocPaths.PACKAGE_LIST.getPath()).toURL();
    1.94 +            readPackageList(link.openStream(), urlpath, false);
    1.95 +        } catch (URISyntaxException exc) {
    1.96 +            throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc);
    1.97          } catch (MalformedURLException exc) {
    1.98 -            return configuration.getText("doclet.MalformedURL", link);
    1.99 +            throw new Fault(configuration.getText("doclet.MalformedURL", pkglisturlpath.toString()), exc);
   1.100          } catch (IOException exc) {
   1.101 -            return configuration.getText("doclet.URL_error", link);
   1.102 +            throw new Fault(configuration.getText("doclet.URL_error", pkglisturlpath.toString()), exc);
   1.103          }
   1.104 -        return null;
   1.105      }
   1.106  
   1.107      /**
   1.108 @@ -246,27 +247,22 @@
   1.109       * @param path URL or directory path to the packages.
   1.110       * @param pkgListPath Path to the local "package-list" file.
   1.111       */
   1.112 -    private String readFileComposeExternPackageList(String path,
   1.113 -                                                   String pkgListPath) {
   1.114 -
   1.115 -        String link = pkgListPath + "package-list";
   1.116 -        if (! ((new File(pkgListPath)).isAbsolute() || linkoffline)){
   1.117 -            link = configuration.destDirName + link;
   1.118 +    private void readPackageListFromFile(String path, File pkgListPath)
   1.119 +            throws Fault {
   1.120 +        File file = new File(pkgListPath, "package-list");
   1.121 +        if (! (file.isAbsolute() || linkoffline)){
   1.122 +            file = new File(configuration.destDirName, file.getPath());
   1.123          }
   1.124          try {
   1.125 -            File file = new File(link);
   1.126              if (file.exists() && file.canRead()) {
   1.127                  readPackageList(new FileInputStream(file), path,
   1.128                      ! ((new File(path)).isAbsolute() || isUrl(path)));
   1.129              } else {
   1.130 -                return configuration.getText("doclet.File_error", link);
   1.131 +                throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null);
   1.132              }
   1.133 -        } catch (FileNotFoundException exc) {
   1.134 -            return configuration.getText("doclet.File_error", link);
   1.135          } catch (IOException exc) {
   1.136 -            return configuration.getText("doclet.File_error", link);
   1.137 +           throw new Fault(configuration.getText("doclet.File_error", file.getPath()), exc);
   1.138          }
   1.139 -        return null;
   1.140      }
   1.141  
   1.142      /**

mercurial