1 /*
   2  * Copyright (c) 2013, 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 
  30 import com.sun.javadoc.*;
  31 import com.sun.tools.javac.sym.Profiles;
  32 import com.sun.tools.doclets.formats.html.markup.*;
  33 import com.sun.tools.doclets.internal.toolkit.*;
  34 import com.sun.tools.doclets.internal.toolkit.util.*;
  35 
  36 /**
  37  * Generate the profile package index for the left-hand frame in the generated output.
  38  * A click on the package name in this frame will update the page in the bottom
  39  * left hand frame with the listing of contents of the clicked profile package.
  40  *
  41  *  <p><b>This is NOT part of any supported API.
  42  *  If you write code that depends on this, you do so at your own risk.
  43  *  This code and its internal interfaces are subject to change or
  44  *  deletion without notice.</b>
  45  *
  46  * @author Bhavesh Patel
  47  */
  48 public class ProfilePackageIndexFrameWriter extends AbstractProfileIndexWriter {
  49 
  50     /**
  51      * Construct the ProfilePackageIndexFrameWriter object.
  52      *
  53      * @param configuration the configuration object
  54      * @param filename Name of the package index file to be generated.
  55      */
  56     public ProfilePackageIndexFrameWriter(ConfigurationImpl configuration,
  57                                    DocPath filename) throws IOException {
  58         super(configuration, filename);
  59     }
  60 
  61     /**
  62      * Generate the profile package index file.
  63      * @throws DocletAbortException
  64      * @param configuration the configuration object
  65      * @param profileName the name of the profile being documented
  66      */
  67     public static void generate(ConfigurationImpl configuration, String profileName) {
  68         ProfilePackageIndexFrameWriter profpackgen;
  69         DocPath filename = DocPaths.profileFrame(profileName);
  70         try {
  71             profpackgen = new ProfilePackageIndexFrameWriter(configuration, filename);
  72             profpackgen.buildProfilePackagesIndexFile("doclet.Window_Overview", false, profileName);
  73             profpackgen.close();
  74         } catch (IOException exc) {
  75             configuration.standardmessage.error(
  76                         "doclet.exception_encountered",
  77                         exc.toString(), filename);
  78             throw new DocletAbortException();
  79         }
  80     }
  81 
  82     /**
  83      * {@inheritDoc}
  84      */
  85     protected void addProfilePackagesList(Profiles profiles, String text,
  86             String tableSummary, Content body, String profileName) {
  87         Content profNameContent = new StringContent(profileName);
  88         Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true,
  89                 getTargetProfileLink("classFrame", profNameContent, profileName));
  90         heading.addContent(getSpace());
  91         heading.addContent(packagesLabel);
  92         Content div = HtmlTree.DIV(HtmlStyle.indexContainer, heading);
  93         HtmlTree ul = new HtmlTree(HtmlTag.UL);
  94         ul.addAttr(HtmlAttr.TITLE, packagesLabel.toString());
  95         PackageDoc[] packages = configuration.profilePackages.get(profileName);
  96         for (int i = 0; i < packages.length; i++) {
  97             if ((!(configuration.nodeprecated && Util.isDeprecated(packages[i])))) {
  98                 ul.addContent(getPackage(packages[i], profileName));
  99             }
 100         }
 101         div.addContent(ul);
 102         body.addContent(div);
 103     }
 104 
 105     /**
 106      * Gets each package name as a separate link.
 107      *
 108      * @param pd PackageDoc
 109      * @param profileName the name of the profile being documented
 110      * @return content for the package link
 111      */
 112     protected Content getPackage(PackageDoc pd, String profileName) {
 113         Content packageLinkContent;
 114         Content pkgLabel;
 115         if (pd.name().length() > 0) {
 116             pkgLabel = getPackageLabel(pd.name());
 117             packageLinkContent = getHyperLink(pathString(pd,
 118                      DocPaths.profilePackageFrame(profileName)), pkgLabel, "",
 119                     "packageFrame");
 120         } else {
 121             pkgLabel = new RawHtml("&lt;unnamed package&gt;");
 122             packageLinkContent = getHyperLink(DocPaths.PACKAGE_FRAME,
 123                     pkgLabel, "", "packageFrame");
 124         }
 125         Content li = HtmlTree.LI(packageLinkContent);
 126         return li;
 127     }
 128 
 129     /**
 130      * {@inheritDoc}
 131      */
 132     protected void addNavigationBarHeader(Content body) {
 133         Content headerContent;
 134         if (configuration.packagesheader.length() > 0) {
 135             headerContent = new RawHtml(replaceDocRootDir(configuration.packagesheader));
 136         } else {
 137             headerContent = new RawHtml(replaceDocRootDir(configuration.header));
 138         }
 139         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
 140                 HtmlStyle.bar, headerContent);
 141         body.addContent(heading);
 142     }
 143 
 144     /**
 145      * Do nothing as there is no overview information in this page.
 146      */
 147     protected void addOverviewHeader(Content body) {
 148     }
 149     
 150     protected void addProfilesList(Profiles profiles, String text,
 151             String tableSummary, Content body) {
 152     }
 153 
 154     /**
 155      * Adds "All Classes" link for the top of the left-hand frame page to the
 156      * documentation tree.
 157      *
 158      * @param div the Content object to which the all classes link should be added
 159      */
 160     protected void addAllClassesLink(Content div) {
 161         Content linkContent = getHyperLink(DocPaths.ALLCLASSES_FRAME,
 162                 allclassesLabel, "", "packageFrame");
 163         Content span = HtmlTree.SPAN(linkContent);
 164         div.addContent(span);
 165     }
 166 
 167     /**
 168      * Adds "All Packages" link for the top of the left-hand frame page to the
 169      * documentation tree.
 170      *
 171      * @param div the Content object to which the all packages link should be added
 172      */
 173     protected void addAllPackagesLink(Content div) {
 174         Content linkContent = getHyperLink(DocPaths.OVERVIEW_FRAME,
 175                 allpackagesLabel, "", "profileListFrame");
 176         Content span = HtmlTree.SPAN(linkContent);
 177         div.addContent(span);
 178     }
 179 
 180     /**
 181      * Adds "All Profiles" link for the top of the left-hand frame page to the
 182      * documentation tree.
 183      *
 184      * @param div the Content object to which the all profiles link should be added
 185      */
 186     protected void addAllProfilesLink(Content div) {
 187         Content linkContent = getHyperLink(DocPaths.PROFILE_OVERVIEW_FRAME,
 188                 allprofilesLabel, "", "profileListFrame");
 189         Content span = HtmlTree.SPAN(linkContent);
 190         div.addContent(span);
 191     }
 192 
 193     /**
 194      * {@inheritDoc}
 195      */
 196     protected void addNavigationBarFooter(Content body) {
 197         Content p = HtmlTree.P(getSpace());
 198         body.addContent(p);
 199     }
 200 }