Example usage for java.net URI normalize

List of usage examples for java.net URI normalize

Introduction

In this page you can find the example usage for java.net URI normalize.

Prototype

public URI normalize() 

Source Link

Document

Normalizes this URI's path.

Usage

From source file:Main.java

public static void main(String[] args) throws URISyntaxException {
    URI uri = new URI("http://java2s.com/./");
    System.out.println("Normalized URI = " + uri.normalize());
}

From source file:Main.java

public static void printURIDetails(URI uri) {
    System.out.println("URI:" + uri);
    System.out.println("Normalized:" + uri.normalize());
    String parts = "[Scheme=" + uri.getScheme() + ", Authority=" + uri.getAuthority() + ", Path="
            + uri.getPath() + ", Query:" + uri.getQuery() + ", Fragment:" + uri.getFragment() + "]";
    System.out.println(parts);//  w w w  .j a  v a2  s.c o m
    System.out.println();
}

From source file:org.cagrid.identifiers.namingauthority.util.SecurityUtil.java

public static boolean isSystemIdentifier(URI localIdentifier) {
    return localIdentifier.normalize().toString().equals(LOCAL_SYSTEM_IDENTIFIER.normalize().toString());
}

From source file:at.beris.virtualfile.util.UrlUtils.java

public static URL normalizeUrl(URL url) throws IOException {
    URI uri = URI.create(url.toString());
    return uri.normalize().toURL();
}

From source file:com.jaeksoft.searchlib.util.LinkUtils.java

public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList,
        boolean removeFragment) {

    if (href == null)
        return null;
    href = href.trim();/*from  w w w . j a  v a2  s  .c  om*/
    if (href.length() == 0)
        return null;

    String fragment = null;
    try {
        URI u = URIUtils.resolve(currentURL.toURI(), href);
        href = u.toString();
        href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList);
        URI uri = URI.create(href);
        uri = uri.normalize();

        String p = uri.getPath();
        if (p != null)
            if (p.contains("/./") || p.contains("/../"))
                return null;

        if (!removeFragment)
            fragment = uri.getRawFragment();

        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(),
                uri.getQuery(), fragment).normalize().toURL();
    } catch (MalformedURLException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (URISyntaxException e) {
        Logging.info(e.getMessage());
        return null;
    } catch (IllegalArgumentException e) {
        Logging.info(e.getMessage());
        return null;
    }
}

From source file:pt.webdetails.cte.editor.ace.ProcessedHtmlPage.java

private static String normalizeUri(String path) {
    try {// w w w  .  j  av  a 2  s .c  om
        URI uri = new URI(path);
        return uri.normalize().getPath();
    } catch (URISyntaxException e) {
        log.error("normalizeUri: cannot process path " + path, e);
        return path;
    }
}

From source file:Main.java

/**
 * Create URL using base URI./*w w  w .ja v  a 2s.c  om*/
 * 
 * @param url a URL string.
 * @param baseURI a base url string to assist in creating a URL.
 * @return newly created URL.
 * @throws MalformedURLException if a malformed URL has occurred.
 */
public static URL createURL(String url, String baseURI) throws MalformedURLException {
    URL returnURL = null;
    URI uri = null;
    try {
        returnURL = new URL(url);
        uri = new URI(url);
        uri = uri.normalize();
        returnURL = new URL(uri.toString());
    }

    catch (Exception mue) {
        int i = baseURI.lastIndexOf('/');
        int j = baseURI.lastIndexOf('\\');
        if (j > i)
            i = j;
        try {
            uri = new URI(baseURI.substring(0, i + 1) + url);
            uri = uri.normalize();
            returnURL = uri.toURL();
        } catch (Exception e) {
            return new URL(baseURI.substring(0, i + 1) + url);
        }
    }
    return returnURL;
}

From source file:org.akubraproject.fs.FSBlob.java

static URI validateId(URI blobId) throws UnsupportedIdException {
    if (blobId == null)
        throw new NullPointerException("Id cannot be null");
    if (!blobId.getScheme().equalsIgnoreCase(scheme))
        throw new UnsupportedIdException(blobId, "Id must be in " + scheme + " scheme");
    String path = blobId.getRawSchemeSpecificPart();
    if (path.startsWith("/"))
        throw new UnsupportedIdException(blobId, "Id must specify a relative path");
    try {/*from  www.j a va2  s.c o m*/
        // insert a '/' so java.net.URI normalization works
        URI tmp = new URI(scheme + ":/" + path);
        String nPath = tmp.normalize().getRawSchemeSpecificPart().substring(1);
        if (nPath.equals("..") || nPath.startsWith("../"))
            throw new UnsupportedIdException(blobId, "Id cannot be outside top-level directory");
        if (nPath.endsWith("/"))
            throw new UnsupportedIdException(blobId, "Id cannot specify a directory");
        return new URI(scheme + ":" + nPath);
    } catch (URISyntaxException wontHappen) {
        throw new Error(wontHappen);
    }
}

From source file:eu.eubrazilcc.lvl.core.util.UrlUtils.java

/**
 * Gets the path part of an URI.// ww  w .j  av a 2s. co  m
 * @param uri - input URI
 * @return the path part of the specified URI or an empty string if one does not exist.
 * @throws IllegalArgumentException If a malformed URI occurs.
 */
public static String getPath(final URI uri) {
    checkArgument(uri != null, "Uninitialized URI");
    try {
        final URI nUri = uri.normalize();
        final URL url = nUri.isAbsolute() ? nUri.toURL()
                : new URL(new URL("http://example.org/"), nUri.getPath());
        return url.getPath();
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Malformed URI", e);
    }
}

From source file:pt.webdetails.cpf.Util.java

public static String normalizeUri(String path) {
    try {/* w w  w.ja  va  2s  .  com*/
        URI uri = new URI(path);
        return uri.normalize().getPath();
    } catch (URISyntaxException e) {
        logger.error("normalizeUri: cannot process path " + path, e);
        return path;
    }
}