001/*
002 * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package org.jdrupes.mdoclet.internal.doclets.formats.html;
027
028import org.jdrupes.mdoclet.internal.doclets.formats.html.Navigation.PageMode;
029import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.BodyContents;
030import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.ContentBuilder;
031import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlStyle;
032import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlTree;
033import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.RawHtml;
034import org.jdrupes.mdoclet.internal.doclets.toolkit.Content;
035import org.jdrupes.mdoclet.internal.doclets.toolkit.util.DocFileIOException;
036import org.jdrupes.mdoclet.internal.doclets.toolkit.util.DocPath;
037
038/**
039 * Abstract class to generate the overview files.
040 */
041public abstract class AbstractOverviewIndexWriter extends HtmlDocletWriter {
042
043    /**
044     * Constructs the AbstractOverviewIndexWriter.
045     *
046     * @param configuration  The current configuration
047     * @param filename Name of the module index file to be generated.
048     */
049    public AbstractOverviewIndexWriter(HtmlConfiguration configuration,
050            DocPath filename) {
051        super(configuration, filename);
052    }
053
054    /**
055     * Adds the overview summary comment for this documentation. Add one line
056     * summary at the top of the page and generate a link to the description,
057     * which is added at the end of this page.
058     *
059     * @param target the content to which the overview header will be added
060     */
061    protected void addOverviewHeader(Content target) {
062        addConfigurationTitle(target);
063        addOverviewComment(target);
064        addOverviewTags(target);
065    }
066
067    /**
068     * Adds the overview comment as provided in the file specified by the
069     * "-overview" option on the command line.
070     *
071     * @param content the content to which the overview comment will be added
072     */
073    protected void addOverviewComment(Content content) {
074        if (!utils.getFullBody(configuration.overviewElement).isEmpty()) {
075            addInlineComment(configuration.overviewElement, content);
076        }
077    }
078
079    /**
080     * Adds the block tags provided in the file specified by the "-overview" option.
081     *
082     * @param content the content to which the tags will be added
083     */
084    protected void addOverviewTags(Content content) {
085        if (!utils.getFullBody(configuration.overviewElement).isEmpty()) {
086            addTagsInfo(configuration.overviewElement, content);
087        }
088    }
089
090    /**
091     * Generate and prints the contents in the index file.
092     *
093     * @param title the title of the window
094     * @param description the content for the description META tag
095     * @throws DocFileIOException if there is a problem building the package index file
096     */
097    protected void buildOverviewIndexFile(String title, String description)
098            throws DocFileIOException {
099        String windowOverview = resources.getText(title);
100        Content body = getBody(getWindowTitle(windowOverview));
101        Content main = new ContentBuilder();
102        addOverviewHeader(main);
103        addIndex(main);
104        body.add(new BodyContents()
105            .setHeader(getHeader(PageMode.OVERVIEW))
106            .addMainContent(main)
107            .setFooter(getFooter()));
108        printHtmlDocument(
109            configuration.metakeywords.getOverviewMetaKeywords(title,
110                configuration.getOptions().docTitle()),
111            description, body);
112    }
113
114    /**
115     * Adds the index to the documentation.
116     *
117     * @param target the content to which the packages/modules list will be added
118     */
119    protected abstract void addIndex(Content target);
120
121    /**
122     * Adds the doctitle to the documentation, if it is specified on the command line.
123     *
124     * @param target the content to which the title will be added
125     */
126    protected void addConfigurationTitle(Content target) {
127        String doctitle = configuration.getOptions().docTitle();
128        if (!doctitle.isEmpty()) {
129            var title = RawHtml.of(doctitle);
130            var heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING,
131                HtmlStyle.title, title);
132            var div = HtmlTree.DIV(HtmlStyle.header, heading);
133            target.add(div);
134        }
135    }
136}