11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.javadoc.internal.doclets.formats.html.markup; 27 28 import java.io.*; 29 import java.util.*; 30 31 import jdk.javadoc.doclet.DocletEnvironment.ModuleMode; 32 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; 33 import jdk.javadoc.internal.doclets.toolkit.Content; 34 import jdk.javadoc.internal.doclets.toolkit.Resources; 35 import jdk.javadoc.internal.doclets.toolkit.util.DocFile; 36 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; 37 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 38 import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants; 39 import jdk.javadoc.internal.doclets.toolkit.util.TableTabTypes; 40 41 42 /** 43 * Class for the Html format code generation. 44 * Initializes PrintWriter with FileWriter, to enable print 45 * related methods to generate the code to the named File through FileWriter. 46 * 47 * <p><b>This is NOT part of any supported API. 48 * If you write code that depends on this, you do so at your own risk. 49 * This code and its internal interfaces are subject to change or 50 * deletion without notice.</b> 51 * 52 * @author Atul M Dambalkar 53 * @author Bhavesh Patel (Modified) 54 */ 55 public class HtmlWriter { 56 57 /** 58 * The window title of this file 59 */ 60 protected String winTitle; 61 62 /** 63 * The configuration 64 */ 65 protected BaseConfiguration configuration; 66 67 /** 68 * Header for table displaying modules and description. 69 */ 70 protected final List<String> moduleTableHeader; 71 72 /** 73 * Header for tables displaying packages and description. 74 */ 75 protected final List<String> packageTableHeader; 76 77 /** 78 * Header for tables displaying modules and description. 79 */ 80 protected final List<String> requiresTableHeader; 81 82 /** 83 * Header for tables displaying packages and description. 84 */ 85 protected final List<String> exportedPackagesTableHeader; 86 87 /** 88 * Header for tables displaying modules and exported packages. 89 */ 90 protected final List<String> indirectPackagesTableHeader; 91 92 /** 93 * Header for tables displaying types and description. 94 */ 95 protected final List<String> usesTableHeader; 96 97 /** 98 * Header for tables displaying types and description. 99 */ 100 protected final List<String> providesTableHeader; 101 102 /** 103 * Summary for use tables displaying class and package use. 104 */ 105 protected final String useTableSummary; 106 107 /** 108 * Column header for class docs displaying Modifier and Type header. 109 */ 110 protected final String modifierTypeHeader; 111 112 private final DocFile docFile; 113 114 protected Content script; 115 116 117 /** 118 * Constructor. 119 * 120 * @param path The directory path to be created for this file 121 * or null if none to be created. 122 */ 123 public HtmlWriter(BaseConfiguration configuration, DocPath path) { 124 docFile = DocFile.createFileForOutput(configuration, path); 125 this.configuration = configuration; 126 127 // The following should be converted to shared Content objects 128 // and moved to Contents, but that will require additional 129 // changes at the use sites. 130 Resources resources = configuration.getResources(); 131 moduleTableHeader = Arrays.asList( 132 resources.getText("doclet.Module"), 133 resources.getText("doclet.Description")); 134 packageTableHeader = new ArrayList<>(); 135 packageTableHeader.add(resources.getText("doclet.Package")); 136 packageTableHeader.add(resources.getText("doclet.Description")); 137 requiresTableHeader = new ArrayList<>(); 138 requiresTableHeader.add(resources.getText("doclet.Modifier")); 139 requiresTableHeader.add(resources.getText("doclet.Module")); 140 requiresTableHeader.add(resources.getText("doclet.Description")); 141 exportedPackagesTableHeader = new ArrayList<>(); 142 exportedPackagesTableHeader.add(resources.getText("doclet.Package")); 143 if (configuration.docEnv.getModuleMode() == ModuleMode.ALL) { 144 exportedPackagesTableHeader.add(resources.getText("doclet.Module")); 145 } 146 exportedPackagesTableHeader.add(resources.getText("doclet.Description")); 147 indirectPackagesTableHeader = new ArrayList<>(); 148 indirectPackagesTableHeader.add(resources.getText("doclet.From")); 149 indirectPackagesTableHeader.add(resources.getText("doclet.Packages")); 150 usesTableHeader = new ArrayList<>(); 151 usesTableHeader.add(resources.getText("doclet.Type")); 152 usesTableHeader.add(resources.getText("doclet.Description")); 153 providesTableHeader = new ArrayList<>(); 154 providesTableHeader.add(resources.getText("doclet.Type")); 155 providesTableHeader.add(resources.getText("doclet.Description")); 156 useTableSummary = resources.getText("doclet.Use_Table_Summary", 157 resources.getText("doclet.packages")); 158 modifierTypeHeader = resources.getText("doclet.0_and_1", 159 resources.getText("doclet.Modifier"), 160 resources.getText("doclet.Type")); 161 } 162 163 public void write(Content c) throws DocFileIOException { 164 try (Writer writer = docFile.openWriter()) { 165 c.write(writer, true); 166 } catch (IOException e) { 167 throw new DocFileIOException(docFile, DocFileIOException.Mode.WRITE, e); 168 } 169 } 170 171 /** 172 * Returns an HtmlTree for the SCRIPT tag. 173 * 174 * @return an HtmlTree for the SCRIPT tag 175 */ 176 protected HtmlTree getWinTitleScript(){ 177 HtmlTree scriptTree = HtmlTree.SCRIPT(); 178 if(winTitle != null && winTitle.length() > 0) { 179 String scriptCode = "<!--\n" + 180 " try {\n" + 374 375 /** 376 * Adds javascript style variables to the document. 377 * 378 * @param style style to be added as a javascript variable 379 * @param vars variable string to which the style variable will be added 380 */ 381 public void addStyles(HtmlStyle style, StringBuilder vars) { 382 vars.append("var ").append(style).append(" = \"").append(style) 383 .append("\";").append(DocletConstants.NL); 384 } 385 386 /** 387 * Returns an HtmlTree for the TITLE tag. 388 * 389 * @return an HtmlTree for the TITLE tag 390 */ 391 public HtmlTree getTitle() { 392 HtmlTree title = HtmlTree.TITLE(new StringContent(winTitle)); 393 return title; 394 } 395 396 /* 397 * Returns a header for Modifier and Type column of a table. 398 */ 399 public String getModifierTypeHeader() { 400 return modifierTypeHeader; 401 } 402 } | 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.javadoc.internal.doclets.formats.html.markup; 27 28 import java.io.*; 29 import java.util.*; 30 31 import jdk.javadoc.internal.doclets.formats.html.HtmlConfiguration; 32 import jdk.javadoc.internal.doclets.toolkit.Content; 33 import jdk.javadoc.internal.doclets.toolkit.Resources; 34 import jdk.javadoc.internal.doclets.toolkit.util.DocFile; 35 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; 36 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 37 import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants; 38 import jdk.javadoc.internal.doclets.toolkit.util.TableTabTypes; 39 40 41 /** 42 * Class for the Html format code generation. 43 * Initializes PrintWriter with FileWriter, to enable print 44 * related methods to generate the code to the named File through FileWriter. 45 * 46 * <p><b>This is NOT part of any supported API. 47 * If you write code that depends on this, you do so at your own risk. 48 * This code and its internal interfaces are subject to change or 49 * deletion without notice.</b> 50 * 51 * @author Atul M Dambalkar 52 * @author Bhavesh Patel (Modified) 53 */ 54 public class HtmlWriter { 55 56 /** 57 * The window title of this file 58 */ 59 protected String winTitle; 60 61 /** 62 * The configuration 63 */ 64 protected HtmlConfiguration configuration; 65 66 private final DocFile docFile; 67 68 protected Content script; 69 70 71 /** 72 * Constructor. 73 * 74 * @param path The directory path to be created for this file 75 * or null if none to be created. 76 */ 77 public HtmlWriter(HtmlConfiguration configuration, DocPath path) { 78 this.configuration = configuration; 79 docFile = DocFile.createFileForOutput(configuration, path); 80 81 // The following should be converted to shared Content objects 82 // and moved to Contents, but that will require additional 83 // changes at the use sites. 84 Resources resources = configuration.getResources(); 85 } 86 87 public void write(Content c) throws DocFileIOException { 88 try (Writer writer = docFile.openWriter()) { 89 c.write(writer, true); 90 } catch (IOException e) { 91 throw new DocFileIOException(docFile, DocFileIOException.Mode.WRITE, e); 92 } 93 } 94 95 /** 96 * Returns an HtmlTree for the SCRIPT tag. 97 * 98 * @return an HtmlTree for the SCRIPT tag 99 */ 100 protected HtmlTree getWinTitleScript(){ 101 HtmlTree scriptTree = HtmlTree.SCRIPT(); 102 if(winTitle != null && winTitle.length() > 0) { 103 String scriptCode = "<!--\n" + 104 " try {\n" + 298 299 /** 300 * Adds javascript style variables to the document. 301 * 302 * @param style style to be added as a javascript variable 303 * @param vars variable string to which the style variable will be added 304 */ 305 public void addStyles(HtmlStyle style, StringBuilder vars) { 306 vars.append("var ").append(style).append(" = \"").append(style) 307 .append("\";").append(DocletConstants.NL); 308 } 309 310 /** 311 * Returns an HtmlTree for the TITLE tag. 312 * 313 * @return an HtmlTree for the TITLE tag 314 */ 315 public HtmlTree getTitle() { 316 HtmlTree title = HtmlTree.TITLE(new StringContent(winTitle)); 317 return title; 318 } 319 } |