Example usage for java.net URI isAbsolute

List of usage examples for java.net URI isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Tells whether or not this URI is absolute.

Usage

From source file:org.killbill.billing.plugin.util.http.HttpClient.java

private String getUrl(final String location, final String uri) throws URISyntaxException {
    final URI u = new URI(uri);
    if (u.isAbsolute()) {
        return uri;
    } else {/*from  w w w  .j  a v a2 s. c om*/
        return String.format("%s%s", location, uri);
    }
}

From source file:de.fhg.iais.cortex.services.ingest.worker.BinaryResolutionWorker.java

private boolean needsRewrite(String href) {
    if (Strings.isNullOrEmpty(href)) {
        return false;
    }/*from   w  w w. j av  a2s.  c  o m*/
    try {
        URI uri = new URI(href);
        return !uri.isAbsolute();
    } catch (URISyntaxException e) {
        return true;
    }
}

From source file:com.github.fge.jsonschema.core.load.URIManager.java

/**
 * Get the content at a given URI as a {@link JsonNode}
 *
 * @param uri the URI//from w w  w  .jav  a  2  s  . c  o  m
 * @return the content
 * @throws NullPointerException provided URI is null
 * @throws ProcessingException scheme is not registered, failed to get
 * content, or content is not JSON
 */
public JsonNode getContent(final URI uri) throws ProcessingException {
    BUNDLE.checkNotNull(uri, "jsonRef.nullURI");

    if (!uri.isAbsolute())
        throw new ProcessingException(new ProcessingMessage()
                .setMessage(BUNDLE.getMessage("refProcessing.uriNotAbsolute")).put("uri", uri));

    final String scheme = uri.getScheme();

    final URIDownloader downloader = downloaders.get(scheme);

    if (downloader == null)
        throw new ProcessingException(
                new ProcessingMessage().setMessage(BUNDLE.getMessage("refProcessing.unhandledScheme"))
                        .putArgument("scheme", scheme).putArgument("uri", uri));

    final Closer closer = Closer.create();
    final InputStream in;

    try {
        in = closer.register(downloader.fetch(uri));
        return reader.fromInputStream(in);
    } catch (JsonMappingException e) {
        throw new ProcessingException(
                new ProcessingMessage().setMessage(e.getOriginalMessage()).put("uri", uri));
    } catch (JsonParseException e) {
        throw new ProcessingException(
                new ProcessingMessage().setMessage(BUNDLE.getMessage("uriManager.uriNotJson"))
                        .putArgument("uri", uri).put("parsingMessage", e.getOriginalMessage()));
    } catch (IOException e) {
        throw new ProcessingException(
                new ProcessingMessage().setMessage(BUNDLE.getMessage("uriManager.uriIOError"))
                        .putArgument("uri", uri).put("exceptionMessage", e.getMessage()));
    } finally {
        try {
            closer.close();
        } catch (IOException ignored) {
            throw new IllegalStateException();
        }
    }
}

From source file:it.unimi.di.big.mg4j.tool.URLMPHVirtualDocumentResolver.java

@Override
public long resolve(final CharSequence virtualDocumentSpec) {
    try {/*  w w w.j av a 2s  .  co m*/
        URI virtualURI = URI.create(virtualDocumentSpec.toString());
        if (!virtualURI.isAbsolute()) {
            if (documentURI == null)
                return -1;
            virtualURI = documentURI.resolve(virtualURI);
        }

        return url2DocumentPointer.getLong(virtualURI.toString());
    } catch (Exception e) {
        return -1;
    }
}

From source file:org.geometerplus.android.fbreader.network.ActivityNetworkContext.java

private String url(URI base, Map<String, String> params, String key) {
    final String path = params.get(key);
    if (path == null) {
        return null;
    }//from ww w.j ava  2  s  .  co  m
    try {
        final URI relative = new URI(path);
        return relative.isAbsolute() ? null : base.resolve(relative).toString();
    } catch (URISyntaxException e) {
        return null;
    }
}

From source file:com.qwazr.extractor.UriInfoImpl.java

public UriInfoImpl(final URI base, final URI child) {
    baseUri = base;//w  ww .j av  a2  s  . co m
    absoluteUri = child.isAbsolute() ? child : base.resolve(child);
    relativeUri = base.relativize(child);
}

From source file:bpelg.packaging.ode.util.BgSchemaCollection.java

public void read(String location, URI baseUri) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Reading schema at '" + location + "' with baseUri '" + baseUri + "'");
    }//from   www  .j  av a 2  s. c  o m
    if (baseUri == null) {
        baseUri = this.baseUri;
    }
    URI loc;
    if (baseUri != null) {
        loc = resolve(baseUri, location);
        if (!loc.isAbsolute()) {
            throw new IllegalArgumentException(
                    "Unable to resolve '" + loc.toString() + "' relative to '" + baseUri + "'");
        }
    } else {
        loc = new URI(location);
        if (!loc.isAbsolute()) {
            throw new IllegalArgumentException(
                    "Location '" + loc.toString() + "' is not absolute and no baseUri specified");
        }
    }
    InputSource inputSource = new InputSource();
    inputSource.setByteStream(loc.toURL().openStream());
    inputSource.setSystemId(loc.toString());
    read(inputSource);
}

From source file:com.anrisoftware.sscontrol.parser.AppParser.java

private URI parseURI(String s) {
    try {/*w ww .j a va2s .c om*/
        URI uri = new URI(s);
        return uri.isAbsolute() ? uri : uriFromFile(s);
    } catch (URISyntaxException e) {
        return uriFromFile(s);
    }
}

From source file:org.apache.taverna.robundle.manifest.PathMetadata.java

public void setUri(URI uri) {
    this.uri = uri;
    if (!uri.isAbsolute()) {
        // TODO: How to create a Path without knowing the root?
        // file = uri;
        // this.uri = null;
    }/*w w  w  .ja v  a  2  s.  co  m*/
}

From source file:com.mgmtp.perfload.core.client.web.request.HttpRequestHandler.java

/**
 * Prepends the current target's base URL to the URI if it is relative.
 * /*from   w w  w . ja v a2 s . c  om*/
 * @param uriString
 *            the uri
 * @return the final URI used to make the request
 * @throws URISyntaxException
 *             if the given string violates RFC 2396
 */
protected URI createAbsoluteURI(final String uriString) throws URISyntaxException {
    URI uri = new URI(uriString);
    if (!uri.isAbsolute()) {
        String targetHost = targetHostProvider.get();
        if (!targetHost.endsWith("/") && !uriString.startsWith("/")) {
            targetHost += "/";
        }
        uri = new URI(targetHost + uriString);
    }
    return uri;
}