Java URI Normalize normalizeURIPath(String uri)

Here you can find the source of normalizeURIPath(String uri)

Description

normalize URI Path

License

Open Source License

Declaration

public static String normalizeURIPath(String uri) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    public static String normalizeURIPath(String uri) {
        if (uri.indexOf('%') < 0 && !uri.startsWith("./") && !uri.startsWith("../") && !uri.endsWith("/.")
                && !uri.endsWith("/..") && uri.indexOf("/../") < 0 && uri.indexOf("/./") < 0
                && uri.indexOf("//") < 0) {
            // Nothing %-encoded, and no special path elements
            return uri;
        }// ww w. j  av  a 2s . co m
        try {
            uri = new URI(uri).normalize().getPath();
        } catch (URISyntaxException e) {
            throw (IllegalArgumentException) new IllegalArgumentException("Malformed URI [" + uri + "]")
                    .initCause(e);
        }
        if (uri.equals("")) {
            uri = "/";
        } else if (!uri.equals("/") && uri.endsWith("/")) {
            uri = uri.substring(0, uri.length() - 1);
        }
        return uri;
    }
}

Related

  1. normalizedUri(URI uri)
  2. normalizeGitRepoLocation(URI location)
  3. normalizeLink(String link, URI parent, boolean removeParams)
  4. normalizeURI(final URI uri)
  5. normalizeURI(String uri)
  6. normalizeUriPath(String uriPath)