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

changeset 1410
bfec2a1cc869
parent 1383
b980e8e6aabf
child 1737
7a9ef837e57f
     1.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java	Wed Nov 14 17:23:10 2012 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/SourceToHTMLConverter.java	Thu Nov 15 09:18:36 2012 -0800
     1.3 @@ -60,16 +60,24 @@
     1.4       */
     1.5      private static final Content NEW_LINE = new RawHtml(DocletConstants.NL);
     1.6  
     1.7 +    private final ConfigurationImpl configuration;
     1.8 +
     1.9 +    private final RootDoc rootDoc;
    1.10 +
    1.11 +    private DocPath outputdir;
    1.12 +
    1.13      /**
    1.14       * Relative path from the documentation root to the file that is being
    1.15       * generated.
    1.16       */
    1.17 -    private static DocPath relativePath = DocPath.empty;
    1.18 +    private DocPath relativePath = DocPath.empty;
    1.19  
    1.20 -    /**
    1.21 -     * Source is converted to HTML using static methods below.
    1.22 -     */
    1.23 -    private SourceToHTMLConverter() {}
    1.24 +    private SourceToHTMLConverter(ConfigurationImpl configuration, RootDoc rd,
    1.25 +            DocPath outputdir) {
    1.26 +        this.configuration  = configuration;
    1.27 +        this.rootDoc = rd;
    1.28 +        this.outputdir = outputdir;
    1.29 +    }
    1.30  
    1.31      /**
    1.32       * Convert the Classes in the given RootDoc to an HTML.
    1.33 @@ -80,36 +88,38 @@
    1.34       */
    1.35      public static void convertRoot(ConfigurationImpl configuration, RootDoc rd,
    1.36              DocPath outputdir) {
    1.37 -        if (rd == null || outputdir == null) {
    1.38 +        new SourceToHTMLConverter(configuration, rd, outputdir).generate();
    1.39 +    }
    1.40 +
    1.41 +    void generate() {
    1.42 +        if (rootDoc == null || outputdir == null) {
    1.43              return;
    1.44          }
    1.45 -        PackageDoc[] pds = rd.specifiedPackages();
    1.46 +        PackageDoc[] pds = rootDoc.specifiedPackages();
    1.47          for (int i = 0; i < pds.length; i++) {
    1.48              // If -nodeprecated option is set and the package is marked as deprecated,
    1.49              // do not convert the package files to HTML.
    1.50              if (!(configuration.nodeprecated && Util.isDeprecated(pds[i])))
    1.51 -                convertPackage(configuration, pds[i], outputdir);
    1.52 +                convertPackage(pds[i], outputdir);
    1.53          }
    1.54 -        ClassDoc[] cds = rd.specifiedClasses();
    1.55 +        ClassDoc[] cds = rootDoc.specifiedClasses();
    1.56          for (int i = 0; i < cds.length; i++) {
    1.57              // If -nodeprecated option is set and the class is marked as deprecated
    1.58              // or the containing package is deprecated, do not convert the
    1.59              // package files to HTML.
    1.60              if (!(configuration.nodeprecated &&
    1.61                      (Util.isDeprecated(cds[i]) || Util.isDeprecated(cds[i].containingPackage()))))
    1.62 -                convertClass(configuration, cds[i], outputdir);
    1.63 +                convertClass(cds[i], outputdir);
    1.64          }
    1.65      }
    1.66  
    1.67      /**
    1.68       * Convert the Classes in the given Package to an HTML.
    1.69       *
    1.70 -     * @param configuration the configuration.
    1.71       * @param pd the Package to convert.
    1.72       * @param outputdir the name of the directory to output to.
    1.73       */
    1.74 -    public static void convertPackage(ConfigurationImpl configuration, PackageDoc pd,
    1.75 -            DocPath outputdir) {
    1.76 +    public void convertPackage(PackageDoc pd, DocPath outputdir) {
    1.77          if (pd == null) {
    1.78              return;
    1.79          }
    1.80 @@ -120,19 +130,17 @@
    1.81              // containing package deprecation since it is already check in
    1.82              // the calling method above.
    1.83              if (!(configuration.nodeprecated && Util.isDeprecated(cds[i])))
    1.84 -                convertClass(configuration, cds[i], outputdir);
    1.85 +                convertClass(cds[i], outputdir);
    1.86          }
    1.87      }
    1.88  
    1.89      /**
    1.90       * Convert the given Class to an HTML.
    1.91       *
    1.92 -     * @param configuration the configuration.
    1.93       * @param cd the class to convert.
    1.94       * @param outputdir the name of the directory to output to.
    1.95       */
    1.96 -    public static void convertClass(ConfigurationImpl configuration, ClassDoc cd,
    1.97 -            DocPath outputdir) {
    1.98 +    public void convertClass(ClassDoc cd, DocPath outputdir) {
    1.99          if (cd == null) {
   1.100              return;
   1.101          }
   1.102 @@ -164,7 +172,7 @@
   1.103              try {
   1.104                  while ((line = reader.readLine()) != null) {
   1.105                      addLineNo(pre, lineno);
   1.106 -                    addLine(pre, line, configuration.sourcetab, lineno);
   1.107 +                    addLine(pre, line, lineno);
   1.108                      lineno++;
   1.109                  }
   1.110              } finally {
   1.111 @@ -173,7 +181,7 @@
   1.112              addBlankLines(pre);
   1.113              Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre);
   1.114              body.addContent(div);
   1.115 -            writeToFile(body, outputdir.resolve(DocPath.forClass(cd)), configuration);
   1.116 +            writeToFile(body, outputdir.resolve(DocPath.forClass(cd)));
   1.117          } catch (IOException e) {
   1.118              e.printStackTrace();
   1.119          }
   1.120 @@ -184,15 +192,13 @@
   1.121       *
   1.122       * @param body the documentation content to be written to the file.
   1.123       * @param path the path for the file.
   1.124 -     * @param configuration the Doclet configuration to pass notices to.
   1.125       */
   1.126 -    private static void writeToFile(Content body, DocPath path,
   1.127 -            ConfigurationImpl configuration) throws IOException {
   1.128 -        Content htmlDocType = DocType.Transitional();
   1.129 +    private void writeToFile(Content body, DocPath path) throws IOException {
   1.130 +        Content htmlDocType = DocType.TRANSITIONAL;
   1.131          Content head = new HtmlTree(HtmlTag.HEAD);
   1.132          head.addContent(HtmlTree.TITLE(new StringContent(
   1.133                  configuration.getText("doclet.Window_Source_title"))));
   1.134 -        head.addContent(getStyleSheetProperties(configuration));
   1.135 +        head.addContent(getStyleSheetProperties());
   1.136          Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
   1.137                  head, body);
   1.138          Content htmlDocument = new HtmlDocument(htmlDocType, htmlTree);
   1.139 @@ -210,10 +216,9 @@
   1.140      /**
   1.141       * Returns a link to the stylesheet file.
   1.142       *
   1.143 -     * @param configuration the doclet configuration for the current run of javadoc
   1.144       * @return an HtmlTree for the lINK tag which provides the stylesheet location
   1.145       */
   1.146 -    public static HtmlTree getStyleSheetProperties(ConfigurationImpl configuration) {
   1.147 +    public HtmlTree getStyleSheetProperties() {
   1.148          String filename = configuration.stylesheetfile;
   1.149          DocPath stylesheet;
   1.150          if (filename.length() > 0) {
   1.151 @@ -260,14 +265,13 @@
   1.152       *
   1.153       * @param pre the content tree to which the line will be added.
   1.154       * @param line the string to format.
   1.155 -     * @param tabLength the number of spaces for each tab.
   1.156       * @param currentLineNo the current number.
   1.157       */
   1.158 -    private static void addLine(Content pre, String line, int tabLength,
   1.159 -            int currentLineNo) {
   1.160 +    private void addLine(Content pre, String line, int currentLineNo) {
   1.161          if (line != null) {
   1.162 -            StringBuilder lineBuffer = new StringBuilder(Util.escapeHtmlChars(line));
   1.163 -            Util.replaceTabs(tabLength, lineBuffer);
   1.164 +            StringBuilder lineBuffer = new StringBuilder(line);
   1.165 +            Util.replaceTabs(configuration, lineBuffer);
   1.166 +            Util.escapeHtmlChars(lineBuffer);
   1.167              pre.addContent(new RawHtml(lineBuffer.toString()));
   1.168              Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo));
   1.169              pre.addContent(anchor);

mercurial