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.google.mr4c.content.ContentFactories.java

/**
  * Turns a URI that is just a file path or a "rel" URI into a real file URI.
*/// w w w  .j  av a  2 s  .  c o m
public static URI scrubURI(URI uri) {
    String scheme = uri.getScheme();
    String path = uri.getSchemeSpecificPart();
    if (StringUtils.isEmpty(scheme)) {
        // its a file path
        if (path.startsWith("/")) {
            // its absolute
            return new File(path).toURI();
        } else {
            // its relative
            return new File(RelativeContentFactory.getWorkingDirectory(), path).toURI();
        }
    } else if (scheme.equals("rel")) {
        return RelativeContentFactory.toFile(uri).toURI();
    } else {
        return uri;
    }
}

From source file:org.sonatype.nexus.httpclient.internal.NexusRedirectStrategy.java

/**
 * Return the scheme of given uri in lower-case, or null if the scheme can not be determined.
 *//*from  www.  ja  v a 2 s  .c  o  m*/
@Nullable
private static String schemeOf(final URI uri) {
    if (uri != null) {
        String scheme = uri.getScheme();
        if (scheme != null) {
            return scheme.toLowerCase(Locale.US);
        }
    }
    return null;
}

From source file:org.mule.tools.rhinodo.impl.NodeModuleImplBuilder.java

public static NodeModuleImpl fromJar(Class<?> klass, String rootDirectory, String destDir) {
    if (rootDirectory == null) {
        throw new IllegalArgumentException("Error validating rootDirectory");
    }// ww w  .j a  v  a  2  s. c o  m

    if (destDir == null) {
        throw new IllegalArgumentException("Error validating destDir");
    }

    URI root = getRoot(klass, rootDirectory);

    if (!"jar".equals(root.getScheme())) {
        throw new IllegalArgumentException("URI must have jar scheme");
    }

    JarURIHelper jarURIHelper;

    new File(destDir).mkdirs();

    try {
        jarURIHelper = new JarURIHelper(root);
        jarURIHelper.copyToFolder(new File(destDir));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return fromFolder(destDir + File.separator + jarURIHelper.getInsideJarRelativePath());
}

From source file:com.microsoft.azure.keyvault.authentication.KeyVaultCredentials.java

private static String getAuthority(URI uri) {
    String scheme = uri.getScheme();
    String host = uri.getHost();/* w w w  .j  a  va2 s  .c o m*/
    int port = uri.getPort();
    StringBuilder builder = new StringBuilder();
    if (scheme != null) {
        builder.append(scheme).append("://");
    }
    builder.append(host);
    if (port >= 0) {
        builder.append(':').append(port);
    }
    return builder.toString();
}

From source file:de.shadowhunt.subversion.internal.URIUtils.java

private static URI createURI0(final URI repository, final Resource... resources) throws URISyntaxException {
    final URIBuilder builder = new URIBuilder();
    builder.setScheme(repository.getScheme());
    builder.setHost(repository.getHost());
    builder.setPort(repository.getPort());
    final StringBuilder completePath = new StringBuilder(repository.getPath());
    for (final Resource resource : resources) {
        completePath.append(resource.getValue());
    }//from ww w.ja  va  2 s. c o m
    builder.setPath(completePath.toString());
    return builder.build();
}

From source file:io.orchestrate.client.itest.BaseClientTest.java

@BeforeClass
public static void setUpClass() {
    final String apiKey = System.getProperty("orchestrate.apiKey");
    if (apiKey == null || apiKey.length() < 1) {
        throw new IllegalStateException("Cannot run integration tests, 'apiKey' is blank.");
    }//from w  ww  .java 2  s. c om

    URI uri = URI.create(System.getProperty("orchestrate.host", OrchestrateClient.Builder.DEFAULT_HOST));

    String host = uri.getScheme() + "://" + uri.getHost();
    int port = uri.getPort();
    if (port == -1) {
        if (uri.getScheme().equals("https")) {
            port = 443;
        } else {
            port = 80;
        }
    }
    boolean ssl = uri.getScheme().equals("https");

    client = OrchestrateClient.builder(apiKey).host(host).port(port).useSSL(ssl).build();
}

From source file:de.fhg.iais.asc.xslt.binaries.download.Downloader.java

private static boolean isDownloadableURI(URI uri) {
    String scheme = uri.getScheme();
    return ALLOWED_SCHEMES.contains(scheme);
}

From source file:de.shadowhunt.subversion.RepositoryFactory.java

private static URI sanitise(final URI uri, final Resource path) {
    try {//from  w w  w  .  ja  v  a  2 s. c o  m
        return new URI(uri.getScheme(), DEFAULT_USER_INFO, uri.getHost(), uri.getPort(), path.getValue(),
                DEFAULT_QUERY, DEFAULT_FRAGMENT);
    } catch (final URISyntaxException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:com.microsoft.tfs.core.exceptions.TFSUnauthorizedException.java

/**
 * Gets a URI string for display, which uses only the scheme, host, and port
 * from the original URI string.//  ww w .  j  av a 2 s  .  c  o m
 *
 * @param uriString
 *        the original URI string for which authorization failed (must not
 *        be <code>null</code>)
 * @return a URI string with the display information for the given URI
 *         string (never <code>null</code>)
 */
private static String getDisplayURIString(final String uriString) {
    Check.notNull(uriString, "uriString"); //$NON-NLS-1$

    String displayURIString;
    try {
        final URI serverURI = new URI(uriString);
        displayURIString = new URI(serverURI.getScheme(), null, serverURI.getHost(), serverURI.getPort(), "/", //$NON-NLS-1$
                null, null).toString();
    } catch (final URISyntaxException uriSyntaxException) {
        // This should be very rare.
        log.error(
                MessageFormat.format("Could not construct message URI for '{0}', returning raw URI string", //$NON-NLS-1$
                        uriString), uriSyntaxException);

        // Fall back to the original URI (with path part and all; better
        // than nothing for the user)
        displayURIString = uriString;
    }

    return displayURIString;
}

From source file:fedora.server.utilities.ServerUtility.java

/**
 * Tell whether the given URL appears to be referring to somewhere within
 * the Fedora webapp.//w w w.  j  a v  a  2  s .co  m
 */
public static boolean isURLFedoraServer(String url) {

    // scheme must be http or https
    URI uri = URI.create(url);
    String scheme = uri.getScheme();
    if (!scheme.equals("http") && !scheme.equals("https")) {
        return false;
    }

    // host must be configured hostname or localhost
    String fHost = CONFIG.getParameter(FEDORA_SERVER_HOST).getValue();
    String host = uri.getHost();
    if (!host.equals(fHost) && !host.equals("localhost")) {
        return false;
    }

    // path must begin with configured webapp context
    String path = uri.getPath();
    String fedoraContext = CONFIG.getParameter(FEDORA_SERVER_CONTEXT).getValue();
    if (!path.startsWith("/" + fedoraContext + "/")) {
        return false;
    }

    // port specification must match http or https port as appropriate
    String httpPort = CONFIG.getParameter(FEDORA_SERVER_PORT).getValue();
    String httpsPort = CONFIG.getParameter(FEDORA_REDIRECT_PORT).getValue();
    if (uri.getPort() == -1) {
        // unspecified, so fedoraPort must be 80 (http), or 443 (https)
        if (scheme.equals("http")) {
            return httpPort.equals("80");
        } else {
            return httpsPort.equals("443");
        }
    } else {
        // specified, so must match appropriate http or https port
        String port = "" + uri.getPort();
        if (scheme.equals("http")) {
            return port.equals(httpPort);
        } else {
            return port.equals(httpsPort);
        }
    }

}