src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java
author ksrini
Thu, 30 Nov 2017 06:14:25 -0800
changeset 48029 e9dab2492924
child 48552 f94706337b07
permissions -rw-r--r--
8185985: Html files in doc-files directories should be wrapped with standard header and footer Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48029
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     1
/*
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     4
 *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    10
 *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    15
 * accompanied this code).
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    16
 *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    20
 *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    23
 * questions.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    24
 */
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    25
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    26
package jdk.javadoc.internal.doclets.formats.html;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    27
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    28
import com.sun.source.doctree.DocTree;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    29
import com.sun.source.doctree.EndElementTree;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    30
import com.sun.source.doctree.StartElementTree;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    31
import com.sun.source.doctree.TextTree;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    32
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    33
import jdk.javadoc.internal.doclets.toolkit.Content;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    34
import jdk.javadoc.internal.doclets.toolkit.DocFileElement;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    35
import jdk.javadoc.internal.doclets.toolkit.DocFilesHandler;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    36
import jdk.javadoc.internal.doclets.toolkit.util.DocFile;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    37
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    38
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    39
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    40
import jdk.javadoc.internal.doclets.toolkit.util.Utils;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    41
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    42
import javax.lang.model.element.Element;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    43
import javax.lang.model.element.ModuleElement;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    44
import javax.lang.model.element.PackageElement;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    45
import javax.tools.FileObject;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    46
import javax.tools.JavaFileManager.Location;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    47
import java.util.Collections;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    48
import java.util.List;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    49
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    50
public class DocFilesHandlerImpl implements DocFilesHandler {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    51
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    52
    public final Element element;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    53
    public final Location location;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    54
    public final DocPath  source;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    55
    public final HtmlConfiguration configuration;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    56
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    57
    /**
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    58
     * Constructor to construct the DocFilesWriter object.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    59
     *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    60
     * @param configuration the configuration of this doclet.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    61
     * @param element the containing element of the doc-files.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    62
     *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    63
     */
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    64
    public DocFilesHandlerImpl(HtmlConfiguration configuration, Element element) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    65
        this.configuration = configuration;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    66
        this.element = element;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    67
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    68
        switch (element.getKind()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    69
            case MODULE:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    70
                location = configuration.utils.getLocationForModule((ModuleElement)element);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    71
                source = DocPaths.DOC_FILES;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    72
                break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    73
            case PACKAGE:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    74
                location = configuration.utils.getLocationForPackage((PackageElement)element);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    75
                source = DocPath.forPackage((PackageElement)element).resolve(DocPaths.DOC_FILES);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    76
                break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    77
            default:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    78
                throw new AssertionError("unsupported element " + element);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    79
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    80
    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    81
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    82
    /**
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    83
     * Copy doc-files directory and its contents from the source
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    84
     * elements directory to the generated documentation directory.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    85
     *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    86
     * @throws DocFileIOException if there is a problem while copying
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    87
     *         the documentation files
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    88
     */
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    89
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    90
    public void copyDocFiles()  throws DocFileIOException {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    91
        boolean first = true;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    92
        for (DocFile srcdir : DocFile.list(configuration, location, source)) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    93
            if (!srcdir.isDirectory()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    94
                continue;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    95
            }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    96
            DocPath path = null;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    97
            switch (this.element.getKind()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    98
                case MODULE:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
    99
                    path = DocPath.forModule((ModuleElement)this.element);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   100
                    break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   101
                case PACKAGE:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   102
                    path = DocPath.forPackage((PackageElement)this.element);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   103
                    break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   104
                default:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   105
                    throw new AssertionError("unknown kind:" + this.element.getKind());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   106
            }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   107
            copyDirectory(srcdir, path.resolve(DocPaths.DOC_FILES), first);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   108
            first = false;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   109
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   110
    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   111
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   112
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   113
    private void copyDirectory(DocFile srcdir, final DocPath dstDocPath,
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   114
                               boolean first) throws DocFileIOException {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   115
        DocFile dstdir = DocFile.createFileForOutput(configuration, dstDocPath);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   116
        if (srcdir.isSameFile(dstdir)) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   117
            return;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   118
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   119
        for (DocFile srcfile: srcdir.list()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   120
            DocFile destfile = dstdir.resolve(srcfile.getName());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   121
            if (srcfile.isFile()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   122
                if (destfile.exists() && !first) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   123
                    configuration.messages.warning("doclet.Copy_Overwrite_warning",
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   124
                            srcfile.getPath(), dstdir.getPath());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   125
                } else {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   126
                    configuration.messages.notice("doclet.Copying_File_0_To_Dir_1",
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   127
                            srcfile.getPath(), dstdir.getPath());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   128
                    if (Utils.toLowerCase(srcfile.getPath()).endsWith(".html")) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   129
                        handleHtmlFile(srcfile, dstDocPath);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   130
                    } else {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   131
                        destfile.copyFile(srcfile);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   132
                    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   133
                }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   134
            } else if (srcfile.isDirectory()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   135
                if (configuration.copydocfilesubdirs
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   136
                        && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   137
                    DocPath dirDocPath = dstDocPath.resolve(srcfile.getName());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   138
                    copyDirectory(srcfile, dirDocPath, first);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   139
                }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   140
            }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   141
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   142
    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   143
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   144
    private void handleHtmlFile(DocFile srcfile, DocPath dstPath) throws DocFileIOException {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   145
        DocPath dfilePath = dstPath.resolve(srcfile.getName());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   146
        HtmlDocletWriter docletWriter = new DocFileWriter(configuration, dfilePath, element);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   147
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   148
        Utils utils = configuration.utils;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   149
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   150
        FileObject fileObject = srcfile.getFileObject();
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   151
        DocFileElement dfElement = new DocFileElement(element, fileObject);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   152
        String title = getWindowTitle(docletWriter, dfElement).trim();
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   153
        HtmlTree htmlContent = docletWriter.getBody(true, title);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   154
        docletWriter.addTop(htmlContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   155
        docletWriter.addNavLinks(true, htmlContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   156
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   157
        List<? extends DocTree> fullBody = utils.getFullBody(dfElement);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   158
        Content bodyContent = docletWriter.commentTagsToContent(null, dfElement, fullBody, false);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   159
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   160
        docletWriter.addTagsInfo(dfElement, bodyContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   161
        htmlContent.addContent(bodyContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   162
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   163
        docletWriter.addNavLinks(false, htmlContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   164
        docletWriter.addBottom(htmlContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   165
        docletWriter.printHtmlDocument(Collections.emptyList(), false, htmlContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   166
    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   167
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   168
    private String getWindowTitle(HtmlDocletWriter docletWriter, Element element) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   169
        List<? extends DocTree> preamble = configuration.utils.getPreamble(element);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   170
        StringBuilder sb = new StringBuilder();
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   171
        boolean titleFound = false;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   172
        loop:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   173
        for (DocTree dt : preamble) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   174
            switch (dt.getKind()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   175
                case START_ELEMENT:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   176
                    StartElementTree nodeStart = (StartElementTree)dt;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   177
                    if (Utils.toLowerCase(nodeStart.getName().toString()).equals("title")) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   178
                        titleFound = true;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   179
                    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   180
                    break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   181
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   182
                case END_ELEMENT:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   183
                    EndElementTree nodeEnd = (EndElementTree)dt;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   184
                    if (Utils.toLowerCase(nodeEnd.getName().toString()).equals("title")) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   185
                        break loop;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   186
                    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   187
                    break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   188
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   189
                case TEXT:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   190
                    TextTree nodeText = (TextTree)dt;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   191
                    if (titleFound)
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   192
                        sb.append(nodeText.getBody());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   193
                    break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   194
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   195
                default:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   196
                    // do nothing
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   197
            }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   198
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   199
        return docletWriter.getWindowTitle(sb.toString().trim());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   200
    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   201
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   202
    private static class DocFileWriter extends HtmlDocletWriter {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   203
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   204
        final PackageElement pkg;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   205
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   206
        /**
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   207
         * Constructor to construct the HtmlDocletWriter object.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   208
         *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   209
         * @param configuration the configuruation of this doclet.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   210
         * @param path          the file to be generated.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   211
         * @param e             the anchoring element.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   212
         */
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   213
        public DocFileWriter(HtmlConfiguration configuration, DocPath path, Element e) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   214
            super(configuration, path);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   215
            switch (e.getKind()) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   216
                case PACKAGE:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   217
                    pkg = (PackageElement)e;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   218
                    break;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   219
                default:
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   220
                    throw new AssertionError("unsupported element: " + e.getKind());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   221
            }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   222
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   223
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   224
        /**
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   225
         * Get the module link.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   226
         *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   227
         * @return a content tree for the module link
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   228
         */
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   229
        @Override
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   230
        protected Content getNavLinkModule() {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   231
            Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(pkg),
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   232
                    contents.moduleLabel);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   233
            Content li = HtmlTree.LI(linkContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   234
            return li;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   235
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   236
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   237
        /**
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   238
         * Get this package link.
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   239
         *
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   240
         * @return a content tree for the package link
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   241
         */
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   242
        @Override
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   243
        protected Content getNavLinkPackage() {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   244
            Content linkContent = getPackageLink(pkg,
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   245
                    contents.packageLabel);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   246
            Content li = HtmlTree.LI(linkContent);
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   247
            return li;
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   248
        }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   249
    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents:
diff changeset
   250
}