Here you can find the source of normalizeURI(final URI uri)
Parameter | Description |
---|---|
uri | the server URI |
public static URI normalizeURI(final URI uri)
//package com.java2s; // Licensed under the MIT license. See License.txt in the repository root. import java.net.URI; import java.net.URISyntaxException; import java.util.Locale; public class Main { /**/* w w w . j a v a 2 s .com*/ * Canonicalizes the URI into "TFS format". This function preserves the * given case on the URI, and is not suitable for serialization or sharing * with Visual Studio (which lowercases URIs.) * * @param uri * the server URI * @return the server URI, canonicalized */ public static URI normalizeURI(final URI uri) { return normalizeURI(uri, false); } /** * Canonicalizes the URI into TFS format. * * @param uri * the server URI * @param lowercase * <code>true</code> to flatten the URI into lowercase, * <code>false</code> to preserve case * @return the server URI, canonicalized */ public static URI normalizeURI(final URI uri, final boolean lowercase) { if (uri == null) { return null; } // Convert null or empty path to "/" String pathPart = (uri.getPath() == null || uri.getPath().length() == 0) ? "/" : uri.getPath(); //$NON-NLS-1$ // Remove trailing slash if there is more than one character while (pathPart.length() > 1 && pathPart.endsWith("/")) //$NON-NLS-1$ { pathPart = pathPart.substring(0, pathPart.length() - 1); } /* Always lowercase scheme for sanity. */ final String scheme = (uri.getScheme() == null) ? null : uri.getScheme().toLowerCase(Locale.ENGLISH); String host = uri.getHost(); if (lowercase) { pathPart = pathPart.toLowerCase(Locale.ENGLISH); host = (host == null) ? null : host.toLowerCase(Locale.ENGLISH); } try { // Use null query and fragment as these are not important for TFS // URIs. return new URI(scheme, uri.getUserInfo(), host, uri.getPort(), pathPart, null, null); } catch (final URISyntaxException e) { throw new RuntimeException(e); } } }