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.eclipse.winery.common.Util.java

public static boolean isRelativeURI(String uri) {
    URI u;
    try {//from w w  w .  j av a 2  s . c o m
        u = new URI(uri);
    } catch (URISyntaxException e) {
        Util.logger.debug(e.getMessage(), e);
        // fallback
        return false;
    }
    return !u.isAbsolute();
}

From source file:com.datatorrent.stram.client.StramClientUtils.java

public static Path getDTDFSRootDir(FileSystem fs, Configuration conf) {
    String dfsRootDir = conf.get(DT_DFS_ROOT_DIR);
    if (StringUtils.isBlank(dfsRootDir)) {
        return new Path(fs.getHomeDirectory(), "datatorrent");
    } else {//from www  .  j ava2  s  .  co  m
        try {
            if (dfsRootDir.contains(DT_DFS_USER_NAME)) {
                dfsRootDir = dfsRootDir.replace(DT_DFS_USER_NAME,
                        UserGroupInformation.getLoginUser().getShortUserName());
                conf.set(DT_DFS_ROOT_DIR, dfsRootDir);
            }
            URI uri = new URI(dfsRootDir);
            if (uri.isAbsolute()) {
                return new Path(uri);
            }
        } catch (IOException ex) {
            LOG.warn("Error getting user login name {}", dfsRootDir, ex);
        } catch (URISyntaxException ex) {
            LOG.warn("{} is not a valid URI. Using the default filesystem to construct the path", dfsRootDir,
                    ex);
        }
        return new Path(fs.getUri().getScheme(), fs.getUri().getAuthority(), dfsRootDir);
    }
}

From source file:com.sworddance.util.UriFactoryImpl.java

/**
 * Converts the given href value to an absolute uri.
 * The html document's baseHtmlElement and
 * baseUri are used in order to derive the
 * correct location of the resource./*from  w  w w.j  a va  2 s  .c  o  m*/
 *
 * @param href accepts null
 * @param baseUri
 * @param baseHtmlElement
 * @return the URI
 *
 * @throws IllegalArgumentException if the uri resolution encounters
 * {@link URI#create(String) problems}.
 */
public static URI absolutize(String href, URI baseUri, String baseHtmlElement) {
    if (href == null) {
        href = "";
    }
    URI uri = createUri(href);
    if (uri != null && uri.isAbsolute()) {
        return uri;
    }

    String start = absolutize(baseUri, baseHtmlElement);
    if (!start.endsWith(PATH_SEPARATOR)) {
        start += PATH_SEPARATOR;
    }
    URI startUri = createUri(start);
    if (uri != null) {
        return startUri.resolve(uri);
    } else {
        return startUri;
    }
}

From source file:com.discovery.darchrow.net.URIUtil.java

/**
 * ?path??.//from  ww  w . ja va  2 s .  c  o  m
 *
 * @param path
 *            ?
 * @return ??, <b>true </b>,? <b>false </b>
 */
public static boolean isAbsolutePath(String path) {
    URI uri = getURI(path);

    if (null == uri) {
        return false;
    }
    return uri.isAbsolute();
}

From source file:com.microsoft.tfs.core.util.URIUtils.java

/**
 * <p>/*from w w  w . j av  a2 s.com*/
 * Resolves the specified child {@link URI} against the specified
 * {@link URI}, returning a {@link URI} as the result.
 * </p>
 *
 * <p>
 * This method behaves differently than calling {@link URI#resolve(URI)}.
 * This method first uses the {@link #ensurePathHasTrailingSlash(URI)}
 * method to ensure that the specified parent {@link URI}'s path has a
 * trailing slash. See the documentation of
 * {@link #ensurePathHasTrailingSlash(URI)} method for a reason why this is
 * necessary.
 * </p>
 *
 * @param parent
 *        a base {@link URI} to resolve against (must not be
 *        <code>null</code>)
 * @param child
 *        a relative path to resolve (must not be <code>null</code>)
 * @return a new {@link URI} as described above (never <code>null</code>)
 */
public static URI resolve(URI parent, final URI child) {
    Check.notNull(parent, "parent"); //$NON-NLS-1$
    Check.notNull(child, "child"); //$NON-NLS-1$

    if (!child.isAbsolute() && !parent.isOpaque()) {
        parent = ensurePathHasTrailingSlash(parent);
    }

    return parent.resolve(child);
}

From source file:com.sworddance.util.UriFactoryImpl.java

/**
 * @param uri/*  ww w  .  j a va2 s. c o  m*/
 * @return true if uri is relative ( so scheme not supplied ), or http/https protocol.
 */
public static boolean isWebUri(URI uri) {
    if (uri == null) {
        return false;
    } else {
        return !uri.isAbsolute() || isHttpProtocol(uri);
    }
}

From source file:org.apache.http.impl.client.AbstractStatisticsGatheringHttpClient.java

private static HttpHost determineTarget(HttpUriRequest request) throws ClientProtocolException {
    // A null target may be acceptable if there is a default target.
    // Otherwise, the null target is detected in the director.
    HttpHost target = null;//from www .j  a va2  s . co  m

    URI requestURI = request.getURI();
    if (requestURI.isAbsolute()) {
        target = URIUtils.extractHost(requestURI);
        if (target == null) {
            throw new ClientProtocolException("URI does not specify a valid host name: " + requestURI);
        }
    }
    return target;
}

From source file:com.sworddance.util.UriFactoryImpl.java

/**
 *
 * @param baseUri//  ww w.ja  va 2  s  .  c om
 * @param relativeUriString may be an absolute uri when converted to a URI
 * @return absolute Uri
 */
public static String absolutize(URI baseUri, String relativeUriString) {
    URI relativeUri = UriFactoryImpl.createUri(relativeUriString);
    if (relativeUri != null && relativeUri.isAbsolute()) {
        return relativeUri.toString();
    }

    notNull(baseUri, "uri should not be null");
    if (relativeUriString == null) {
        ApplicationIllegalArgumentException.valid(baseUri.isAbsolute(), baseUri,
                ": uri must be absolute because there is no relativeUriString.");
        return baseUri.resolve(".").toString();
    }
    return baseUri.resolve(relativeUri).toString();
}

From source file:org.apache.synapse.config.SynapseConfigUtils.java

public static String resolveRelativeURI(String parentLocation, String relativeLocation) {

    if (relativeLocation == null) {
        throw new IllegalArgumentException("Import URI cannot be null");
    }/* w w w.j  ava2s .  c  o  m*/

    if (log.isDebugEnabled()) {
        log.debug("Resolving import URI ' " + parentLocation + " '  " + "against base URI ' " + relativeLocation
                + " '  ");
    }

    URI importUri = null;
    try {
        importUri = new URI(relativeLocation);
        if (importUri.isAbsolute()) {
            return importUri.toString();
        }
    } catch (URISyntaxException e) {
        handleException("Invalid URI : " + relativeLocation, e);
    }

    if (parentLocation == null) {
        assert importUri != null;
        return importUri.toString();
    } else {
        // if the import-uri is absolute
        if (relativeLocation.startsWith("/") || relativeLocation.startsWith("\\")) {
            if (importUri != null && !importUri.isAbsolute()) {
                try {
                    importUri = new URI("file:" + relativeLocation);
                    return importUri.toString();
                } catch (URISyntaxException e) {
                    handleException("Invalid URI ' " + importUri.getPath() + " '", e);
                }
            }
        } else {
            int index = parentLocation.lastIndexOf("/");
            if (index == -1) {
                index = parentLocation.lastIndexOf("\\");
            }
            if (index != -1) {
                String basepath = parentLocation.substring(0, index + 1);
                String resolvedPath = basepath + relativeLocation;
                try {
                    URI resolvedUri = new URI(resolvedPath);
                    if (!resolvedUri.isAbsolute()) {
                        resolvedUri = new URI("file:" + resolvedPath);
                    }
                    return resolvedUri.toString();
                } catch (URISyntaxException e) {
                    handleException("Invalid URI ' " + resolvedPath + " '", e);
                }
            } else {
                assert importUri != null;
                return importUri.toString();
            }
        }
    }
    return null;
}

From source file:eu.asterics.mw.services.ResourceRegistry.java

/**
 * Checks if the given uri points to a subpath of the given baseURI URI. 
 * @param baseURI// ww  w .java 2  s .c  om
 * @param toTest
 * @return
 */
public static boolean isSubURI(URI baseURI, URI toTest) {
    URI relativeURI = baseURI.normalize().relativize(toTest.normalize());
    return !relativeURI.isAbsolute();
}