1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
58
59 /**
60 * Calculate the parent URI path of the given URI path.
61 *
62 * @param uriPath the uriPath (as returned by java.net.URI#getPath()
63 * @return the parent URI path of the given URI path
64 */
65 public static String getParentUriPath(String uriPath) {
66 int idx = uriPath.lastIndexOf('/');
67
68 if (uriPath.endsWith("/")) {
69 uriPath = uriPath.substring(0,idx); // trim trailing slash
70 idx = uriPath.lastIndexOf('/'); // move idx to parent context
71 }
72
73 return uriPath.substring(0, idx)+"/";
74 }
75
76 /**
77 * Calculate the normalized form of the given uriPath.
78 *
79 * For example:
80 * /a/b/c/ -> /a/b/c/
81 * /a/b/c -> /a/b/
82 * /a/ -> /a/
83 * /a -> /
84 *
85 * @param uriPath path of a URI (as returned by java.net.URI#getPath()
86 * @return the normalized uri path
87 */
88 public static String normalizeUriPath(String uriPath) {
89 if (uriPath.endsWith("/"))
90 return uriPath;
91
92 // the uri path should always have at least a leading slash,
93 // so no need to make sure that ( idx == -1 )
94 int idx = uriPath.lastIndexOf('/');
95 return uriPath.substring(0, idx+1);
96 }
97
98 /**
99 * determine if two Strings are equal ignoring case allowing null values
100 *
101 * @param s string 1
102 * @param t string 2
103 * @return true iff the given strings are equal ignoring case, false if they aren't
|
1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
58
59 /**
60 * Calculate the parent URI path of the given URI path.
61 *
62 * @param uriPath the uriPath (as returned by java.net.URI#getPath()
63 * @return the parent URI path of the given URI path
64 */
65 public static String getParentUriPath(String uriPath) {
66 int idx = uriPath.lastIndexOf('/');
67
68 if (uriPath.endsWith("/")) {
69 uriPath = uriPath.substring(0,idx); // trim trailing slash
70 idx = uriPath.lastIndexOf('/'); // move idx to parent context
71 }
72
73 return uriPath.substring(0, idx)+"/";
74 }
75
76 /**
77 * Calculate the normalized form of the given uriPath.
78 * <p>
79 * For example: <pre>{@code
80 * /a/b/c/ -> /a/b/c/
81 * /a/b/c -> /a/b/
82 * /a/ -> /a/
83 * /a -> /
84 * }</pre>
85 *
86 * @param uriPath path of a URI (as returned by java.net.URI#getPath()
87 * @return the normalized uri path
88 */
89 public static String normalizeUriPath(String uriPath) {
90 if (uriPath.endsWith("/"))
91 return uriPath;
92
93 // the uri path should always have at least a leading slash,
94 // so no need to make sure that ( idx == -1 )
95 int idx = uriPath.lastIndexOf('/');
96 return uriPath.substring(0, idx+1);
97 }
98
99 /**
100 * determine if two Strings are equal ignoring case allowing null values
101 *
102 * @param s string 1
103 * @param t string 2
104 * @return true iff the given strings are equal ignoring case, false if they aren't
|