duke@1: /* jjg@1358: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html.markup; duke@1: bpatel@233: import java.io.*; bpatel@233: duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: duke@1: /** duke@1: * Class for the Html format code generation. jjg@1365: * Initializes PrintWriter with FileWriter, to enable print duke@1: * related methods to generate the code to the named File through FileWriter. duke@1: * jjg@1359: *

This is NOT part of any supported API. jjg@1359: * If you write code that depends on this, you do so at your own risk. jjg@1359: * This code and its internal interfaces are subject to change or jjg@1359: * deletion without notice. jjg@1359: * duke@1: * @since 1.2 duke@1: * @author Atul M Dambalkar bpatel@243: * @author Bhavesh Patel (Modified) duke@1: */ jjg@1365: public class HtmlWriter { duke@1: duke@1: /** duke@1: * Name of the file, to which this writer is writing to. duke@1: */ duke@1: protected final String htmlFilename; duke@1: duke@1: /** duke@1: * The window title of this file duke@1: */ duke@1: protected String winTitle; duke@1: duke@1: /** duke@1: * URL file separator string("/"). duke@1: */ duke@1: public static final String fileseparator = bpatel@766: DirectoryManager.URL_FILE_SEPARATOR; duke@1: duke@1: /** duke@1: * The configuration duke@1: */ duke@1: protected Configuration configuration; duke@1: duke@1: /** bpatel@233: * The flag to indicate whether a member details list is printed or not. bpatel@233: */ bpatel@233: protected boolean memberDetailsListPrinted; bpatel@233: bpatel@233: /** bpatel@243: * Header for tables displaying packages and description.. bpatel@243: */ bpatel@243: protected final String[] packageTableHeader; bpatel@243: bpatel@243: /** bpatel@243: * Summary for use tables displaying class and package use. bpatel@243: */ bpatel@243: protected final String useTableSummary; bpatel@243: bpatel@243: /** bpatel@243: * Column header for class docs displaying Modifier and Type header. bpatel@243: */ bpatel@243: protected final String modifierTypeHeader; bpatel@243: bpatel@766: public final Content overviewLabel; bpatel@766: bpatel@766: public final Content defaultPackageLabel; bpatel@766: bpatel@766: public final Content packageLabel; bpatel@766: bpatel@766: public final Content useLabel; bpatel@766: bpatel@766: public final Content prevLabel; bpatel@766: bpatel@766: public final Content nextLabel; bpatel@766: bpatel@766: public final Content prevclassLabel; bpatel@766: bpatel@766: public final Content nextclassLabel; bpatel@766: bpatel@766: public final Content summaryLabel; bpatel@766: bpatel@766: public final Content detailLabel; bpatel@766: bpatel@766: public final Content framesLabel; bpatel@766: bpatel@766: public final Content noframesLabel; bpatel@766: bpatel@766: public final Content treeLabel; bpatel@766: bpatel@766: public final Content classLabel; bpatel@766: bpatel@766: public final Content deprecatedLabel; bpatel@766: bpatel@766: public final Content deprecatedPhrase; bpatel@766: bpatel@766: public final Content allclassesLabel; bpatel@766: bpatel@766: public final Content indexLabel; bpatel@766: bpatel@766: public final Content helpLabel; bpatel@766: bpatel@766: public final Content seeLabel; bpatel@766: bpatel@766: public final Content descriptionLabel; bpatel@766: bpatel@766: public final Content prevpackageLabel; bpatel@766: bpatel@766: public final Content nextpackageLabel; bpatel@766: bpatel@766: public final Content packagesLabel; bpatel@766: bpatel@766: public final Content methodDetailsLabel; bpatel@766: bpatel@766: public final Content annotationTypeDetailsLabel; bpatel@766: bpatel@766: public final Content fieldDetailsLabel; bpatel@766: bpatel@766: public final Content constructorDetailsLabel; bpatel@766: bpatel@766: public final Content enumConstantsDetailsLabel; bpatel@766: bpatel@766: public final Content specifiedByLabel; bpatel@766: bpatel@766: public final Content overridesLabel; bpatel@766: bpatel@766: public final Content descfrmClassLabel; bpatel@766: bpatel@766: public final Content descfrmInterfaceLabel; bpatel@766: jjg@1365: private final Writer writer; jjg@1365: bpatel@243: /** duke@1: * Constructor. duke@1: * duke@1: * @param path The directory path to be created for this file duke@1: * or null if none to be created. duke@1: * @param filename File Name to which the PrintWriter will duke@1: * do the Output. duke@1: * @param docencoding Encoding to be used for this file. duke@1: * @exception IOException Exception raised by the FileWriter is passed on duke@1: * to next level. jjg@1358: * @exception UnsupportedEncodingException Exception raised by the duke@1: * OutputStreamWriter is passed on to next level. duke@1: */ duke@1: public HtmlWriter(Configuration configuration, duke@1: String path, String filename, String docencoding) duke@1: throws IOException, UnsupportedEncodingException { jjg@1365: writer = Util.genWriter(configuration, path, filename, docencoding); duke@1: this.configuration = configuration; duke@1: htmlFilename = filename; bpatel@233: this.memberDetailsListPrinted = false; bpatel@243: packageTableHeader = new String[] { bpatel@243: configuration.getText("doclet.Package"), bpatel@243: configuration.getText("doclet.Description") bpatel@243: }; bpatel@243: useTableSummary = configuration.getText("doclet.Use_Table_Summary", bpatel@243: configuration.getText("doclet.packages")); bpatel@243: modifierTypeHeader = configuration.getText("doclet.0_and_1", bpatel@243: configuration.getText("doclet.Modifier"), bpatel@243: configuration.getText("doclet.Type")); bpatel@766: overviewLabel = getResource("doclet.Overview"); bpatel@766: defaultPackageLabel = new RawHtml( bpatel@766: DocletConstants.DEFAULT_PACKAGE_NAME); bpatel@766: packageLabel = getResource("doclet.Package"); bpatel@766: useLabel = getResource("doclet.navClassUse"); bpatel@766: prevLabel = getResource("doclet.Prev"); bpatel@766: nextLabel = getResource("doclet.Next"); bpatel@766: prevclassLabel = getResource("doclet.Prev_Class"); bpatel@766: nextclassLabel = getResource("doclet.Next_Class"); bpatel@766: summaryLabel = getResource("doclet.Summary"); bpatel@766: detailLabel = getResource("doclet.Detail"); bpatel@942: framesLabel = getResource("doclet.Frames"); bpatel@942: noframesLabel = getResource("doclet.No_Frames"); bpatel@766: treeLabel = getResource("doclet.Tree"); bpatel@766: classLabel = getResource("doclet.Class"); bpatel@766: deprecatedLabel = getResource("doclet.navDeprecated"); bpatel@766: deprecatedPhrase = getResource("doclet.Deprecated"); bpatel@766: allclassesLabel = getResource("doclet.All_Classes"); bpatel@766: indexLabel = getResource("doclet.Index"); bpatel@766: helpLabel = getResource("doclet.Help"); bpatel@766: seeLabel = getResource("doclet.See"); bpatel@766: descriptionLabel = getResource("doclet.Description"); bpatel@766: prevpackageLabel = getResource("doclet.Prev_Package"); bpatel@766: nextpackageLabel = getResource("doclet.Next_Package"); bpatel@766: packagesLabel = getResource("doclet.Packages"); bpatel@766: methodDetailsLabel = getResource("doclet.Method_Detail"); bpatel@766: annotationTypeDetailsLabel = getResource("doclet.Annotation_Type_Member_Detail"); bpatel@766: fieldDetailsLabel = getResource("doclet.Field_Detail"); bpatel@766: constructorDetailsLabel = getResource("doclet.Constructor_Detail"); bpatel@766: enumConstantsDetailsLabel = getResource("doclet.Enum_Constant_Detail"); bpatel@766: specifiedByLabel = getResource("doclet.Specified_By"); bpatel@766: overridesLabel = getResource("doclet.Overrides"); bpatel@766: descfrmClassLabel = getResource("doclet.Description_From_Class"); bpatel@766: descfrmInterfaceLabel = getResource("doclet.Description_From_Interface"); bpatel@766: } bpatel@766: jjg@1365: public void write(Content c) throws IOException { jjg@1365: c.write(writer, true); jjg@1365: } jjg@1365: jjg@1365: public void close() throws IOException { jjg@1365: writer.close(); jjg@1365: } jjg@1365: bpatel@766: /** bpatel@766: * Get the configuration string as a content. bpatel@766: * bpatel@766: * @param key the key to look for in the configuration file bpatel@766: * @return a content tree for the text bpatel@766: */ bpatel@766: public Content getResource(String key) { bpatel@766: return new StringContent(configuration.getText(key)); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get the configuration string as a content. bpatel@766: * bpatel@766: * @param key the key to look for in the configuration file bpatel@766: * @param a1 string argument added to configuration text bpatel@766: * @return a content tree for the text bpatel@766: */ bpatel@766: public Content getResource(String key, String a1) { bpatel@766: return new RawHtml(configuration.getText(key, a1)); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Get the configuration string as a content. bpatel@766: * bpatel@766: * @param key the key to look for in the configuration file bpatel@766: * @param a1 string argument added to configuration text bpatel@766: * @param a2 string argument added to configuration text bpatel@766: * @return a content tree for the text bpatel@766: */ bpatel@766: public Content getResource(String key, String a1, String a2) { bpatel@766: return new RawHtml(configuration.getText(key, a1, a2)); duke@1: } duke@1: duke@1: /** bpatel@766: * Returns an HtmlTree for the SCRIPT tag. bpatel@766: * bpatel@766: * @return an HtmlTree for the SCRIPT tag bpatel@766: */ bpatel@766: protected HtmlTree getWinTitleScript(){ bpatel@766: HtmlTree script = new HtmlTree(HtmlTag.SCRIPT); bpatel@766: if(winTitle != null && winTitle.length() > 0) { bpatel@766: script.addAttr(HtmlAttr.TYPE, "text/javascript"); bpatel@793: String scriptCode = "" + DocletConstants.NL; bpatel@766: RawHtml scriptContent = new RawHtml(scriptCode); bpatel@766: script.addContent(scriptContent); bpatel@766: } bpatel@766: return script; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Returns a content tree for the SCRIPT tag for the main page(index.html). bpatel@766: * bpatel@766: * @return a content for the SCRIPT tag bpatel@766: */ bpatel@766: protected Content getFramesetJavaScript(){ bpatel@766: HtmlTree script = new HtmlTree(HtmlTag.SCRIPT); bpatel@766: script.addAttr(HtmlAttr.TYPE, "text/javascript"); bpatel@793: String scriptCode = DocletConstants.NL + " targetPage = \"\" + window.location.search;" + DocletConstants.NL + bpatel@793: " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL + bpatel@793: " targetPage = targetPage.substring(1);" + DocletConstants.NL + bpatel@793: " if (targetPage.indexOf(\":\") != -1)" + DocletConstants.NL + bpatel@793: " targetPage = \"undefined\";" + DocletConstants.NL + bpatel@793: " function loadFrames() {" + DocletConstants.NL + bpatel@793: " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL + bpatel@793: " top.classFrame.location = top.targetPage;" + DocletConstants.NL + bpatel@793: " }" + DocletConstants.NL; bpatel@766: RawHtml scriptContent = new RawHtml(scriptCode); bpatel@766: script.addContent(scriptContent); bpatel@766: return script; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Returns an HtmlTree for the BODY tag. bpatel@766: * bpatel@766: * @param includeScript set true if printing windowtitle script bpatel@766: * @param title title for the window bpatel@766: * @return an HtmlTree for the BODY tag bpatel@766: */ bpatel@766: public HtmlTree getBody(boolean includeScript, String title) { bpatel@766: HtmlTree body = new HtmlTree(HtmlTag.BODY); bpatel@766: // Set window title string which is later printed bpatel@766: this.winTitle = title; bpatel@766: // Don't print windowtitle script for overview-frame, allclasses-frame bpatel@766: // and package-frame bpatel@766: if (includeScript) { bpatel@766: body.addContent(getWinTitleScript()); bpatel@766: Content noScript = HtmlTree.NOSCRIPT( bpatel@766: HtmlTree.DIV(getResource("doclet.No_Script_Message"))); bpatel@766: body.addContent(noScript); bpatel@766: } bpatel@766: return body; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Returns an HtmlTree for the TITLE tag. bpatel@766: * bpatel@766: * @return an HtmlTree for the TITLE tag bpatel@766: */ bpatel@766: public HtmlTree getTitle() { bpatel@766: HtmlTree title = HtmlTree.TITLE(new StringContent(winTitle)); bpatel@766: return title; bpatel@766: } duke@1: duke@1: /** bpatel@766: * Return, text passed, with Italics <i> and </i> tags, surrounding it. bpatel@766: * So if the text passed is "Hi", then string returned will be "<i>Hi</i>". duke@1: * duke@1: * @param text String to be printed in between <I> and </I> tags. duke@1: */ duke@1: public String italicsText(String text) { bpatel@766: return "" + text + ""; duke@1: } duke@1: duke@1: public String codeText(String text) { bpatel@766: return "" + text + ""; duke@1: } duke@1: duke@1: /** bpatel@766: * Return "&nbsp;", non-breaking space. bpatel@766: */ bpatel@766: public Content getSpace() { bpatel@766: return RawHtml.nbsp; bpatel@766: } bpatel@766: bpatel@243: /* bpatel@243: * Returns a header for Modifier and Type column of a table. bpatel@243: */ bpatel@243: public String getModifierTypeHeader() { bpatel@243: return modifierTypeHeader; bpatel@243: } duke@1: }