1 /* 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 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 com.sun.tools.doclets.formats.html; 27 28 import java.io.*; 29 import com.sun.tools.doclets.internal.toolkit.util.*; 30 import com.sun.tools.doclets.internal.toolkit.*; 31 import com.sun.tools.doclets.formats.html.markup.*; 32 33 /** 34 * Generate the Help File for the generated API documentation. The help file 35 * contents are helpful for browsing the generated documentation. 36 * 37 * @author Atul M Dambalkar 38 */ 39 public class HelpWriter extends HtmlDocletWriter { 40 41 /** 42 * Constructor to construct HelpWriter object. 43 * @param filename File to be generated. 44 */ 45 public HelpWriter(ConfigurationImpl configuration, 46 String filename) throws IOException { 47 super(configuration, filename); 48 } 49 50 /** 51 * Construct the HelpWriter object and then use it to generate the help 52 * file. The name of the generated file is "help-doc.html". The help file 53 * will get generated if and only if "-helpfile" and "-nohelp" is not used 54 * on the command line. 55 * @throws DocletAbortException 56 */ 57 public static void generate(ConfigurationImpl configuration) { 58 HelpWriter helpgen; 59 String filename = ""; 60 try { 61 filename = "help-doc.html"; 62 helpgen = new HelpWriter(configuration, filename); 63 helpgen.generateHelpFile(); 64 helpgen.close(); 65 } catch (IOException exc) { 66 configuration.standardmessage.error( 67 "doclet.exception_encountered", 68 exc.toString(), filename); 69 throw new DocletAbortException(); 70 } 71 } 72 73 /** 74 * Generate the help file contents. 75 */ 76 protected void generateHelpFile() { 77 String title = configuration.getText("doclet.Window_Help_title"); 78 Content body = getBody(true, getWindowTitle(title)); 79 addTop(body); 80 addNavLinks(true, body); 81 addHelpFileContents(body); 82 addNavLinks(false, body); 83 addBottom(body); 84 printHtmlDocument(null, true, body); 85 } 86 87 /** 88 * Add the help file contents from the resource file to the content tree. While adding the 89 * help file contents it also keeps track of user options. If "-notree" 90 * is used, then the "overview-tree.html" will not get added and hence 91 * help information also will not get added. 92 * 93 * @param contentTree the content tree to which the help file contents will be added 94 */ 95 protected void addHelpFileContents(Content contentTree) { 96 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, HtmlStyle.title, 97 getResource("doclet.Help_line_1")); 98 Content div = HtmlTree.DIV(HtmlStyle.header, heading); 99 Content line2 = HtmlTree.P(HtmlStyle.subTitle, 100 getResource("doclet.Help_line_2")); 101 div.addContent(line2); 102 contentTree.addContent(div); 103 HtmlTree ul = new HtmlTree(HtmlTag.UL); 104 ul.addStyle(HtmlStyle.blockList); 105 if (configuration.createoverview) { 106 Content overviewHeading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 107 getResource("doclet.Overview")); 108 Content liOverview = HtmlTree.LI(HtmlStyle.blockList, overviewHeading); 109 Content line3 = getResource("doclet.Help_line_3", 110 getHyperLinkString("overview-summary.html", 111 configuration.getText("doclet.Overview"))); 112 Content overviewPara = HtmlTree.P(line3); 113 liOverview.addContent(overviewPara); 114 ul.addContent(liOverview); 115 } 116 Content packageHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 117 getResource("doclet.Package")); 118 Content liPackage = HtmlTree.LI(HtmlStyle.blockList, packageHead); 119 Content line4 = getResource("doclet.Help_line_4"); 120 Content packagePara = HtmlTree.P(line4); 121 liPackage.addContent(packagePara); 122 HtmlTree ulPackage = new HtmlTree(HtmlTag.UL); 123 ulPackage.addContent(HtmlTree.LI( 124 getResource("doclet.Interfaces_Italic"))); 125 ulPackage.addContent(HtmlTree.LI( 126 getResource("doclet.Classes"))); 127 ulPackage.addContent(HtmlTree.LI( 128 getResource("doclet.Enums"))); 129 ulPackage.addContent(HtmlTree.LI( 130 getResource("doclet.Exceptions"))); 131 ulPackage.addContent(HtmlTree.LI( 132 getResource("doclet.Errors"))); 133 ulPackage.addContent(HtmlTree.LI( 134 getResource("doclet.AnnotationTypes"))); 135 liPackage.addContent(ulPackage); 136 ul.addContent(liPackage); 137 Content classHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 138 getResource("doclet.Help_line_5")); 139 Content liClass = HtmlTree.LI(HtmlStyle.blockList, classHead); 140 Content line6 = getResource("doclet.Help_line_6"); 141 Content classPara = HtmlTree.P(line6); 142 liClass.addContent(classPara); 143 HtmlTree ul1 = new HtmlTree(HtmlTag.UL); 144 ul1.addContent(HtmlTree.LI( 145 getResource("doclet.Help_line_7"))); 146 ul1.addContent(HtmlTree.LI( 147 getResource("doclet.Help_line_8"))); 148 ul1.addContent(HtmlTree.LI( 149 getResource("doclet.Help_line_9"))); 150 ul1.addContent(HtmlTree.LI( 151 getResource("doclet.Help_line_10"))); 152 ul1.addContent(HtmlTree.LI( 153 getResource("doclet.Help_line_11"))); 154 ul1.addContent(HtmlTree.LI( 155 getResource("doclet.Help_line_12"))); 156 liClass.addContent(ul1); 157 HtmlTree ul2 = new HtmlTree(HtmlTag.UL); 158 ul2.addContent(HtmlTree.LI( 159 getResource("doclet.Nested_Class_Summary"))); 160 ul2.addContent(HtmlTree.LI( 161 getResource("doclet.Field_Summary"))); 162 ul2.addContent(HtmlTree.LI( 163 getResource("doclet.Constructor_Summary"))); 164 ul2.addContent(HtmlTree.LI( 165 getResource("doclet.Method_Summary"))); 166 liClass.addContent(ul2); 167 HtmlTree ul3 = new HtmlTree(HtmlTag.UL); 168 ul3.addContent(HtmlTree.LI( 169 getResource("doclet.Field_Detail"))); 170 ul3.addContent(HtmlTree.LI( 171 getResource("doclet.Constructor_Detail"))); 172 ul3.addContent(HtmlTree.LI( 173 getResource("doclet.Method_Detail"))); 174 liClass.addContent(ul3); 175 Content line13 = getResource("doclet.Help_line_13"); 176 Content para = HtmlTree.P(line13); 177 liClass.addContent(para); 178 ul.addContent(liClass); 179 //Annotation Types 180 Content aHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 181 getResource("doclet.AnnotationType")); 182 Content liAnnotation = HtmlTree.LI(HtmlStyle.blockList, aHead); 183 Content aline1 = getResource("doclet.Help_annotation_type_line_1"); 184 Content aPara = HtmlTree.P(aline1); 185 liAnnotation.addContent(aPara); 186 HtmlTree aul = new HtmlTree(HtmlTag.UL); 187 aul.addContent(HtmlTree.LI( 188 getResource("doclet.Help_annotation_type_line_2"))); 189 aul.addContent(HtmlTree.LI( 190 getResource("doclet.Help_annotation_type_line_3"))); 191 aul.addContent(HtmlTree.LI( 192 getResource("doclet.Annotation_Type_Required_Member_Summary"))); 193 aul.addContent(HtmlTree.LI( 194 getResource("doclet.Annotation_Type_Optional_Member_Summary"))); 195 aul.addContent(HtmlTree.LI( 196 getResource("doclet.Annotation_Type_Member_Detail"))); 197 liAnnotation.addContent(aul); 198 ul.addContent(liAnnotation); 199 //Enums 200 Content enumHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 201 getResource("doclet.Enum")); 202 Content liEnum = HtmlTree.LI(HtmlStyle.blockList, enumHead); 203 Content eline1 = getResource("doclet.Help_enum_line_1"); 204 Content enumPara = HtmlTree.P(eline1); 205 liEnum.addContent(enumPara); 206 HtmlTree eul = new HtmlTree(HtmlTag.UL); 207 eul.addContent(HtmlTree.LI( 208 getResource("doclet.Help_enum_line_2"))); 209 eul.addContent(HtmlTree.LI( 210 getResource("doclet.Help_enum_line_3"))); 211 eul.addContent(HtmlTree.LI( 212 getResource("doclet.Enum_Constant_Summary"))); 213 eul.addContent(HtmlTree.LI( 214 getResource("doclet.Enum_Constant_Detail"))); 215 liEnum.addContent(eul); 216 ul.addContent(liEnum); 217 if (configuration.classuse) { 218 Content useHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 219 getResource("doclet.Help_line_14")); 220 Content liUse = HtmlTree.LI(HtmlStyle.blockList, useHead); 221 Content line15 = getResource("doclet.Help_line_15"); 222 Content usePara = HtmlTree.P(line15); 223 liUse.addContent(usePara); 224 ul.addContent(liUse); 225 } 226 if (configuration.createtree) { 227 Content treeHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 228 getResource("doclet.Help_line_16")); 229 Content liTree = HtmlTree.LI(HtmlStyle.blockList, treeHead); 230 Content line17 = getResource("doclet.Help_line_17_with_tree_link", 231 getHyperLinkString("overview-tree.html", 232 configuration.getText("doclet.Class_Hierarchy"))); 233 Content treePara = HtmlTree.P(line17); 234 liTree.addContent(treePara); 235 HtmlTree tul = new HtmlTree(HtmlTag.UL); 236 tul.addContent(HtmlTree.LI( 237 getResource("doclet.Help_line_18"))); 238 tul.addContent(HtmlTree.LI( 239 getResource("doclet.Help_line_19"))); 240 liTree.addContent(tul); 241 ul.addContent(liTree); 242 } 243 if (!(configuration.nodeprecatedlist || 244 configuration.nodeprecated)) { 245 Content dHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 246 getResource("doclet.Deprecated_API")); 247 Content liDeprecated = HtmlTree.LI(HtmlStyle.blockList, dHead); 248 Content line20 = getResource("doclet.Help_line_20_with_deprecated_api_link", 249 getHyperLinkString("deprecated-list.html", 250 configuration.getText("doclet.Deprecated_API"))); 251 Content dPara = HtmlTree.P(line20); 252 liDeprecated.addContent(dPara); 253 ul.addContent(liDeprecated); 254 } 255 if (configuration.createindex) { 256 String indexlink; 257 if (configuration.splitindex) { 258 indexlink = getHyperLinkString("index-files/index-1.html", 259 configuration.getText("doclet.Index")); 260 } else { 261 indexlink = getHyperLinkString("index-all.html", 262 configuration.getText("doclet.Index")); 263 } 264 Content indexHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 265 getResource("doclet.Help_line_21")); 266 Content liIndex = HtmlTree.LI(HtmlStyle.blockList, indexHead); 267 Content line22 = getResource("doclet.Help_line_22", indexlink); 268 Content indexPara = HtmlTree.P(line22); 269 liIndex.addContent(indexPara); 270 ul.addContent(liIndex); 271 } 272 Content prevHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 273 getResource("doclet.Help_line_23")); 274 Content liPrev = HtmlTree.LI(HtmlStyle.blockList, prevHead); 275 Content line24 = getResource("doclet.Help_line_24"); 276 Content prevPara = HtmlTree.P(line24); 277 liPrev.addContent(prevPara); 278 ul.addContent(liPrev); 279 Content frameHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 280 getResource("doclet.Help_line_25")); 281 Content liFrame = HtmlTree.LI(HtmlStyle.blockList, frameHead); 282 Content line26 = getResource("doclet.Help_line_26"); 283 Content framePara = HtmlTree.P(line26); 284 liFrame.addContent(framePara); 285 ul.addContent(liFrame); 286 Content allclassesHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 287 getResource("doclet.All_Classes")); 288 Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead); 289 Content line27 = getResource("doclet.Help_line_27", 290 getHyperLinkString("allclasses-noframe.html", 291 configuration.getText("doclet.All_Classes"))); 292 Content allclassesPara = HtmlTree.P(line27); 293 liAllClasses.addContent(allclassesPara); 294 ul.addContent(liAllClasses); 295 Content sHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 296 getResource("doclet.Serialized_Form")); 297 Content liSerial = HtmlTree.LI(HtmlStyle.blockList, sHead); 298 Content line28 = getResource("doclet.Help_line_28"); 299 Content serialPara = HtmlTree.P(line28); 300 liSerial.addContent(serialPara); 301 ul.addContent(liSerial); 302 Content constHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 303 getResource("doclet.Constants_Summary")); 304 Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead); 305 Content line29 = getResource("doclet.Help_line_29"); 306 Content constPara = HtmlTree.P(line29); 307 liConst.addContent(constPara); 308 ul.addContent(liConst); 309 Content divContent = HtmlTree.DIV(HtmlStyle.contentContainer, ul); 310 Content line30 = HtmlTree.EM(getResource("doclet.Help_line_30")); 311 divContent.addContent(line30); 312 contentTree.addContent(divContent); 313 } 314 315 /** 316 * Get the help label. 317 * 318 * @return a content tree for the help label 319 */ 320 protected Content getNavLinkHelp() { 321 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, helpLabel); 322 return li; 323 } 324 }