Java URI to Relative URI resolveFileUri(String fullPageURI, File rootPath)

Here you can find the source of resolveFileUri(String fullPageURI, File rootPath)

Description

resolve File Uri

License

Open Source License

Declaration

public static File resolveFileUri(String fullPageURI, File rootPath) 

Method Source Code


//package com.java2s;
// Released under the terms of the CPL Common Public License version 1.0.

import java.io.File;
import java.net.URI;

public class Main {
    public static File resolveFileUri(String fullPageURI, File rootPath) {
        URI uri = URI.create(fullPageURI);
        try {/*from   w  ww. ja  v  a2 s. c  o  m*/
            return new File(uri);
        } catch (IllegalArgumentException e) {
            if (!"file".equals(uri.getScheme()) || rootPath == null) {
                throw e;
            }
            // "URI has an authority component" (file://something) or "URI is not hierarchical" (file:something)
            // As a fallback, resolve as a relative URI
            URI rootUri = rootPath.toURI();
            uri = rootUri.resolve(uri.getSchemeSpecificPart().replaceFirst("^/+", ""));
            return new File(uri);
        }
    }
}

Related

  1. resolve(URI baseURI, String reference)
  2. resolveAbsoluteURI(final URI relativeURI)
  3. resolveFile(final URI relativeURI)
  4. resolveFileName(URI uri)
  5. resolveFileNameNoExt(URI uri)
  6. resolvePartUri(URI sourcePartUri, URI targetUri)
  7. resolvePath(URI root, String subPath)
  8. resolvePort(URI uri)
  9. resolveReferenceStartingWithQueryString(final URI baseURI, final URI reference)