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.ibm.jaggr.core.util.PathUtil.java

public static URI stripJsExtension(URI value) throws URISyntaxException {
    if (value == null) {
        return null;
    }/*  w  w  w .  jav a 2 s  . c  om*/
    return value.getPath().endsWith(".js") ? //$NON-NLS-1$
            new URI(value.getScheme(), value.getAuthority(),
                    value.getPath().substring(0, value.getPath().length() - 3), value.getQuery(),
                    value.getFragment())
            : value;
}

From source file:org.dkpro.lab.storage.filesystem.FileSystemStorageService.java

public static boolean isStaticImport(URI uri) {
    if (LATEST_CONTEXT_SCHEME.equals(uri.getScheme())) {
        return false;
    } else if (CONTEXT_ID_SCHEME.equals(uri.getScheme())) {
        return false;
    } else {//  www  .j a  va  2s .com
        return true;
    }
}

From source file:me.footlights.core.crypto.SecretKey.java

/** Parse a hexadecimal URI. */
public static SecretKey parse(URI uri)
        throws GeneralSecurityException, org.apache.commons.codec.DecoderException {
    return newGenerator().setAlgorithm(uri.getScheme())
            .setBytes(Hex.decodeHex(uri.getSchemeSpecificPart().toCharArray())).generate();
}

From source file:nl.esciencecenter.osmium.mac.MacScheme.java

/**
 * @param uri Uri from which to extract port
 * @return Port of `uri` based on explicit port or derived from scheme
 *//*from w  w w  . ja va 2 s. c  o m*/
public static int getPort(URI uri) {
    int port = uri.getPort();
    if (port == -1) {
        String scheme = uri.getScheme();
        if (scheme.equals("http")) {
            port = HTTP_PORT;
        } else if (scheme.equals("https")) {
            port = HTTPS_PORT;
        }
    }
    return port;
}

From source file:com.limegroup.gnutella.licenses.LicenseFactoryImpl.java

/** Gets a CC license URI from the given license string. */
private static URI getCCLicenseURI(String license) {
    license = license.toLowerCase(Locale.US);

    // find where the URL should begin.
    int verifyAt = license.indexOf(CCConstants.URL_INDICATOR);
    if (verifyAt == -1)
        return null;

    int urlStart = verifyAt + CCConstants.URL_INDICATOR.length();
    if (urlStart >= license.length())
        return null;

    String url = license.substring(urlStart).trim();
    URI uri = null;
    try {/*  ww w . j a v a2 s  .co m*/
        uri = URIUtils.toURI(url);

        // Make sure the scheme is HTTP.
        String scheme = uri.getScheme();
        if (scheme == null || !scheme.equalsIgnoreCase("http"))
            throw new URISyntaxException(uri.toString(), "Invalid scheme: " + scheme);
        // Make sure the scheme has some authority.
        String authority = uri.getAuthority();
        if (authority == null || authority.equals("") || authority.indexOf(' ') != -1)
            throw new URISyntaxException(uri.toString(), "Invalid authority: " + authority);

    } catch (URISyntaxException e) {
        //URIUtils.error(e);
        uri = null;
        LOG.error("Unable to create URI", e);
    }

    return uri;
}

From source file:org.switchyard.component.http.endpoint.StandaloneEndpointPublisher.java

/**
 * Method for get request information from a http exchange.
 *
 * @param request HttpExchange//from  w  w  w .jav a 2s  .  c  om
 * @param type ContentType
 * @return Request information from a http exchange
 * @throws IOException when the request information could not be read
 */
public static HttpRequestInfo getRequestInfo(HttpExchange request, ContentType type) throws IOException {
    HttpRequestInfo requestInfo = new HttpRequestInfo();

    if (request.getHttpContext().getAuthenticator() instanceof BasicAuthenticator) {
        requestInfo.setAuthType(HttpServletRequest.BASIC_AUTH);
    }
    URI u = request.getRequestURI();
    URI requestURI = null;
    try {
        requestURI = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), null, null);
    } catch (URISyntaxException e) {
        // Strange that this could happen when copying from another URI.
        LOGGER.debug(e);
    }
    requestInfo.setCharacterEncoding(type.getCharset());
    requestInfo.setContentType(type.toString());
    requestInfo.setContextPath(request.getHttpContext().getPath());
    requestInfo.setLocalAddr(request.getLocalAddress().getAddress().getHostAddress());
    requestInfo.setLocalName(request.getLocalAddress().getAddress().getHostName());
    requestInfo.setMethod(request.getRequestMethod());
    requestInfo.setProtocol(request.getProtocol());
    requestInfo.setQueryString(u.getQuery());
    requestInfo.setRemoteAddr(request.getRemoteAddress().getAddress().getHostAddress());
    requestInfo.setRemoteHost(request.getRemoteAddress().getAddress().getHostName());
    if (request.getHttpContext().getAuthenticator() instanceof BasicAuthenticator) {
        requestInfo.setRemoteUser(request.getPrincipal().getUsername());
    }
    requestInfo.setContentLength(request.getRequestBody().available());
    // requestInfo.setRequestSessionId(request.getRequestedSessionId());
    if (requestURI != null) {
        requestInfo.setRequestURI(requestURI.toString());
    }
    requestInfo.setScheme(u.getScheme());
    requestInfo.setServerName(u.getHost());
    requestInfo.setRequestPath(u.getPath());

    // Http Query params...
    if (requestInfo.getQueryString() != null) {
        Charset charset = null;
        if (type.getCharset() != null) {
            try {
                charset = Charset.forName(type.getCharset());
            } catch (Exception exception) {
                LOGGER.debug(exception);
            }
        }
        for (NameValuePair nameValuePair : URLEncodedUtils.parse(requestInfo.getQueryString(), charset)) {
            requestInfo.addQueryParam(nameValuePair.getName(), nameValuePair.getValue());
        }
    }

    // Credentials...
    requestInfo.getCredentials().addAll(new HttpExchangeCredentialExtractor().extract(request));

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace(requestInfo);
    }

    return requestInfo;
}

From source file:com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration.java

/**
 * Fix a serverUrl.//w  w  w  . j  a  v  a 2s. c om
 *
 * @param serverUrl the server URL.
 * @return the normalized server URL.
 */
@NonNull
public static String normalizeServerUrl(@CheckForNull String serverUrl) {
    serverUrl = StringUtils.defaultIfBlank(serverUrl, BitbucketCloudEndpoint.SERVER_URL);
    try {
        URI uri = new URI(serverUrl).normalize();
        String scheme = uri.getScheme();
        if ("http".equals(scheme) || "https".equals(scheme)) {
            // we only expect http / https, but also these are the only ones where we know the authority
            // is server based, i.e. [userinfo@]server[:port]
            // DNS names must be US-ASCII and are case insensitive, so we force all to lowercase

            String host = uri.getHost() == null ? null : uri.getHost().toLowerCase(Locale.ENGLISH);
            int port = uri.getPort();
            if ("http".equals(scheme) && port == 80) {
                port = -1;
            } else if ("https".equals(scheme) && port == 443) {
                port = -1;
            }
            serverUrl = new URI(scheme, uri.getUserInfo(), host, port, uri.getPath(), uri.getQuery(),
                    uri.getFragment()).toASCIIString();
        }
    } catch (URISyntaxException e) {
        // ignore, this was a best effort tidy-up
    }
    return serverUrl.replaceAll("/$", "");
}

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

private static BufferedReader getReader(URI filePath) throws MalformedURLException, IOException {
    BufferedReader reader;//from w ww. j  a  v a2s .  c o  m
    if (filePath.getScheme().equals("file")) {
        reader = new BufferedReader(new FileReader(new File(filePath)));
    } else {
        reader = new BufferedReader(new InputStreamReader(filePath.toURL().openConnection().getInputStream()));
    }
    return reader;
}

From source file:URISupport.java

/**
 * Creates a URI with the given query//from  ww w  . j  a  v  a2s  . co  m
 */
public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException {
    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query,
            uri.getFragment());
}

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

private static NodeModuleImpl extractFromPackageJson(URI root) {
    if (root == null) {
        throw new IllegalArgumentException("Error validating rootDirectory");
    }//from  w  w w . jav a 2  s. com

    URI packageJson;
    try {
        packageJson = new URI(root.toString() + "/" + "package.json");
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    boolean exists;
    if ("file".equals(packageJson.getScheme())) {
        exists = new File(packageJson).exists();
    } else {
        throw new IllegalStateException(
                String.format("Error: scheme [%s] not supported.", packageJson.getScheme()));
    }

    if (!exists) {
        throw new IllegalStateException(String.format("Error: package.json not found at [%s].", packageJson));
    }

    return NodeModuleImpl.create(root,
            NodeModuleImplBuilder.<String, String>getPackageJSONMap(new File(packageJson.getPath())));
}