< prev index next >

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AbstractIndexWriter.java

Print this page




 409         }
 410         addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing,
 411                 false, contentTree);
 412     }
 413 
 414     /**
 415      * Generate a valid HTML name for member index page.
 416      *
 417      * @param unicode the string that needs to be converted to valid HTML name.
 418      * @return a valid HTML name string.
 419      */
 420     public String getNameForIndex(String unicode) {
 421         return "I:" + links.getName(unicode);
 422     }
 423 
 424     /**
 425      * @throws DocFileIOException if there is a problem creating any of the search index files
 426      */
 427     protected void createSearchIndexFiles() throws DocFileIOException {
 428         if (configuration.showModules) {
 429             createSearchIndexFile(DocPaths.MODULE_SEARCH_INDEX_JSON, DocPaths.MODULE_SEARCH_INDEX_ZIP,
 430                     DocPaths.MODULE_SEARCH_INDEX_JS, configuration.moduleSearchIndex, "moduleSearchIndex");

 431         }
 432         if (!configuration.packages.isEmpty()) {
 433             SearchIndexItem si = new SearchIndexItem();
 434             si.setCategory(SearchIndexItem.Category.PACKAGES);
 435             si.setLabel(resources.getText("doclet.All_Packages"));
 436             si.setUrl(DocPaths.ALLPACKAGES_INDEX.getPath());
 437             configuration.packageSearchIndex.add(si);
 438         }
 439         createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JSON, DocPaths.PACKAGE_SEARCH_INDEX_ZIP,
 440                 DocPaths.PACKAGE_SEARCH_INDEX_JS, configuration.packageSearchIndex, "packageSearchIndex");

 441         SearchIndexItem si = new SearchIndexItem();
 442         si.setCategory(SearchIndexItem.Category.TYPES);
 443         si.setLabel(resources.getText("doclet.All_Classes"));
 444         si.setUrl(DocPaths.ALLCLASSES_INDEX.getPath());
 445         configuration.typeSearchIndex.add(si);
 446         createSearchIndexFile(DocPaths.TYPE_SEARCH_INDEX_JSON, DocPaths.TYPE_SEARCH_INDEX_ZIP,
 447                 DocPaths.TYPE_SEARCH_INDEX_JS, configuration.typeSearchIndex, "typeSearchIndex");
 448         createSearchIndexFile(DocPaths.MEMBER_SEARCH_INDEX_JSON, DocPaths.MEMBER_SEARCH_INDEX_ZIP,
 449                 DocPaths.MEMBER_SEARCH_INDEX_JS, configuration.memberSearchIndex, "memberSearchIndex");
 450         createSearchIndexFile(DocPaths.TAG_SEARCH_INDEX_JSON, DocPaths.TAG_SEARCH_INDEX_ZIP,
 451                 DocPaths.TAG_SEARCH_INDEX_JS, configuration.tagSearchIndex, "tagSearchIndex");



 452     }
 453 
 454     /**
 455      * Creates a search index file.
 456      *
 457      * @param searchIndexFile   the file to be generated
 458      * @param searchIndexZip    the zip file to be generated
 459      * @param searchIndexJS     the file for the JavaScript to be generated
 460      * @param searchIndex       the search index items
 461      * @param varName           the variable name to write in the JavaScript file
 462      * @throws DocFileIOException if there is a problem creating the search index file
 463      */
 464     protected void createSearchIndexFile(DocPath searchIndexFile, DocPath searchIndexZip,
 465             DocPath searchIndexJS, Collection<SearchIndexItem> searchIndex, String varName) throws DocFileIOException {
 466         if (!searchIndex.isEmpty()) {



 467             StringBuilder searchVar = new StringBuilder("[");
 468             boolean first = true;
 469             for (SearchIndexItem item : searchIndex) {
 470                 if (first) {
 471                     searchVar.append(item.toString());
 472                     first = false;
 473                 } else {
 474                     searchVar.append(",").append(item.toString());
 475                 }
 476             }
 477             searchVar.append("]");
 478             DocFile jsFile = DocFile.createFileForOutput(configuration, searchIndexJS);
 479             try (Writer wr = jsFile.openWriter()) {
 480                 wr.write(varName);
 481                 wr.write(" = ");
 482                 wr.write(searchVar.toString());
 483             } catch (IOException ie) {
 484                 throw new DocFileIOException(jsFile, DocFileIOException.Mode.WRITE, ie);
 485             }
 486 
 487             DocFile zipFile = DocFile.createFileForOutput(configuration, searchIndexZip);
 488             try (OutputStream fos = zipFile.openOutputStream();
 489                     ZipOutputStream zos = new ZipOutputStream(fos)) {
 490                 try {
 491                     ZipEntry ze = new ZipEntry(searchIndexFile.getPath());
 492                     zos.putNextEntry(ze);
 493                     zos.write(searchVar.toString().getBytes());
 494                 } finally {
 495                     zos.closeEntry();
 496                 }
 497             } catch (IOException ie) {
 498                 throw new DocFileIOException(zipFile, DocFileIOException.Mode.WRITE, ie);
 499             }
 500         }
 501     }
 502 }


 409         }
 410         addPreQualifiedClassLink(LinkInfoImpl.Kind.INDEX, containing,
 411                 false, contentTree);
 412     }
 413 
 414     /**
 415      * Generate a valid HTML name for member index page.
 416      *
 417      * @param unicode the string that needs to be converted to valid HTML name.
 418      * @return a valid HTML name string.
 419      */
 420     public String getNameForIndex(String unicode) {
 421         return "I:" + links.getName(unicode);
 422     }
 423 
 424     /**
 425      * @throws DocFileIOException if there is a problem creating any of the search index files
 426      */
 427     protected void createSearchIndexFiles() throws DocFileIOException {
 428         if (configuration.showModules) {
 429             createSearchIndexFile(DocPaths.MODULE_SEARCH_INDEX_JS,
 430                                   configuration.moduleSearchIndex,
 431                                   "moduleSearchIndex");
 432         }
 433         if (!configuration.packages.isEmpty()) {
 434             SearchIndexItem si = new SearchIndexItem();
 435             si.setCategory(SearchIndexItem.Category.PACKAGES);
 436             si.setLabel(resources.getText("doclet.All_Packages"));
 437             si.setUrl(DocPaths.ALLPACKAGES_INDEX.getPath());
 438             configuration.packageSearchIndex.add(si);
 439         }
 440         createSearchIndexFile(DocPaths.PACKAGE_SEARCH_INDEX_JS,
 441                               configuration.packageSearchIndex,
 442                               "packageSearchIndex");
 443         SearchIndexItem si = new SearchIndexItem();
 444         si.setCategory(SearchIndexItem.Category.TYPES);
 445         si.setLabel(resources.getText("doclet.All_Classes"));
 446         si.setUrl(DocPaths.ALLCLASSES_INDEX.getPath());
 447         configuration.typeSearchIndex.add(si);
 448         createSearchIndexFile(DocPaths.TYPE_SEARCH_INDEX_JS,
 449                               configuration.typeSearchIndex,
 450                               "typeSearchIndex");
 451         createSearchIndexFile(DocPaths.MEMBER_SEARCH_INDEX_JS,
 452                               configuration.memberSearchIndex,
 453                               "memberSearchIndex");
 454         createSearchIndexFile(DocPaths.TAG_SEARCH_INDEX_JS,
 455                               configuration.tagSearchIndex,
 456                               "tagSearchIndex");
 457     }
 458 
 459     /**
 460      * Creates a search index file.
 461      *


 462      * @param searchIndexJS     the file for the JavaScript to be generated
 463      * @param searchIndex       the search index items
 464      * @param varName           the variable name to write in the JavaScript file
 465      * @throws DocFileIOException if there is a problem creating the search index file
 466      */
 467     protected void createSearchIndexFile(DocPath searchIndexJS,
 468                                          Collection<SearchIndexItem> searchIndex,
 469                                          String varName)
 470             throws DocFileIOException
 471     {
 472         if (!searchIndex.isEmpty()) { // TODO: write to disk straight
 473             StringBuilder searchVar = new StringBuilder("[");
 474             boolean first = true;
 475             for (SearchIndexItem item : searchIndex) {
 476                 if (first) {
 477                     searchVar.append(item.toString());
 478                     first = false;
 479                 } else {
 480                     searchVar.append(",").append(item.toString());
 481                 }
 482             }
 483             searchVar.append("]");
 484             DocFile jsFile = DocFile.createFileForOutput(configuration, searchIndexJS);
 485             try (Writer wr = jsFile.openWriter()) {
 486                 wr.write(varName);
 487                 wr.write(" = ");
 488                 wr.write(searchVar.toString());
 489             } catch (IOException ie) {
 490                 throw new DocFileIOException(jsFile, DocFileIOException.Mode.WRITE, ie);
 491             }














 492         }
 493     }
 494 }
< prev index next >