src/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java

changeset 1383
b980e8e6aabf
parent 1372
78962d89f283
child 1410
bfec2a1cc869
     1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java	Wed Oct 31 08:31:40 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java	Wed Oct 31 13:48:15 2012 -0700
     1.3 @@ -26,11 +26,13 @@
     1.4  package com.sun.tools.doclets.formats.html;
     1.5  
     1.6  import java.io.*;
     1.7 +
     1.8  import javax.tools.FileObject;
     1.9 +
    1.10  import com.sun.javadoc.*;
    1.11 +import com.sun.tools.doclets.formats.html.markup.*;
    1.12  import com.sun.tools.doclets.internal.toolkit.*;
    1.13  import com.sun.tools.doclets.internal.toolkit.util.*;
    1.14 -import com.sun.tools.doclets.formats.html.markup.*;
    1.15  
    1.16  /**
    1.17   * Converts Java Source Code to HTML.
    1.18 @@ -95,8 +97,7 @@
    1.19              // package files to HTML.
    1.20              if (!(configuration.nodeprecated &&
    1.21                      (Util.isDeprecated(cds[i]) || Util.isDeprecated(cds[i].containingPackage()))))
    1.22 -                convertClass(configuration, cds[i],
    1.23 -                        getPackageOutputDir(outputdir, cds[i].containingPackage()));
    1.24 +                convertClass(configuration, cds[i], outputdir);
    1.25          }
    1.26      }
    1.27  
    1.28 @@ -109,10 +110,9 @@
    1.29       */
    1.30      public static void convertPackage(ConfigurationImpl configuration, PackageDoc pd,
    1.31              DocPath outputdir) {
    1.32 -        if (pd == null || outputdir == null) {
    1.33 +        if (pd == null) {
    1.34              return;
    1.35          }
    1.36 -        DocPath classOutputdir = getPackageOutputDir(outputdir, pd);
    1.37          ClassDoc[] cds = pd.allClasses();
    1.38          for (int i = 0; i < cds.length; i++) {
    1.39              // If -nodeprecated option is set and the class is marked as deprecated,
    1.40 @@ -120,22 +120,11 @@
    1.41              // containing package deprecation since it is already check in
    1.42              // the calling method above.
    1.43              if (!(configuration.nodeprecated && Util.isDeprecated(cds[i])))
    1.44 -                convertClass(configuration, cds[i], classOutputdir);
    1.45 +                convertClass(configuration, cds[i], outputdir);
    1.46          }
    1.47      }
    1.48  
    1.49      /**
    1.50 -     * Return the directory write output to for the given package.
    1.51 -     *
    1.52 -     * @param outputDir the directory to output to.
    1.53 -     * @param pd the Package to generate output for.
    1.54 -     * @return the package output directory as a String.
    1.55 -     */
    1.56 -    private static DocPath getPackageOutputDir(DocPath outputDir, PackageDoc pd) {
    1.57 -        return outputDir.resolve(DocPath.forPackage(pd));
    1.58 -    }
    1.59 -
    1.60 -    /**
    1.61       * Convert the given Class to an HTML.
    1.62       *
    1.63       * @param configuration the configuration.
    1.64 @@ -144,7 +133,7 @@
    1.65       */
    1.66      public static void convertClass(ConfigurationImpl configuration, ClassDoc cd,
    1.67              DocPath outputdir) {
    1.68 -        if (cd == null || outputdir == null) {
    1.69 +        if (cd == null) {
    1.70              return;
    1.71          }
    1.72          try {
    1.73 @@ -184,8 +173,8 @@
    1.74              addBlankLines(pre);
    1.75              Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
    1.76              body.addContent(div);
    1.77 -            writeToFile(body, outputdir, cd.name(), configuration);
    1.78 -        } catch (Exception e){
    1.79 +            writeToFile(body, outputdir.resolve(DocPath.forClass(cd)), configuration);
    1.80 +        } catch (IOException e) {
    1.81              e.printStackTrace();
    1.82          }
    1.83      }
    1.84 @@ -194,12 +183,11 @@
    1.85       * Write the output to the file.
    1.86       *
    1.87       * @param body the documentation content to be written to the file.
    1.88 -     * @param outputDir the directory to output to.
    1.89 -     * @param className the name of the class that I am converting to HTML.
    1.90 +     * @param path the path for the file.
    1.91       * @param configuration the Doclet configuration to pass notices to.
    1.92       */
    1.93 -    private static void writeToFile(Content body, DocPath outputDir,
    1.94 -            String className, ConfigurationImpl configuration) throws IOException {
    1.95 +    private static void writeToFile(Content body, DocPath path,
    1.96 +            ConfigurationImpl configuration) throws IOException {
    1.97          Content htmlDocType = DocType.Transitional();
    1.98          Content head = new HtmlTree(HtmlTag.HEAD);
    1.99          head.addContent(HtmlTree.TITLE(new StringContent(
   1.100 @@ -208,15 +196,15 @@
   1.101          Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
   1.102                  head, body);
   1.103          Content htmlDocument = new HtmlDocument(htmlDocType, htmlTree);
   1.104 -        File dir = outputDir.resolveAgainst(configuration.destDirName);
   1.105 -        dir.mkdirs();
   1.106 -        File newFile = new File(dir, className + ".html");
   1.107 -        configuration.message.notice("doclet.Generating_0", newFile.getPath());
   1.108 -        FileOutputStream fout = new FileOutputStream(newFile);
   1.109 -        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fout));
   1.110 -        bw.write(htmlDocument.toString());
   1.111 -        bw.close();
   1.112 -        fout.close();
   1.113 +        configuration.message.notice("doclet.Generating_0", path.getPath());
   1.114 +        DocFile df = DocFile.createFileForOutput(configuration, path);
   1.115 +        Writer w = df.openWriter();
   1.116 +        try {
   1.117 +            htmlDocument.write(w, true);
   1.118 +        } finally {
   1.119 +            w.close();
   1.120 +        }
   1.121 +
   1.122      }
   1.123  
   1.124      /**
   1.125 @@ -229,7 +217,8 @@
   1.126          String filename = configuration.stylesheetfile;
   1.127          DocPath stylesheet;
   1.128          if (filename.length() > 0) {
   1.129 -            stylesheet = DocPath.create(new File(filename).getName());
   1.130 +            DocFile file = DocFile.createFileForInput(configuration, filename);
   1.131 +            stylesheet = DocPath.create(file.getName());
   1.132          } else {
   1.133              stylesheet = DocPaths.STYLESHEET;
   1.134          }

mercurial