AllClassesFrameWriter.java revision 3233:b5d08bc0d224
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 26package jdk.javadoc.internal.doclets.formats.html; 27 28import java.io.*; 29 30import javax.lang.model.element.Element; 31import javax.lang.model.element.TypeElement; 32 33import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 34import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 35import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 36import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 37import jdk.javadoc.internal.doclets.toolkit.Content; 38import jdk.javadoc.internal.doclets.toolkit.util.DocPath; 39import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 40import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; 41import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder; 42 43 44/** 45 * Generate the file with list of all the classes in this run. This page will be 46 * used in the left-hand bottom frame, when "All Classes" link is clicked in 47 * the left-hand top frame. The name of the generated file is 48 * "allclasses-frame.html". 49 * 50 * <p><b>This is NOT part of any supported API. 51 * If you write code that depends on this, you do so at your own risk. 52 * This code and its internal interfaces are subject to change or 53 * deletion without notice.</b> 54 * 55 * @author Atul M Dambalkar 56 * @author Doug Kramer 57 * @author Bhavesh Patel (Modified) 58 */ 59public class AllClassesFrameWriter extends HtmlDocletWriter { 60 61 /** 62 * Index of all the classes. 63 */ 64 protected IndexBuilder indexbuilder; 65 66 /** 67 * BR tag to be used within a document tree. 68 */ 69 final HtmlTree BR = new HtmlTree(HtmlTag.BR); 70 71 /** 72 * Construct AllClassesFrameWriter object. Also initializes the indexbuilder 73 * variable in this class. 74 * @param configuration The current configuration 75 * @param filename Path to the file which is getting generated. 76 * @param indexbuilder Unicode based Index from {@link IndexBuilder} 77 * @throws IOException 78 * @throws DocletAbortException 79 */ 80 public AllClassesFrameWriter(ConfigurationImpl configuration, 81 DocPath filename, IndexBuilder indexbuilder) 82 throws IOException { 83 super(configuration, filename); 84 this.indexbuilder = indexbuilder; 85 } 86 87 /** 88 * Create AllClassesFrameWriter object. Then use it to generate the 89 * "allclasses-frame.html" file. Generate the file in the current or the 90 * destination directory. 91 * 92 * @param indexbuilder IndexBuilder object for all classes index. 93 * @throws DocletAbortException 94 */ 95 public static void generate(ConfigurationImpl configuration, 96 IndexBuilder indexbuilder) { 97 AllClassesFrameWriter allclassgen; 98 DocPath filename = DocPaths.ALLCLASSES_FRAME; 99 try { 100 allclassgen = new AllClassesFrameWriter(configuration, 101 filename, indexbuilder); 102 allclassgen.buildAllClassesFile(true); 103 allclassgen.close(); 104 filename = DocPaths.ALLCLASSES_NOFRAME; 105 allclassgen = new AllClassesFrameWriter(configuration, 106 filename, indexbuilder); 107 allclassgen.buildAllClassesFile(false); 108 allclassgen.close(); 109 } catch (IOException exc) { 110 configuration.standardmessage. 111 error("doclet.exception_encountered", 112 exc.toString(), filename); 113 throw new DocletAbortException(exc); 114 } 115 } 116 117 /** 118 * Print all the classes in the file. 119 * @param wantFrames True if we want frames. 120 */ 121 protected void buildAllClassesFile(boolean wantFrames) throws IOException { 122 String label = configuration.getText("doclet.All_Classes"); 123 Content body = getBody(false, getWindowTitle(label)); 124 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, 125 HtmlStyle.bar, allclassesLabel); 126 body.addContent(heading); 127 Content ul = new HtmlTree(HtmlTag.UL); 128 // Generate the class links and add it to the tdFont tree. 129 addAllClasses(ul, wantFrames); 130 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 131 ? HtmlTree.MAIN(HtmlStyle.indexContainer, ul) 132 : HtmlTree.DIV(HtmlStyle.indexContainer, ul); 133 body.addContent(htmlTree); 134 printHtmlDocument(null, false, body); 135 } 136 137 /** 138 * Use the sorted index of all the classes and add all the classes to the 139 * content list. 140 * 141 * @param content HtmlTree content to which all classes information will be added 142 * @param wantFrames True if we want frames. 143 */ 144 protected void addAllClasses(Content content, boolean wantFrames) { 145 for (Character unicode : indexbuilder.index()) { 146 addContents(indexbuilder.getMemberList(unicode), wantFrames, content); 147 } 148 } 149 150 /** 151 * Given a list of classes, generate links for each class or interface. 152 * If the class kind is interface, print it in the italics font. Also all 153 * links should target the right-hand frame. If clicked on any class name 154 * in this page, appropriate class page should get opened in the right-hand 155 * frame. 156 * 157 * @param classlist Sorted list of classes. 158 * @param wantFrames True if we want frames. 159 * @param content HtmlTree content to which the links will be added 160 */ 161 protected void addContents(Iterable<? extends Element> classlist, boolean wantFrames, 162 Content content) { 163 for (Element element : classlist) { 164 TypeElement typeElement = (TypeElement)element; 165 if (!utils.isCoreClass(typeElement)) { 166 continue; 167 } 168 Content label = interfaceName(typeElement, false); 169 Content linkContent; 170 if (wantFrames) { 171 linkContent = getLink(new LinkInfoImpl(configuration, 172 LinkInfoImpl.Kind.ALL_CLASSES_FRAME, typeElement).label(label).target("classFrame")); 173 } else { 174 linkContent = getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, typeElement).label(label)); 175 } 176 Content li = HtmlTree.LI(linkContent); 177 content.addContent(li); 178 } 179 } 180} 181