Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

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

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

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

/**
 * TODO need to figure out what parts of WebLocationImpl belong here.
 * @param uri//  w ww . jav  a  2 s  . co  m
 * @return uri
 */
public static URI getNormalizedUri(URI uri) {
    try {
        String path = uri.getPath();

        // see WebLocationImpl ( this implementation here may not be correct )
        return new URI(uri.getScheme(), uri.getHost(), path == null ? PATH_SEPARATOR : PATH_SEPARATOR + path,
                uri.getQuery());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:org.springsource.ide.eclipse.commons.core.SpringCoreUtils.java

public static URI getResourceURI(IResource resource) {
    if (resource != null) {
        URI uri = resource.getRawLocationURI();
        if (uri == null) {
            uri = resource.getLocationURI();
        }//from  w  w w. j  av a2 s .com
        if (uri != null) {
            String scheme = uri.getScheme();
            if (FILE_SCHEME.equalsIgnoreCase(scheme)) {
                return uri;
            } else if (SOURCE_CONTROL_SCHEME.equals(scheme)) {
                // special case of Rational Team Concert
                IPath path = resource.getLocation();
                File file = path.toFile();
                if (file.exists()) {
                    return file.toURI();
                }
            } else {
                IPathVariableManager variableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
                return variableManager.resolveURI(uri);
            }
        }
    }
    return null;
}

From source file:net.rim.ejde.internal.ui.wizards.BasicBlackBerryProjectWizardPageTwo.java

protected static URI getRealLocation(String projectName, URI location) {
    if (location == null) { // inside workspace
        try {/*from   ww w .j ava 2 s. c  o  m*/
            URI rootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocationURI();

            location = new URI(rootLocation.getScheme(), null,
                    Path.fromPortableString(rootLocation.getPath()).append(projectName).toString(), null);
        } catch (URISyntaxException e) {
            Assert.isTrue(false, "Can't happen"); //$NON-NLS-1$
        }
    }
    return location;
}

From source file:com.vmware.identity.idm.server.ServerUtils.java

/**
 * Checks the connectivity to an identity provider
 *
 * @param providerUri Location of identity provider. non-null non-empty, required
 * @param userName    Login identifier. non-null, required
 * @param pwd         Password    non-null non-empty, required
 * @param certVerifierCallback Callback called to validate SSL certificates
 * @return connection:  non-null//from   w w  w  . ja v  a 2  s  .  c o m
 * @throws IDMLoginException. If one or more of the input argument is illegal.
 *                                 Or URI syntax is incorrect.
 * @throws Exception     if no connection
 * @throws IllegalArgumentException  one or more input are empty
 */
public static ILdapConnectionEx getLdapConnectionByURIs(Collection<URI> uris, String userName, String password,
        AuthenticationType authType, boolean useGcPort,
        LdapCertificateValidationSettings certValidationsettings) throws Exception {
    ValidateUtil.validateNotEmpty(uris, "uris");

    // NB: not checking whether the port is Kerberos port 88.

    ILdapConnectionEx result = null;
    Exception latestEx = null;
    for (URI uri : uris) {
        if (!DirectoryStoreProtocol.isProtocolSupported(uri.getScheme())) {
            logger.warn(String.format("protocol scheme for the specified URI is not supported: [%s]",
                    uri.toString()));
            continue; //skip unsupported protocol
        }

        logger.trace("start creating connection {}", uri);
        try {
            result = getLdapConnection(uri, userName, password, authType, useGcPort, certValidationsettings);
            if (null != result) {
                logger.trace("done creating connection");

                return result; //done
            }
        } catch (Exception e) { //log an error, pin down the latest and continue
            latestEx = e;
            logger.error("cannot establish connection with uri: {}", uri);
        }
    }

    assert (result == null);
    if (latestEx != null) {
        throw latestEx; // could not get connection from any of them
    }
    return null;
}

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

public static Path toPath(URI uri) throws URISyntaxException {
    String scheme = uri.getScheme();
    if (scheme != null && !scheme.startsWith("file")) {
        throw new URISyntaxException(uri.toString(), "The uri does not start with the scheme <file>");
    }/*from ww w.  ja v  a2 s .  c  om*/
    Path p = toFile(uri).toPath();
    return p;
}

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

/**
 * Returns a File object representing the given URI if possible.
 * This only works if the given URI is a relative path or is a path with a file scheme (starting with: file)
 * @param uri// w ww  .j a  v a 2s . c  o m
 * @return
 * @throws URISyntaxException 
 */
public static File toFile(URI uri) throws URISyntaxException {
    String scheme = uri.getScheme();
    if (scheme != null && !scheme.startsWith("file")) {
        throw new URISyntaxException(uri.toString(), "The uri does not start with the scheme <file>");
    }
    File f = new File(uri.getPath());
    return f;
}

From source file:com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient.java

private static String getMethodHost(HttpRequestBase method) {
    URI uri = method.getURI();
    String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
    return scheme + "://" + uri.getAuthority();
}

From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java

public static <T> PropertyStore<T> getStore(ZKConnection zkclient, String store,
        PropertySerializer<T> serializer) throws URISyntaxException, IOException, PropertyStoreException {
    URI storeUri = URI.create(store);

    if (storeUri.getScheme() != null) {
        if (storeUri.getScheme().equals("zk")) {

            ZooKeeperPermanentStore<T> zkStore = new ZooKeeperPermanentStore<T>(zkclient, serializer,
                    storeUri.getPath());
            startStore(zkStore);//w  ww  . java2 s  .  co m
            return zkStore;
        } else {
            throw new URISyntaxException(store,
                    "Unable to parse store uri. Only zk and file stores are supported.");
        }
    } else {
        // assume it's a local file
        return new FileStore<T>(storeUri.getPath(), ".json", serializer);
    }

}

From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java

public static <T> PropertyStore<T> getEphemeralStore(ZKConnection zkclient, String store,
        PropertySerializer<T> serializer, ZooKeeperPropertyMerger<T> merger)
        throws URISyntaxException, IOException, PropertyStoreException {
    URI storeUri = URI.create(store);

    if (storeUri.getScheme() != null) {
        if (storeUri.getScheme().equals("zk")) {

            ZooKeeperEphemeralStore<T> zkStore = new ZooKeeperEphemeralStore<T>(zkclient, serializer, merger,
                    storeUri.getPath());
            startStore(zkStore);//from   ww  w . j ava2 s .  c  om
            return zkStore;
        } else {
            throw new URISyntaxException(store,
                    "Unable to parse store uri. Only zk and file stores are supported.");
        }
    } else {
        // assume it's a local file
        return new FileStore<T>(storeUri.getPath(), ".json", serializer);
    }

}

From source file:Main.java

public InputSource resolveEntity(String publicId, String systemId) {
    try {// w w w  . java 2  s  .  co  m
        URI uri = new URI(systemId);
        if ("file".equals(uri.getScheme())) {
            String filename = uri.getSchemeSpecificPart();
            return new InputSource(new FileReader(filename));
        }
    } catch (Exception e) {
    }
    return null;
}