duke@1: /* bpatel@1568: * Copyright (c) 1997, 2013, 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@1417: import java.util.*; jjg@1740: import java.util.regex.Matcher; jjg@1740: import java.util.regex.Pattern; 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: * The window title of this file
duke@1: */
duke@1: protected String winTitle;
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@1568: * Header for table displaying profiles and description..
bpatel@1568: */
bpatel@1568: protected final String[] profileTableHeader;
bpatel@1568:
bpatel@1568: /**
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@1568: public final Content profileLabel;
bpatel@1568:
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@1568: public final Content allpackagesLabel;
bpatel@1568:
bpatel@1568: public final Content allprofilesLabel;
bpatel@1568:
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@1568: public final Content prevprofileLabel;
bpatel@1568:
bpatel@1568: public final Content nextprofileLabel;
bpatel@1568:
bpatel@766: public final Content packagesLabel;
bpatel@766:
bpatel@1568: public final Content profilesLabel;
bpatel@1568:
bpatel@766: public final Content methodDetailsLabel;
bpatel@766:
bpatel@766: public final Content annotationTypeDetailsLabel;
bpatel@766:
bpatel@766: public final Content fieldDetailsLabel;
bpatel@766:
jjg@1606: public final Content propertyDetailsLabel;
jjg@1606:
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@1417: private Content script;
bpatel@1417:
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: * @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: */
jjg@1381: public HtmlWriter(Configuration configuration, DocPath path)
jjg@1372: throws IOException, UnsupportedEncodingException {
jjg@1383: writer = DocFile.createFileForOutput(configuration, path).openWriter();
duke@1: this.configuration = configuration;
bpatel@233: this.memberDetailsListPrinted = false;
bpatel@1568: profileTableHeader = new String[] {
bpatel@1568: configuration.getText("doclet.Profile"),
bpatel@1568: configuration.getText("doclet.Description")
bpatel@1568: };
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");
jjg@1746: defaultPackageLabel = new StringContent(DocletConstants.DEFAULT_PACKAGE_NAME);
bpatel@766: packageLabel = getResource("doclet.Package");
bpatel@1568: profileLabel = getResource("doclet.Profile");
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@1568: allpackagesLabel = getResource("doclet.All_Packages");
bpatel@1568: allprofilesLabel = getResource("doclet.All_Profiles");
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@1568: prevprofileLabel = getResource("doclet.Prev_Profile");
bpatel@1568: nextprofileLabel = getResource("doclet.Next_Profile");
bpatel@766: packagesLabel = getResource("doclet.Packages");
bpatel@1568: profilesLabel = getResource("doclet.Profiles");
bpatel@766: methodDetailsLabel = getResource("doclet.Method_Detail");
bpatel@766: annotationTypeDetailsLabel = getResource("doclet.Annotation_Type_Member_Detail");
bpatel@766: fieldDetailsLabel = getResource("doclet.Field_Detail");
jjg@1606: propertyDetailsLabel = getResource("doclet.Property_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) {
jjg@1740: return configuration.getResource(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
jjg@1740: * @param o string or content argument added to configuration text
bpatel@766: * @return a content tree for the text
bpatel@766: */
jjg@1740: public Content getResource(String key, Object o) {
jjg@1740: return configuration.getResource(key, o);
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
jjg@1740: * @param o1 string or content argument added to configuration text
jjg@1740: * @param o2 string or content argument added to configuration text
bpatel@766: * @return a content tree for the text
bpatel@766: */
jjg@1740: public Content getResource(String key, Object o0, Object o1) {
jjg@1740: return configuration.getResource(key, o0, o1);
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: */
jjg@1737: protected Content getFramesetJavaScript() {
bpatel@766: HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
bpatel@766: script.addAttr(HtmlAttr.TYPE, "text/javascript");
jjg@1737: String scriptCode = DocletConstants.NL +
jjg@1737: " targetPage = \"\" + window.location.search;" + DocletConstants.NL +
bpatel@793: " if (targetPage != \"\" && targetPage != \"undefined\")" + DocletConstants.NL +
bpatel@793: " targetPage = targetPage.substring(1);" + DocletConstants.NL +
bpatel@1829: " if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + DocletConstants.NL +
bpatel@793: " targetPage = \"undefined\";" + DocletConstants.NL +
bpatel@1829: " function validURL(url) {" + DocletConstants.NL +
bpatel@1835: " var pos = url.indexOf(\".html\");" + DocletConstants.NL +
bpatel@1835: " if (pos == -1 || pos != url.length - 5)" + DocletConstants.NL +
bpatel@1829: " return false;" + DocletConstants.NL +
bpatel@1829: " var allowNumber = false;" + DocletConstants.NL +
bpatel@1829: " var allowSep = false;" + DocletConstants.NL +
bpatel@1829: " var seenDot = false;" + DocletConstants.NL +
bpatel@1829: " for (var i = 0; i < url.length - 5; i++) {" + DocletConstants.NL +
bpatel@1829: " var ch = url.charAt(i);" + DocletConstants.NL +
bpatel@1829: " if ('a' <= ch && ch <= 'z' ||" + DocletConstants.NL +
bpatel@1829: " 'A' <= ch && ch <= 'Z' ||" + DocletConstants.NL +
bpatel@1829: " ch == '$' ||" + DocletConstants.NL +
bpatel@1829: " ch == '_') {" + DocletConstants.NL +
bpatel@1829: " allowNumber = true;" + DocletConstants.NL +
bpatel@1829: " allowSep = true;" + DocletConstants.NL +
bpatel@1829: " } else if ('0' <= ch && ch <= '9'" + DocletConstants.NL +
bpatel@1829: " || ch == '-') {" + DocletConstants.NL +
bpatel@1829: " if (!allowNumber)" + DocletConstants.NL +
bpatel@1829: " return false;" + DocletConstants.NL +
bpatel@1829: " } else if (ch == '/' || ch == '.') {" + DocletConstants.NL +
bpatel@1829: " if (!allowSep)" + DocletConstants.NL +
bpatel@1829: " return false;" + DocletConstants.NL +
bpatel@1829: " allowNumber = false;" + DocletConstants.NL +
bpatel@1829: " allowSep = false;" + DocletConstants.NL +
bpatel@1829: " if (ch == '.')" + DocletConstants.NL +
bpatel@1829: " seenDot = true;" + DocletConstants.NL +
bpatel@1829: " if (ch == '/' && seenDot)" + DocletConstants.NL +
bpatel@1829: " return false;" + DocletConstants.NL +
bpatel@1829: " } else {" + DocletConstants.NL +
bpatel@1829: " return false;"+ DocletConstants.NL +
bpatel@1829: " }" + DocletConstants.NL +
bpatel@1829: " }" + DocletConstants.NL +
bpatel@1829: " return true;" + DocletConstants.NL +
bpatel@1829: " }" + 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@1417: this.script = getWinTitleScript();
bpatel@1417: body.addContent(script);
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@1417: * Generated javascript variables for the document.
bpatel@1417: *
bpatel@1417: * @param typeMap map comprising of method and type relationship
bpatel@1417: * @param methodTypes set comprising of all methods types for this class
bpatel@1417: */
bpatel@1417: public void generateMethodTypesScript(Map" + text + "
";
duke@1: }
duke@1:
duke@1: /**
bpatel@766: * Return " ", 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: }