src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageTreeWriter.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2015, 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.doclets.formats.html.markup.*;
  32 import com.sun.tools.doclets.internal.toolkit.*;
  33 import com.sun.tools.doclets.internal.toolkit.util.*;
  34 











  35 /**
  36  * Class to generate Tree page for a package. The name of the file generated is
  37  * "package-tree.html" and it is generated in the respective package directory.
  38  *
  39  *  <p><b>This is NOT part of any supported API.
  40  *  If you write code that depends on this, you do so at your own risk.
  41  *  This code and its internal interfaces are subject to change or
  42  *  deletion without notice.</b>
  43  *
  44  * @author Atul M Dambalkar
  45  * @author Bhavesh Patel (Modified)
  46  */
  47 public class PackageTreeWriter extends AbstractTreeWriter {
  48 
  49     /**
  50      * Package for which tree is to be generated.
  51      */
  52     protected PackageDoc packagedoc;
  53 
  54     /**
  55      * The previous package name in the alpha-order list.
  56      */
  57     protected PackageDoc prev;
  58 
  59     /**
  60      * The next package name in the alpha-order list.
  61      */
  62     protected PackageDoc next;
  63 
  64     /**
  65      * Constructor.





  66      * @throws IOException
  67      * @throws DocletAbortException
  68      */
  69     public PackageTreeWriter(ConfigurationImpl configuration,
  70                              DocPath path,
  71                              PackageDoc packagedoc,
  72                              PackageDoc prev, PackageDoc next)
  73                       throws IOException {
  74         super(configuration, path,
  75               new ClassTree(
  76                 configuration.classDocCatalog.allClasses(packagedoc),
  77                 configuration));
  78         this.packagedoc = packagedoc;
  79         this.prev = prev;
  80         this.next = next;
  81     }
  82 
  83     /**
  84      * Construct a PackageTreeWriter object and then use it to generate the
  85      * package tree page.
  86      *

  87      * @param pkg      Package for which tree file is to be generated.
  88      * @param prev     Previous package in the alpha-ordered list.
  89      * @param next     Next package in the alpha-ordered list.
  90      * @param noDeprecated  If true, do not generate any information for
  91      * deprecated classe or interfaces.
  92      * @throws DocletAbortException
  93      */
  94     public static void generate(ConfigurationImpl configuration,
  95                                 PackageDoc pkg, PackageDoc prev,
  96                                 PackageDoc next, boolean noDeprecated) {
  97         PackageTreeWriter packgen;
  98         DocPath path = DocPath.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE);
  99         try {
 100             packgen = new PackageTreeWriter(configuration, path, pkg,
 101                 prev, next);
 102             packgen.generatePackageTreeFile();
 103             packgen.close();
 104         } catch (IOException exc) {
 105             configuration.standardmessage.error(
 106                         "doclet.exception_encountered",
 107                         exc.toString(), path.getPath());
 108             throw new DocletAbortException(exc);
 109         }
 110     }
 111 
 112     /**
 113      * Generate a separate tree file for each package.

 114      */
 115     protected void generatePackageTreeFile() throws IOException {
 116         HtmlTree body = getPackageTreeHeader();
 117         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
 118                 ? HtmlTree.MAIN()
 119                 : body;
 120         Content headContent = getResource("doclet.Hierarchy_For_Package",
 121                 utils.getPackageName(packagedoc));
 122         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
 123                 HtmlStyle.title, headContent);
 124         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
 125         if (configuration.packages.size() > 1) {
 126             addLinkToMainTree(div);
 127         }
 128         htmlTree.addContent(div);
 129         HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
 130         divTree.addStyle(HtmlStyle.contentContainer);
 131         addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree);
 132         addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree);
 133         addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
 134         addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree);
 135         htmlTree.addContent(divTree);
 136         if (configuration.allowTag(HtmlTag.MAIN)) {
 137             body.addContent(htmlTree);
 138         }
 139         HtmlTree tree = (configuration.allowTag(HtmlTag.FOOTER))
 140                 ? HtmlTree.FOOTER()
 141                 : body;
 142         addNavLinks(false, tree);
 143         addBottom(tree);
 144         if (configuration.allowTag(HtmlTag.FOOTER)) {
 145             body.addContent(tree);
 146         }
 147         printHtmlDocument(null, true, body);
 148     }
 149 
 150     /**
 151      * Get the package tree header.
 152      *
 153      * @return a content tree for the header
 154      */
 155     protected HtmlTree getPackageTreeHeader() {
 156         String title = packagedoc.name() + " " +
 157                 configuration.getText("doclet.Window_Class_Hierarchy");
 158         HtmlTree bodyTree = getBody(true, getWindowTitle(title));
 159         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
 160                 ? HtmlTree.HEADER()
 161                 : bodyTree;
 162         addTop(htmlTree);
 163         addNavLinks(true, htmlTree);
 164         if (configuration.allowTag(HtmlTag.HEADER)) {
 165             bodyTree.addContent(htmlTree);
 166         }
 167         return bodyTree;
 168     }
 169 
 170     /**
 171      * Add a link to the tree for all the packages.
 172      *
 173      * @param div the content tree to which the link will be added
 174      */
 175     protected void addLinkToMainTree(Content div) {
 176         Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel,
 177                 getResource("doclet.Package_Hierarchies"));
 178         div.addContent(span);
 179         HtmlTree ul = new HtmlTree (HtmlTag.UL);
 180         ul.addStyle(HtmlStyle.horizontal);
 181         ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages")));
 182         div.addContent(ul);
 183     }
 184 
 185     /**
 186      * Get link for the previous package tree file.
 187      *
 188      * @return a content tree for the link
 189      */
 190     protected Content getNavLinkPrevious() {
 191         if (prev == null) {
 192             return getNavLinkPrevious(null);
 193         } else {
 194             DocPath path = DocPath.relativePath(packagedoc, prev);
 195             return getNavLinkPrevious(path.resolve(DocPaths.PACKAGE_TREE));
 196         }
 197     }
 198 
 199     /**
 200      * Get link for the next package tree file.
 201      *
 202      * @return a content tree for the link
 203      */
 204     protected Content getNavLinkNext() {
 205         if (next == null) {
 206             return getNavLinkNext(null);
 207         } else {
 208             DocPath path = DocPath.relativePath(packagedoc, next);
 209             return getNavLinkNext(path.resolve(DocPaths.PACKAGE_TREE));
 210         }
 211     }
 212 
 213     /**
 214      * Get link to the package summary page for the package of this tree.
 215      *
 216      * @return a content tree for the package link
 217      */
 218     protected Content getNavLinkPackage() {
 219         Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
 220                 packageLabel);
 221         Content li = HtmlTree.LI(linkContent);
 222         return li;
 223     }
 224 }
   1 /*
   2  * Copyright (c) 1998, 2016, 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 jdk.javadoc.internal.doclets.formats.html;
  27 
  28 import java.io.*;
  29 
  30 import javax.lang.model.element.PackageElement;



  31 
  32 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
  33 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
  34 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
  35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
  36 import jdk.javadoc.internal.doclets.toolkit.Content;
  37 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
  38 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
  39 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
  40 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException;
  41 
  42 
  43 /**
  44  * Class to generate Tree page for a package. The name of the file generated is
  45  * "package-tree.html" and it is generated in the respective package directory.
  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 PackageTreeWriter extends AbstractTreeWriter {
  56 
  57     /**
  58      * Package for which tree is to be generated.
  59      */
  60     protected PackageElement packageElement;
  61 
  62     /**
  63      * The previous package name in the alpha-order list.
  64      */
  65     protected PackageElement prev;
  66 
  67     /**
  68      * The next package name in the alpha-order list.
  69      */
  70     protected PackageElement next;
  71 
  72     /**
  73      * Constructor.
  74      * @param configuration the configuration
  75      * @param path the docpath to generate files into
  76      * @param packageElement the current package
  77      * @param prev the previous package
  78      * @param next the next package
  79      * @throws IOException
  80      * @throws DocletAbortException
  81      */
  82     public PackageTreeWriter(ConfigurationImpl configuration,
  83                              DocPath path,
  84                              PackageElement packageElement,
  85                              PackageElement prev, PackageElement next)
  86                       throws IOException {
  87         super(configuration, path,
  88               new ClassTree(configuration.classDocCatalog.allClasses(packageElement), configuration));
  89         this.packageElement = packageElement;


  90         this.prev = prev;
  91         this.next = next;
  92     }
  93 
  94     /**
  95      * Construct a PackageTreeWriter object and then use it to generate the
  96      * package tree page.
  97      *
  98      * @param configuration the configuration for this run.
  99      * @param pkg      Package for which tree file is to be generated.
 100      * @param prev     Previous package in the alpha-ordered list.
 101      * @param next     Next package in the alpha-ordered list.
 102      * @param noDeprecated  If true, do not generate any information for
 103      * deprecated classe or interfaces.
 104      * @throws DocletAbortException
 105      */
 106     public static void generate(ConfigurationImpl configuration,
 107                                 PackageElement pkg, PackageElement prev,
 108                                 PackageElement next, boolean noDeprecated) {
 109         PackageTreeWriter packgen;
 110         DocPath path = DocPath.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE);
 111         try {
 112             packgen = new PackageTreeWriter(configuration, path, pkg,
 113                 prev, next);
 114             packgen.generatePackageTreeFile();
 115             packgen.close();
 116         } catch (IOException exc) {
 117             configuration.standardmessage.error(
 118                         "doclet.exception_encountered",
 119                         exc.toString(), path.getPath());
 120             throw new DocletAbortException(exc);
 121         }
 122     }
 123 
 124     /**
 125      * Generate a separate tree file for each package.
 126      * @throws java.io.IOException
 127      */
 128     protected void generatePackageTreeFile() throws IOException {
 129         HtmlTree body = getPackageTreeHeader();
 130         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
 131                 ? HtmlTree.MAIN()
 132                 : body;
 133         Content headContent = getResource("doclet.Hierarchy_For_Package",
 134                 utils.getPackageName(packageElement));
 135         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false,
 136                 HtmlStyle.title, headContent);
 137         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
 138         if (configuration.packages.size() > 1) {
 139             addLinkToMainTree(div);
 140         }
 141         htmlTree.addContent(div);
 142         HtmlTree divTree = new HtmlTree(HtmlTag.DIV);
 143         divTree.addStyle(HtmlStyle.contentContainer);
 144         addTree(classtree.baseClasses(), "doclet.Class_Hierarchy", divTree);
 145         addTree(classtree.baseInterfaces(), "doclet.Interface_Hierarchy", divTree);
 146         addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree);
 147         addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree, true);
 148         htmlTree.addContent(divTree);
 149         if (configuration.allowTag(HtmlTag.MAIN)) {
 150             body.addContent(htmlTree);
 151         }
 152         HtmlTree tree = (configuration.allowTag(HtmlTag.FOOTER))
 153                 ? HtmlTree.FOOTER()
 154                 : body;
 155         addNavLinks(false, tree);
 156         addBottom(tree);
 157         if (configuration.allowTag(HtmlTag.FOOTER)) {
 158             body.addContent(tree);
 159         }
 160         printHtmlDocument(null, true, body);
 161     }
 162 
 163     /**
 164      * Get the package tree header.
 165      *
 166      * @return a content tree for the header
 167      */
 168     protected HtmlTree getPackageTreeHeader() {
 169         String packageName = packageElement.isUnnamed() ? "" : utils.getPackageName(packageElement);
 170         String title = packageName + " " + configuration.getText("doclet.Window_Class_Hierarchy");
 171         HtmlTree bodyTree = getBody(true, getWindowTitle(title));
 172         HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER))
 173                 ? HtmlTree.HEADER()
 174                 : bodyTree;
 175         addTop(htmlTree);
 176         addNavLinks(true, htmlTree);
 177         if (configuration.allowTag(HtmlTag.HEADER)) {
 178             bodyTree.addContent(htmlTree);
 179         }
 180         return bodyTree;
 181     }
 182 
 183     /**
 184      * Add a link to the tree for all the packages.
 185      *
 186      * @param div the content tree to which the link will be added
 187      */
 188     protected void addLinkToMainTree(Content div) {
 189         Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel,
 190                 getResource("doclet.Package_Hierarchies"));
 191         div.addContent(span);
 192         HtmlTree ul = new HtmlTree (HtmlTag.UL);
 193         ul.addStyle(HtmlStyle.horizontal);
 194         ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages")));
 195         div.addContent(ul);
 196     }
 197 
 198     /**
 199      * Get link for the previous package tree file.
 200      *
 201      * @return a content tree for the link
 202      */
 203     protected Content getNavLinkPrevious() {
 204         if (prev == null) {
 205             return getNavLinkPrevious(null);
 206         } else {
 207             DocPath path = DocPath.relativePath(packageElement, prev);
 208             return getNavLinkPrevious(path.resolve(DocPaths.PACKAGE_TREE));
 209         }
 210     }
 211 
 212     /**
 213      * Get link for the next package tree file.
 214      *
 215      * @return a content tree for the link
 216      */
 217     protected Content getNavLinkNext() {
 218         if (next == null) {
 219             return getNavLinkNext(null);
 220         } else {
 221             DocPath path = DocPath.relativePath(packageElement, next);
 222             return getNavLinkNext(path.resolve(DocPaths.PACKAGE_TREE));
 223         }
 224     }
 225 
 226     /**
 227      * Get link to the package summary page for the package of this tree.
 228      *
 229      * @return a content tree for the package link
 230      */
 231     protected Content getNavLinkPackage() {
 232         Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
 233                 packageLabel);
 234         Content li = HtmlTree.LI(linkContent);
 235         return li;
 236     }
 237 }