src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Extern.java
changeset 52644 43efb4ca6d6c
parent 51861 f7d40158eb2f
child 52687 526f5cf13972
equal deleted inserted replaced
52643:f8fb0c86f2b3 52644:43efb4ca6d6c
    37 import javax.tools.Diagnostic;
    37 import javax.tools.Diagnostic;
    38 import javax.tools.DocumentationTool;
    38 import javax.tools.DocumentationTool;
    39 
    39 
    40 import jdk.javadoc.doclet.Reporter;
    40 import jdk.javadoc.doclet.Reporter;
    41 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
    41 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
       
    42 import jdk.javadoc.internal.doclets.toolkit.Resources;
    42 
    43 
    43 /**
    44 /**
    44  * Process and manage "-link" and "-linkoffline" to external packages. The
    45  * Process and manage "-link" and "-linkoffline" to external packages. The
    45  * options "-link" and "-linkoffline" both depend on the fact that Javadoc now
    46  * options "-link" and "-linkoffline" both depend on the fact that Javadoc now
    46  * generates "package-list"(lists all the packages which are getting
    47  * generates "package-list"(lists all the packages which are getting
    66 
    67 
    67     /**
    68     /**
    68      * The global configuration information for this run.
    69      * The global configuration information for this run.
    69      */
    70      */
    70     private final BaseConfiguration configuration;
    71     private final BaseConfiguration configuration;
       
    72 
       
    73     private final Resources resources;
       
    74 
       
    75     private final Utils utils;
    71 
    76 
    72     /**
    77     /**
    73      * True if we are using -linkoffline and false if -link is used instead.
    78      * True if we are using -linkoffline and false if -link is used instead.
    74      */
    79      */
    75     private boolean linkoffline = false;
    80     private boolean linkoffline = false;
   120         }
   125         }
   121     }
   126     }
   122 
   127 
   123     public Extern(BaseConfiguration configuration) {
   128     public Extern(BaseConfiguration configuration) {
   124         this.configuration = configuration;
   129         this.configuration = configuration;
       
   130         this.resources = configuration.getResources();
       
   131         this.utils = configuration.utils;
   125     }
   132     }
   126 
   133 
   127     /**
   134     /**
   128      * Determine if a element item is externally documented.
   135      * Determine if a element item is externally documented.
   129      *
   136      *
   132      */
   139      */
   133     public boolean isExternal(Element element) {
   140     public boolean isExternal(Element element) {
   134         if (packageItems.isEmpty()) {
   141         if (packageItems.isEmpty()) {
   135             return false;
   142             return false;
   136         }
   143         }
   137         PackageElement pe = configuration.utils.containingPackage(element);
   144         PackageElement pe = utils.containingPackage(element);
   138         if (pe.isUnnamed()) {
   145         if (pe.isUnnamed()) {
   139             return false;
   146             return false;
   140         }
   147         }
   141 
   148 
   142         return findElementItem(pe) != null;
   149         return findElementItem(pe) != null;
   240 
   247 
   241     private URL toURL(String url) throws Fault {
   248     private URL toURL(String url) throws Fault {
   242         try {
   249         try {
   243             return new URL(url);
   250             return new URL(url);
   244         } catch (MalformedURLException e) {
   251         } catch (MalformedURLException e) {
   245             throw new Fault(configuration.getText("doclet.MalformedURL", url), e);
   252             throw new Fault(resources.getText("doclet.MalformedURL", url), e);
   246         }
   253         }
   247     }
   254     }
   248 
   255 
   249     private class Fault extends Exception {
   256     private class Fault extends Exception {
   250         private static final long serialVersionUID = 0;
   257         private static final long serialVersionUID = 0;
   260      * @param element Element
   267      * @param element Element
   261      */
   268      */
   262     private Item findElementItem(Element element) {
   269     private Item findElementItem(Element element) {
   263         Item item = null;
   270         Item item = null;
   264         if (element instanceof ModuleElement) {
   271         if (element instanceof ModuleElement) {
   265             item = moduleItems.get(configuration.utils.getModuleName((ModuleElement)element));
   272             item = moduleItems.get(utils.getModuleName((ModuleElement)element));
   266         }
   273         }
   267         else if (element instanceof PackageElement) {
   274         else if (element instanceof PackageElement) {
   268             PackageElement packageElement = (PackageElement)element;
   275             PackageElement packageElement = (PackageElement)element;
   269             ModuleElement moduleElement = configuration.utils.containingModule(packageElement);
   276             ModuleElement moduleElement = utils.containingModule(packageElement);
   270             Map<String, Item> pkgMap = packageItems.get(configuration.utils.getModuleName(moduleElement));
   277             Map<String, Item> pkgMap = packageItems.get(utils.getModuleName(moduleElement));
   271             item = (pkgMap != null) ? pkgMap.get(configuration.utils.getPackageName(packageElement)) : null;
   278             item = (pkgMap != null) ? pkgMap.get(utils.getPackageName(packageElement)) : null;
   272         }
   279         }
   273         return item;
   280         return item;
   274     }
   281     }
   275 
   282 
   276     /**
   283     /**
   289     private void readElementListFromURL(String urlpath, URL elemlisturlpath) throws Fault {
   296     private void readElementListFromURL(String urlpath, URL elemlisturlpath) throws Fault {
   290         try {
   297         try {
   291             URL link = elemlisturlpath.toURI().resolve(DocPaths.ELEMENT_LIST.getPath()).toURL();
   298             URL link = elemlisturlpath.toURI().resolve(DocPaths.ELEMENT_LIST.getPath()).toURL();
   292             readElementList(link.openStream(), urlpath, false);
   299             readElementList(link.openStream(), urlpath, false);
   293         } catch (URISyntaxException | MalformedURLException exc) {
   300         } catch (URISyntaxException | MalformedURLException exc) {
   294             throw new Fault(configuration.getText("doclet.MalformedURL", elemlisturlpath.toString()), exc);
   301             throw new Fault(resources.getText("doclet.MalformedURL", elemlisturlpath.toString()), exc);
   295         } catch (IOException exc) {
   302         } catch (IOException exc) {
   296             readAlternateURL(urlpath, elemlisturlpath);
   303             readAlternateURL(urlpath, elemlisturlpath);
   297         }
   304         }
   298     }
   305     }
   299 
   306 
   306     private void readAlternateURL(String urlpath, URL elemlisturlpath) throws Fault {
   313     private void readAlternateURL(String urlpath, URL elemlisturlpath) throws Fault {
   307         try {
   314         try {
   308             URL link = elemlisturlpath.toURI().resolve(DocPaths.PACKAGE_LIST.getPath()).toURL();
   315             URL link = elemlisturlpath.toURI().resolve(DocPaths.PACKAGE_LIST.getPath()).toURL();
   309             readElementList(link.openStream(), urlpath, false);
   316             readElementList(link.openStream(), urlpath, false);
   310         } catch (URISyntaxException | MalformedURLException exc) {
   317         } catch (URISyntaxException | MalformedURLException exc) {
   311             throw new Fault(configuration.getText("doclet.MalformedURL", elemlisturlpath.toString()), exc);
   318             throw new Fault(resources.getText("doclet.MalformedURL", elemlisturlpath.toString()), exc);
   312         } catch (IOException exc) {
   319         } catch (IOException exc) {
   313             throw new Fault(configuration.getText("doclet.URL_error", elemlisturlpath.toString()), exc);
   320             throw new Fault(resources.getText("doclet.URL_error", elemlisturlpath.toString()), exc);
   314         }
   321         }
   315     }
   322     }
   316 
   323 
   317     /**
   324     /**
   318      * Read the "element-list" file which is available locally.
   325      * Read the "element-list" file which is available locally.
   336                 file1 = file1.resolveAgainst(DocumentationTool.Location.DOCUMENTATION_OUTPUT);
   343                 file1 = file1.resolveAgainst(DocumentationTool.Location.DOCUMENTATION_OUTPUT);
   337             }
   344             }
   338             if (file1.exists()) {
   345             if (file1.exists()) {
   339                 readElementList(file1, path);
   346                 readElementList(file1, path);
   340             } else {
   347             } else {
   341                 throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null);
   348                 throw new Fault(resources.getText("doclet.File_error", file.getPath()), null);
   342             }
   349             }
   343         }
   350         }
   344     }
   351     }
   345 
   352 
   346     private void readElementList(DocFile file, String path) throws Fault, DocFileIOException {
   353     private void readElementList(DocFile file, String path) throws Fault, DocFileIOException {
   349                 boolean pathIsRelative
   356                 boolean pathIsRelative
   350                         = !isUrl(path)
   357                         = !isUrl(path)
   351                         && !DocFile.createFileForInput(configuration, path).isAbsolute();
   358                         && !DocFile.createFileForInput(configuration, path).isAbsolute();
   352                 readElementList(file.openInputStream(), path, pathIsRelative);
   359                 readElementList(file.openInputStream(), path, pathIsRelative);
   353             } else {
   360             } else {
   354                 throw new Fault(configuration.getText("doclet.File_error", file.getPath()), null);
   361                 throw new Fault(resources.getText("doclet.File_error", file.getPath()), null);
   355             }
   362             }
   356         } catch (IOException exc) {
   363         } catch (IOException exc) {
   357            throw new Fault(configuration.getText("doclet.File_error", file.getPath()), exc);
   364             throw new Fault(resources.getText("doclet.File_error", file.getPath()), exc);
   358         }
   365         }
   359     }
   366     }
   360 
   367 
   361     /**
   368     /**
   362      * Read the file "element-list" and for each element name found, create
   369      * Read the file "element-list" and for each element name found, create
   414         PackageElement pe = configuration.utils.elementUtils.getPackageElement(packageName);
   421         PackageElement pe = configuration.utils.elementUtils.getPackageElement(packageName);
   415         if (pe != null) {
   422         if (pe != null) {
   416             ModuleElement me = (ModuleElement)pe.getEnclosingElement();
   423             ModuleElement me = (ModuleElement)pe.getEnclosingElement();
   417             if (me == null || me.isUnnamed()) {
   424             if (me == null || me.isUnnamed()) {
   418                 if (moduleName != null)
   425                 if (moduleName != null)
   419                     throw new Fault(configuration.getText("doclet.linkMismatch_PackagedLinkedtoModule",
   426                     throw new Fault(resources.getText("doclet.linkMismatch_PackagedLinkedtoModule",
   420                             path), null);
   427                             path), null);
   421             } else if (moduleName == null)
   428             } else if (moduleName == null)
   422                 throw new Fault(configuration.getText("doclet.linkMismatch_ModuleLinkedtoPackage",
   429                 throw new Fault(resources.getText("doclet.linkMismatch_ModuleLinkedtoPackage",
   423                         path), null);
   430                         path), null);
   424         }
   431         }
   425     }
   432     }
   426 }
   433 }