src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Links.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58286 e4d90117c5de
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     1
/*
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 54051
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     4
 *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    10
 *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    15
 * accompanied this code).
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    16
 *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    20
 *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    23
 * questions.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    24
 */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    25
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    26
package jdk.javadoc.internal.doclets.formats.html.markup;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    27
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    28
import jdk.javadoc.internal.doclets.formats.html.SectionName;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    29
import jdk.javadoc.internal.doclets.toolkit.Content;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    30
import jdk.javadoc.internal.doclets.toolkit.util.DocLink;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    31
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    32
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    33
/**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    34
 * Factory for HTML A elements, both links (with a {@code href} attribute)
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    35
 * and anchors (with an {@code id} or {@code name} attribute).
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    36
 *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    37
 * Most methods in this class are static factory methods.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    38
 * The exceptions are those methods that directly or indirectly depend on the HTML version
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    39
 * being used, when determining valid HTML names (ids),
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    40
 * and those methods that generate anchors.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    41
 *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    42
 *  <p><b>This is NOT part of any supported API.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    43
 *  If you write code that depends on this, you do so at your own risk.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    44
 *  This code and its internal interfaces are subject to change or
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    45
 *  deletion without notice.</b>
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    46
 */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    47
public class Links {
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    48
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
    49
    private final DocPath file;
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    50
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    51
    /**
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
    52
     * Creates a {@code Links} object for a specific file, to be written in a specific HTML version.
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    53
     * The version is used by the {@link #getName(String) getName} method
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    54
     * to help determine valid HTML names (ids), and to determine whether
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    55
     * to use an {@code id} or {@code name} attribute when creating anchors.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    56
     *
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
    57
     * @param file the file
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    58
     */
53562
0d9dee001667 8215577: Remove javadoc support for HTML 4
pmuthuswamy
parents: 48654
diff changeset
    59
    public Links(DocPath file) {
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
    60
        this.file = file;
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    61
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    62
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    63
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    64
     * Creates an anchor of the form {@code <a id="name"><!-- --></a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    65
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    66
     * @param name the value for the {@code id} or {@code name} attribute
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    67
     * @return a content tree for the anchor
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    68
     */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    69
    public Content createAnchor(String name) {
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    70
        return createAnchor(getName(name), null);
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    71
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    72
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    73
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    74
     * Creates an anchor of the form {@code <a id="sectionName"><!-- --></a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    75
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    76
     * @param sectionName the value for the {@code id} or {@code name} attribute
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    77
     * @return a content tree for the anchor
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    78
     */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    79
    public Content createAnchor(SectionName sectionName) {
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    80
        return createAnchor(sectionName.getName(), null);
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    81
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    82
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    83
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    84
     * Creates an anchor of the form {@code <a id="sectionNameName"><!-- --></a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    85
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    86
     * @param sectionName the first part of the value for the {@code id} or {@code name} attribute
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    87
     * @param name the second part of the value for the {@code id} or {@code name} attribute
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    88
     * @return a content tree for the anchor
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    89
     */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    90
    public Content createAnchor(SectionName sectionName, String name) {
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    91
        return createAnchor(sectionName.getName() + getName(name), null);
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    92
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    93
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    94
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    95
     * Creates an anchor of the form {@code <a id="anchorName">content</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    96
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    97
     * @param name the value for the {@code id} or {@code name} attribute
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    98
     * @param content the content that should be added to the anchor,
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
    99
     *              or null, to use an empty comment
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   100
     * @return a content tree for the marker anchor
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   101
     */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   102
    public Content createAnchor(String name, Content content) {
55339
0530705ca300 8223364: Bad placement of anchor relative to header
hannesw
parents: 54060
diff changeset
   103
        return HtmlTree.A_ID(getName(name), (content == null ? EMPTY_COMMENT : content));
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   104
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   105
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   106
    private static final Content EMPTY_COMMENT = new Comment(" ");
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   107
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   108
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   109
     * Creates a link of the form {@code <a href="#where">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   110
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   111
     * @param where      the position of the link in the file
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   112
     * @param label      the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   113
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   114
     */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   115
    public Content createLink(String where, Content label) {
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   116
        DocLink l = DocLink.fragment(getName(where));
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   117
        return createLink(l, label, "", "");
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   118
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   119
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   120
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   121
     * Creates a link of the form {@code <a href="#sectionName">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   122
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   123
     * @param sectionName   the section name to which the link will be created
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   124
     * @param label         the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   125
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   126
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   127
    public Content createLink(SectionName sectionName, Content label) {
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   128
        DocLink l =  DocLink.fragment(sectionName.getName());
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   129
        return createLink(l, label, "", "");
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   130
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   131
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   132
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   133
     * Creates a link of the form {@code <a href="#sectionNameWhere">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   134
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   135
     * @param sectionName   the section name combined with where to which the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   136
     *                      will be created
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   137
     * @param where         the fragment combined with sectionName to which the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   138
     *                      will be created
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   139
     * @param label         the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   140
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   141
     */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   142
    public Content createLink(SectionName sectionName, String where, Content label) {
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   143
        DocLink l =  DocLink.fragment(sectionName.getName() + getName(where));
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   144
        return createLink(l, label, "", "");
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   145
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   146
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   147
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   148
     * Creates a link of the form {@code <a href="#stylename" title="title" target="target">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   149
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   150
     * @param sectionName   the section name to which the link will be created
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   151
     * @param label     the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   152
     * @param title     the title for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   153
     * @param target    the target for the link, or null
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   154
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   155
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   156
    public Content createLink(SectionName sectionName, Content label, String title, String target) {
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   157
        DocLink l = DocLink.fragment(sectionName.getName());
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   158
        return createLink(l, label, title, target);
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   159
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   160
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   161
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   162
     * Creates a link of the form {@code <a href="path">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   163
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   164
     * @param path   the path for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   165
     * @param label  the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   166
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   167
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   168
    public Content createLink(DocPath path, String label) {
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   169
        return createLink(path, new StringContent(label), false, "", "");
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   170
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   171
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   172
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   173
     * Creates a link of the form {@code <a href="path">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   174
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   175
     * @param path   the path for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   176
     * @param label  the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   177
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   178
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   179
    public Content createLink(DocPath path, Content label) {
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   180
        return createLink(path, label, "", "");
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   181
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   182
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   183
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   184
     * Creates a link of the form {@code <a href="path" title="title" target="target">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   185
     * If {@code strong} is set, the label will be wrapped in
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   186
     *      {@code <span style="typeNameLink">...</span>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   187
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   188
     * @param path      the path for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   189
     * @param label     the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   190
     * @param strong    whether to wrap the {@code label} in a SPAN element
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   191
     * @param title     the title for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   192
     * @param target    the target for the link, or null
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   193
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   194
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   195
    public Content createLink(DocPath path, Content label, boolean strong,
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   196
            String title, String target) {
47851
6a9bb4f77d50 8190822: Remove dead code that could lead to invalid HTML
jjg
parents: 47850
diff changeset
   197
        return createLink(new DocLink(path), label, strong, title, target);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   198
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   199
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   200
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   201
     * Creates a link of the form {@code <a href="path" title="title" target="target">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   202
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   203
     * @param path      the path for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   204
     * @param label     the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   205
     * @param title     the title for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   206
     * @param target    the target for the link, or null
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   207
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   208
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   209
    public Content createLink(DocPath path, Content label, String title, String target) {
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   210
        return createLink(new DocLink(path), label, title, target);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   211
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   212
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   213
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   214
     * Creates a link of the form {@code <a href="link">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   215
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   216
     * @param link      the details for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   217
     * @param label     the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   218
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   219
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   220
    public Content createLink(DocLink link, Content label) {
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   221
        return createLink(link, label, "", "");
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   222
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   223
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   224
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   225
     * Creates a link of the form {@code <a href="path" title="title" target="target">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   226
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   227
     * @param link      the details for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   228
     * @param label     the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   229
     * @param title     the title for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   230
     * @param target    the target for the link, or null
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   231
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   232
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   233
    public Content createLink(DocLink link, Content label, String title, String target) {
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   234
        HtmlTree anchor = HtmlTree.A(link.relativizeAgainst(file).toString(), label);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   235
        if (title != null && title.length() != 0) {
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 54051
diff changeset
   236
            anchor.put(HtmlAttr.TITLE, title);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   237
        }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   238
        if (target != null && target.length() != 0) {
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 54051
diff changeset
   239
            anchor.put(HtmlAttr.TARGET, target);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   240
        }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   241
        return anchor;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   242
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   243
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   244
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   245
     * Creates a link of the form {@code <a href="link" title="title" target="target">label</a>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   246
     * If {@code strong} is set, the label will be wrapped in
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   247
     *      {@code <span style="typeNameLink">...</span>}.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   248
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   249
     * @param link      the details for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   250
     * @param label     the content for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   251
     * @param strong    whether to wrap the {@code label} in a SPAN element
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   252
     * @param title     the title for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   253
     * @param target    the target for the link, or null
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   254
     * @return a content tree for the link
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   255
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   256
    public Content createLink(DocLink link, Content label, boolean strong,
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   257
            String title, String target) {
48295
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   258
        return createLink(link, label, strong, title, target, false);
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   259
    }
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   260
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   261
    /**
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   262
     * Creates a link of the form {@code <a href="link" title="title" target="target">label</a>}.
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   263
     * If {@code strong} is set, the label will be wrapped in
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   264
     *      {@code <span style="typeNameLink">...</span>}.
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   265
     *
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   266
     * @param link       the details for the link
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   267
     * @param label      the content for the link
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   268
     * @param strong     whether to wrap the {@code label} in a SPAN element
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   269
     * @param title      the title for the link
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   270
     * @param target     the target for the link, or null
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   271
     * @param isExternal is the link external to the generated documentation
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   272
     * @return a content tree for the link
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   273
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   274
    public Content createLink(DocLink link, Content label, boolean strong,
48295
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   275
            String title, String target, boolean isExternal) {
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   276
        Content body = label;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   277
        if (strong) {
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   278
            body = HtmlTree.SPAN(HtmlStyle.typeNameLink, body);
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   279
        }
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   280
        HtmlTree l = HtmlTree.A(link.relativizeAgainst(file).toString(), body);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   281
        if (title != null && title.length() != 0) {
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 54051
diff changeset
   282
            l.put(HtmlAttr.TITLE, title);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   283
        }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   284
        if (target != null && target.length() != 0) {
54060
53a95878619f 8220202: Simplify/standardize method naming for HtmlTree
jjg
parents: 54051
diff changeset
   285
            l.put(HtmlAttr.TARGET, target);
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   286
        }
48295
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   287
        if (isExternal) {
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   288
            l.setStyle(HtmlStyle.externalLink);
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   289
        }
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   290
        return l;
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   291
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   292
48295
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   293
    /**
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   294
     * Creates a link.
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   295
     *
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   296
     * @param link       the details for the link
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   297
     * @param label      the content for the link
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   298
     * @param isExternal is the link external to the generated documentation
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   299
     * @return a content tree for the link
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   300
     */
48654
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   301
    public Content createLink(DocLink link, Content label, boolean isExternal) {
36f58bd6269f 8195796: Reduce the size of relative URLs in generated docs
jjg
parents: 48295
diff changeset
   302
        HtmlTree anchor = HtmlTree.A(link.relativizeAgainst(file).toString(), label);
48295
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   303
        anchor.setStyle(HtmlStyle.externalLink);
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   304
        return anchor;
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   305
    }
c79d31ba84b9 8164407: Add module support for -link and -linkoffline javadoc option
bpatel
parents: 47851
diff changeset
   306
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   307
    /**
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   308
     * Converts a name to a valid HTML name (id).
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   309
     * This depends on the HTML version specified when the {@code Links} object was created.
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   310
     *
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   311
     * @param name the string that needs to be converted to a valid HTML name
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   312
     * @return a valid HTML name
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   313
     */
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   314
    public String getName(String name) {
58286
e4d90117c5de 8231122: @index tag with newline causes tag search to fail
hannesw
parents: 55339
diff changeset
   315
        return name.replaceAll("\\s+", "");
47850
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   316
    }
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   317
4a28dc8a86c2 8190821: Introduce a new Links builder class
jjg
parents:
diff changeset
   318
}