src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/DocPath.java
author ksrini
Thu, 07 Dec 2017 14:15:14 -0800
changeset 48213 59696a3595bd
parent 48029 e9dab2492924
child 48654 36f58bd6269f
permissions -rw-r--r--
8191030: @value Tags are not resolved by javadoc 9. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     1
/*
48029
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     4
 *
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    10
 *
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    15
 * accompanied this code).
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    16
 *
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    20
 *
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    23
 * questions.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    24
 */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    25
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    26
package jdk.javadoc.internal.doclets.toolkit.util;
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    27
48029
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
    28
import javax.lang.model.element.ModuleElement;
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    29
import javax.lang.model.element.PackageElement;
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    30
import javax.lang.model.element.TypeElement;
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    31
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    32
/**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    33
 * Abstraction for immutable relative paths.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    34
 * Paths always use '/' as a separator, and never begin or end with '/'.
14358
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
    35
 *
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
    36
 *  <p><b>This is NOT part of any supported API.
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
    37
 *  If you write code that depends on this, you do so at your own risk.
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
    38
 *  This code and its internal interfaces are subject to change or
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
    39
 *  deletion without notice.</b>
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    40
 */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    41
public class DocPath {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    42
    private final String path;
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    43
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    44
    /** The empty path. */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    45
    public static final DocPath empty = new DocPath("");
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    46
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    47
    /** The empty path. */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    48
    public static final DocPath parent = new DocPath("..");
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    49
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    50
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    51
     * Create a path from a string.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    52
     */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    53
    public static DocPath create(String p) {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    54
        return (p == null) || p.isEmpty() ? empty : new DocPath(p);
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    55
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    56
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    57
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    58
     * Return the path for a class.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    59
     * For example, if the class is java.lang.Object,
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    60
     * the path is java/lang/Object.html.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    61
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    62
    public static DocPath forClass(Utils utils, TypeElement typeElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    63
        return (typeElement == null)
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    64
                ? empty
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    65
                : forPackage(utils.containingPackage(typeElement)).resolve(forName(utils, typeElement));
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    66
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    67
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    68
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    69
     * Return the path for the simple name of the class.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    70
     * For example, if the class is java.lang.Object,
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    71
     * the path is Object.html.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    72
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    73
    public static DocPath forName(Utils utils, TypeElement typeElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    74
        return (typeElement == null) ? empty : new DocPath(utils.getSimpleName(typeElement) + ".html");
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    75
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    76
48029
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
    77
    public static DocPath forModule(ModuleElement mdle) {
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
    78
        return mdle == null || mdle.isUnnamed()
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
    79
                ? empty
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
    80
                : DocPath.create(mdle.getQualifiedName().toString());
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
    81
    }
e9dab2492924 8185985: Html files in doc-files directories should be wrapped with standard header and footer
ksrini
parents: 47216
diff changeset
    82
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    83
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    84
     * Return the path for the package of a class.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    85
     * For example, if the class is java.lang.Object,
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    86
     * the path is java/lang.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    87
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    88
    public static DocPath forPackage(Utils utils, TypeElement typeElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    89
        return (typeElement == null) ? empty : forPackage(utils.containingPackage(typeElement));
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    90
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    91
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    92
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    93
     * Return the path for a package.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    94
     * For example, if the package is java.lang,
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    95
     * the path is java/lang.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
    96
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    97
    public static DocPath forPackage(PackageElement pkgElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    98
        return pkgElement == null || pkgElement.isUnnamed()
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
    99
                ? empty
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   100
                : DocPath.create(pkgElement.getQualifiedName().toString().replace('.', '/'));
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   101
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   102
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   103
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   104
     * Return the inverse path for a package.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   105
     * For example, if the package is java.lang,
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   106
     * the inverse path is ../...
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   107
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   108
    public static DocPath forRoot(PackageElement pkgElement) {
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   109
        String name = (pkgElement == null || pkgElement.isUnnamed())
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   110
                ? ""
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   111
                : pkgElement.getQualifiedName().toString();
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   112
        return new DocPath(name.replace('.', '/').replaceAll("[^/]+", ".."));
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   113
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   114
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   115
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   116
     * Return the relative path from one package to another.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   117
     */
35426
374342e56a56 8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents: 25874
diff changeset
   118
    public static DocPath relativePath(PackageElement from, PackageElement to) {
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   119
        return forRoot(from).resolve(forPackage(to));
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   120
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   121
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   122
    protected DocPath(String p) {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   123
        path = (p.endsWith("/") ? p.substring(0, p.length() - 1) : p);
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   124
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   125
14366
af625e568667 8001929: fix doclint errors in langtools doc comments
jjg
parents: 14358
diff changeset
   126
    /** {@inheritDoc} */
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   127
    @Override
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   128
    public boolean equals(Object other) {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   129
        return (other instanceof DocPath) && path.equals(((DocPath)other).path);
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   130
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   131
14366
af625e568667 8001929: fix doclint errors in langtools doc comments
jjg
parents: 14358
diff changeset
   132
    /** {@inheritDoc} */
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   133
    @Override
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   134
    public int hashCode() {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   135
        return path.hashCode();
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   136
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   137
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   138
    public DocPath basename() {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   139
        int sep = path.lastIndexOf("/");
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   140
        return (sep == -1) ? this : new DocPath(path.substring(sep + 1));
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   141
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   142
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   143
    public DocPath parent() {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   144
        int sep = path.lastIndexOf("/");
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   145
        return (sep == -1) ? empty : new DocPath(path.substring(0, sep));
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   146
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   147
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   148
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   149
     * Return the path formed by appending the specified string to the current path.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   150
     */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   151
    public DocPath resolve(String p) {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   152
        if (p == null || p.isEmpty())
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   153
            return this;
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   154
        if (path.isEmpty())
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   155
            return new DocPath(p);
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   156
        return new DocPath(path + "/" + p);
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   157
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   158
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   159
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   160
     * Return the path by appending the specified path to the current path.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   161
     */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   162
    public DocPath resolve(DocPath p) {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   163
        if (p == null || p.isEmpty())
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   164
            return this;
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   165
        if (path.isEmpty())
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   166
            return p;
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   167
        return new DocPath(path + "/" + p.getPath());
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   168
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   169
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   170
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   171
     * Return the inverse path for this path.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   172
     * For example, if the path is a/b/c, the inverse path is ../../..
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   173
     */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   174
    public DocPath invert() {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   175
        return new DocPath(path.replaceAll("[^/]+", ".."));
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   176
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   177
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   178
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   179
     * Return true if this path is empty.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   180
     */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   181
    public boolean isEmpty() {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   182
        return path.isEmpty();
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   183
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   184
14358
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   185
    public DocLink fragment(String fragment) {
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   186
        return new DocLink(path, null, fragment);
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   187
    }
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   188
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   189
    public DocLink query(String query) {
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   190
        return new DocLink(path, query, null);
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   191
    }
9eda9239cba0 8000416: refactor javadoc to provide and use an abstraction for relative URIs
jjg
parents: 14357
diff changeset
   192
14357
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   193
    /**
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   194
     * Return this path as a string.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   195
     */
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   196
    // This is provided instead of using toString() to help catch
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   197
    // unintended use of toString() in string concatenation sequences.
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   198
    public String getPath() {
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   199
        return path;
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   200
    }
faf9cde2817b 8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
diff changeset
   201
}