Example usage for java.net URI resolve

List of usage examples for java.net URI resolve

Introduction

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

Prototype

public URI resolve(String str) 

Source Link

Document

Constructs a new URI by parsing the given string and then resolving it against this URI.

Usage

From source file:com.cedarsoft.couchdb.CouchDatabase.java

@Nonnull
public static CouchDatabase create(@Nonnull Client client, @Nonnull URI serverUri, @Nonnull String dbName) {
    return create(client, serverUri.resolve("/" + dbName));
}

From source file:com.jtstand.swing.Main.java

public static URI resolve(String uristr, URI baseuri) {
    if (uristr.equals(".") || uristr.equals("this")) {
        return baseuri;
    }// w w w .ja  v a 2 s  .c o m
    URI uri = null;
    try {
        uri = new URI(uristr);
    } catch (URISyntaxException ex) {
        return null;
    }
    if (uri.isAbsolute()) {
        return uri;
    }
    return baseuri.resolve(uri);
}

From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UmlsCommon.LoadRRFToDB.java

private static Hashtable readMRCols(URI rrfLocation) throws MalformedURLException, IOException {
    Hashtable result = new Hashtable();
    BufferedReader reader = getReader(rrfLocation.resolve("MRCOLS.RRF"));

    String line = reader.readLine();
    while (line != null) {
        String[] vals = stringToArray(line, '|');
        String key = vals[0] + "|" + vals[6];
        result.put(key, vals[7]);/*from w w  w  . j  av a2  s.c om*/
        line = reader.readLine();
    }
    reader.close();

    return result;
}

From source file:com.vaadin.sass.testcases.scss.W3ConformanceTests.java

protected static Collection<URI> scrapeIndexForTests(String url, String regexp, int maxTests,
        Collection<URI> excludeUrls) throws Exception {

    URI baseUrl = new URI(url);
    Document doc = Jsoup.connect(url).timeout(10000).get();
    Elements elems = doc.select(String.format("a[href~=%s]", regexp));
    LinkedHashSet<URI> tests = new LinkedHashSet<URI>();
    for (Element e : elems) {
        URI testUrl = new URI(e.attr("href"));
        if (!testUrl.isAbsolute()) {
            testUrl = baseUrl.resolve(testUrl);
        }/*from w  w w . j  a va  2  s.com*/
        if (tests.size() < maxTests) {
            if (!excludeUrls.contains(testUrl)) {
                tests.add(testUrl);
            }
        } else {
            break;
        }
    }

    return tests;
}

From source file:at.bitfire.davdroid.webdav.DavRedirectStrategy.java

/**
 * Gets the destination of a redirection 
 * @return absolute URL of new location; null if not available
 *///from   w w  w  . j a v  a2s .c  o m
static URI getLocation(HttpRequest request, HttpResponse response, HttpContext context) {
    Header locationHdr = response.getFirstHeader("Location");
    if (locationHdr == null) {
        Log.e(TAG, "Received redirection without Location header, ignoring");
        return null;
    }
    try {
        URI location = URIUtils.parseURI(locationHdr.getValue(), false);

        // some servers don't return absolute URLs as required by RFC 2616
        if (!location.isAbsolute()) {
            Log.w(TAG, "Received invalid redirection to relative URL, repairing");
            URI originalURI = URIUtils.parseURI(request.getRequestLine().getUri(), false);
            if (!originalURI.isAbsolute()) {
                final HttpHost target = HttpClientContext.adapt(context).getTargetHost();
                if (target != null)
                    originalURI = org.apache.http.client.utils.URIUtilsHC4.rewriteURI(originalURI, target);
                else
                    return null;
            }
            return originalURI.resolve(location);
        }
        return location;
    } catch (URISyntaxException e) {
        Log.e(TAG, "Received redirection from/to invalid URI, ignoring", e);
    }
    return null;
}

From source file:org.apache.taverna.robundle.Bundles.java

public static Path uriToBundlePath(Bundle bundle, URI uri) {
    URI rootUri = bundle.getRoot().toUri();
    uri = relativizeFromBase(uri, rootUri);
    if (uri.isAbsolute() || uri.getFragment() != null)
        return null;
    return bundle.getFileSystem().provider().getPath(rootUri.resolve(uri));
}

From source file:URIUtils.java

/**
 * Resolves a URI reference against a base URI. Work-around for bug in
 * java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)
 *
 * @param baseURI the base URI/*from  ww  w  . j a v a  2 s  .  c o  m*/
 * @param reference the URI reference
 * @return the resulting URI
 */
public static URI resolve(final URI baseURI, URI reference) {
    if (baseURI == null) {
        throw new IllegalArgumentException("Base URI may nor be null");
    }
    if (reference == null) {
        throw new IllegalArgumentException("Reference URI may nor be null");
    }
    boolean emptyReference = reference.toString().length() == 0;
    if (emptyReference) {
        reference = URI.create("#");
    }
    URI resolved = baseURI.resolve(reference);
    if (emptyReference) {
        String resolvedString = resolved.toString();
        resolved = URI.create(resolvedString.substring(0, resolvedString.indexOf('#')));
    }
    return resolved;
}

From source file:com.googlesource.gerrit.plugins.supermanifest.JiriManifestParser.java

public static JiriProjects getProjects(GerritRemoteReader reader, String repoKey, String ref, String manifest)
        throws ConfigInvalidException, IOException {

    try (RepoMap<String, Repository> repoMap = new RepoMap<>()) {
        repoMap.put(repoKey, reader.openRepository(repoKey));
        Queue<ManifestItem> q = new LinkedList<>();
        q.add(new ManifestItem(repoKey, manifest, ref, "", false));
        HashMap<String, HashSet<String>> processedRepoFiles = new HashMap<>();
        HashMap<String, JiriProjects.Project> projectMap = new HashMap<>();

        while (q.size() != 0) {
            ManifestItem mi = q.remove();
            Repository repo = repoMap.get(mi.repoKey);
            if (repo == null) {
                repo = reader.openRepository(mi.repoKey);
                repoMap.put(mi.repoKey, repo);
            }//from   w  ww .  j  a  va2  s  .  co m
            HashSet<String> processedFiles = processedRepoFiles.get(mi.repoKey);
            if (processedFiles == null) {
                processedFiles = new HashSet<String>();
                processedRepoFiles.put(mi.repoKey, processedFiles);
            }
            if (processedFiles.contains(mi.manifest)) {
                continue;
            }
            processedFiles.add(mi.manifest);
            JiriManifest m;
            try {
                m = parseManifest(repo, mi.ref, mi.manifest);
            } catch (JAXBException | XMLStreamException e) {
                throw new ConfigInvalidException("XML parse error", e);
            }

            for (JiriProjects.Project project : m.projects.getProjects()) {
                project.fillDefault();
                if (mi.revisionPinned && project.Key().equals(mi.projectKey)) {
                    project.setRevision(mi.ref);
                }
                if (projectMap.containsKey(project.Key())) {
                    if (!projectMap.get(project.Key()).equals(project))
                        throw new ConfigInvalidException(String.format(
                                "Duplicate conflicting project %s in manifest %s\n%s\n%s", project.Key(),
                                mi.manifest, project.toString(), projectMap.get(project.Key()).toString()));
                } else {
                    projectMap.put(project.Key(), project);
                }
            }

            URI parentURI;
            try {
                parentURI = new URI(mi.manifest);
            } catch (URISyntaxException e) {
                throw new ConfigInvalidException("Invalid parent URI", e);
            }
            for (JiriManifest.LocalImport l : m.imports.getLocalImports()) {
                ManifestItem tw = new ManifestItem(mi.repoKey, parentURI.resolve(l.getFile()).getPath(), mi.ref,
                        mi.projectKey, mi.revisionPinned);
                q.add(tw);
            }

            for (JiriManifest.Import i : m.imports.getImports()) {
                i.fillDefault();
                URI uri;
                try {
                    uri = new URI(i.getRemote());
                } catch (URISyntaxException e) {
                    throw new ConfigInvalidException("Invalid URI", e);
                }
                String iRepoKey = new Project.NameKey(StringUtils.strip(uri.getPath(), "/")).toString();
                String iRef = i.getRevision();
                boolean revisionPinned = true;
                if (iRef.isEmpty()) {
                    iRef = REFS_HEADS + i.getRemotebranch();
                    revisionPinned = false;
                }

                ManifestItem tmi = new ManifestItem(iRepoKey, i.getManifest(), iRef, i.Key(), revisionPinned);
                q.add(tmi);
            }
        }
        return new JiriProjects(projectMap.values().toArray(new JiriProjects.Project[0]));
    }
}

From source file:org.tinygroup.template.rumtime.TemplateUtil.java

/**
 * ???/*  w  ww. jav  a  2s  .c  om*/
 *
 * @param currentPath
 * @param newPath
 * @return
 */
public static String getPath(String currentPath, String newPath) {
    String path = newPath;
    URI uri = URI.create(currentPath);
    path = path.replaceAll("[\\\\]", "/");
    URI newUri = uri.resolve(path);
    return newUri.getPath();
}

From source file:org.opencb.opencga.storage.core.variant.VariantStorageBaseTest.java

public static URI newOutputUri(int extraCalls, URI outputUri) throws IOException {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    // stackTrace[0] = "Thread.currentThread"
    // stackTrace[1] = "newOutputUri"
    // stackTrace[2] =  caller method
    String testName = stackTrace[2 + extraCalls].getMethodName();
    int c = 0;//w w  w. j a  v  a 2 s.  c  om
    URI finalOutputUri = outputUri.resolve("test_" + testName + "/");
    while (Paths.get(finalOutputUri).toFile().exists()) {
        finalOutputUri = outputUri.resolve("test_" + testName + "-" + ++c + "/");
    }
    Files.createDirectory(Paths.get(finalOutputUri));
    return finalOutputUri;
}