Example usage for java.net URI getRawSchemeSpecificPart

List of usage examples for java.net URI getRawSchemeSpecificPart

Introduction

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

Prototype

public String getRawSchemeSpecificPart() 

Source Link

Document

Returns the raw scheme-specific part of this URI.

Usage

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.java2s.com");
    System.out.println("URI      : " + uri);
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
}

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:IRIDemo.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://r%C3%A9sum%C3%A9.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:org.gedcomx.rt.DataURIUtil.java

/**
 * Get the string data from the specified URI.
 *
 * @param uri the URI./*  ww  w.  j  av a 2  s.  c om*/
 * @return The string form of the data, or null if the data URI doesn't contain a string.
 */
public static String getValueAsString(URI uri) {
    if ("data".equals(uri.getScheme())) {
        String ssp;
        try {
            ssp = URLDecoder.decode(uri.getRawSchemeSpecificPart(), "utf-8");
        } catch (UnsupportedEncodingException e) {
            return null;
        }

        int commaIndex = ssp.indexOf(',');
        if (commaIndex >= 0) {
            String meta = ssp.substring(0, commaIndex);
            try {
                boolean base64 = meta.endsWith(";base64");
                if (base64) {
                    meta = meta.substring(0, meta.indexOf(";base64"));
                }

                MediaType mediaType = meta.trim().length() > 0 ? MediaType.valueOf(meta)
                        : MediaType.TEXT_PLAIN_TYPE;
                if (MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType)) {
                    String value = ssp.substring(commaIndex + 1);
                    if (base64) {
                        byte[] decoded = Base64.decodeBase64(value);
                        String charset = mediaType.getParameters().get("charset");
                        if (charset == null) {
                            charset = "utf-8";
                        }
                        return new String(decoded, charset);
                    } else {
                        return value;
                    }
                }
            } catch (IllegalArgumentException e) {
                //fall through...
            } catch (UnsupportedEncodingException e) {
                //fall through...
            }
        }
    }

    return null;
}

From source file:com.collective.celos.Util.java

public static String augmentHdfsPath(String hdfsPrefix, String path) throws URISyntaxException {

    if (hdfsPrefix.isEmpty() || hdfsPrefix.equals("/")) {
        return path;
    }/*from ww  w  .  j  a  v a 2s.  co  m*/

    for (String ch : conversions.keySet()) {
        path = path.replace(ch.toString(), conversions.get(ch).toString());
    }
    URI oldUri = URI.create(path);

    String host = oldUri.getHost();
    if (oldUri.getRawSchemeSpecificPart().startsWith("///") && host == null) {
        host = "";
    }

    URI newUri = new URI(oldUri.getScheme(), oldUri.getUserInfo(), host, oldUri.getPort(),
            hdfsPrefix + oldUri.getPath(), oldUri.getQuery(), oldUri.getFragment());
    path = newUri.toString();
    for (String ch : backConversions.keySet()) {
        path = path.replace(ch.toString(), backConversions.get(ch).toString());
    }
    return path;
}

From source file:de.javagl.jgltf.model.io.GltfUtils.java

/**
 * Tries to detect the format of the image data from the given URI, and 
 * return the corresponding string of the <code>"image/..."</code> MIME 
 * type. This may, for example, be <code>"png"</code> or <code>"gif"</code>
 * or <code>"jpeg"</code> (<b>not</b> <code>"jpg"</code>!)
 *  //from w w w.j ava 2s  .co  m
 * @param uriString The image data
 * @return The image format string, or <code>null</code> if it can not
 * be detected.
 */
private static String guessImageMimeTypeString(String uriString) {
    try {
        URI uri = new URI(uriString);
        if ("data".equalsIgnoreCase(uri.getScheme())) {
            String raw = uri.getRawSchemeSpecificPart().toLowerCase();
            return getStringBetween(raw, "image/", ";base64");
        }
    } catch (URISyntaxException e) {
        return null;
    }
    int lastDotIndex = uriString.lastIndexOf('.');
    if (lastDotIndex == -1) {
        return null;
    }
    String end = uriString.substring(lastDotIndex + 1).toLowerCase();
    if (end.equals("jpg") || end.equals("jpeg")) {
        return "jpeg";
    }
    return end;
}

From source file:org.apache.camel.component.gae.http.GHttpEndpoint.java

/**
 * Constructs a {@link URL} from an <code>uri</code> and an optional
 * <code>query</code> string. The encoding strategy follow those of the
 * Camel HTTP component./*  w  w w  . j  av a 2s .  c om*/
 * 
 * @param uri
 *            must be encoded with
 *            {@link UnsafeUriCharactersEncoder#encode(String)}.
 * @param query
 *            decoded query string. Replaces the query part of
 *            <code>uri</code> if not <code>null</code>.
 */
static URL getEndpointUrl(String uri, String query) throws Exception {
    Map<String, Object> parameters = null;
    URI uriObj = new URI(uri);
    if (query == null) {
        parameters = URISupport.parseParameters(uriObj);
    } else {
        parameters = URISupport.parseQuery(query);
    }
    if (uriObj.getScheme().equals(GHTTPS_SCHEME)) {
        uriObj = new URI(HTTPS_SCHEME + ":" + uriObj.getRawSchemeSpecificPart());
    } else { // ghttp or anything else
        uriObj = new URI(HTTP_SCHEME + ":" + uriObj.getRawSchemeSpecificPart());
    }
    return URISupport.createRemainingURI(uriObj, parameters).toURL();
}

From source file:org.akubraproject.fs.FSBlob.java

static URI validateId(URI blobId) throws UnsupportedIdException {
    if (blobId == null)
        throw new NullPointerException("Id cannot be null");
    if (!blobId.getScheme().equalsIgnoreCase(scheme))
        throw new UnsupportedIdException(blobId, "Id must be in " + scheme + " scheme");
    String path = blobId.getRawSchemeSpecificPart();
    if (path.startsWith("/"))
        throw new UnsupportedIdException(blobId, "Id must specify a relative path");
    try {//  w  ww .j a  v  a  2s. c  om
        // insert a '/' so java.net.URI normalization works
        URI tmp = new URI(scheme + ":/" + path);
        String nPath = tmp.normalize().getRawSchemeSpecificPart().substring(1);
        if (nPath.equals("..") || nPath.startsWith("../"))
            throw new UnsupportedIdException(blobId, "Id cannot be outside top-level directory");
        if (nPath.endsWith("/"))
            throw new UnsupportedIdException(blobId, "Id cannot specify a directory");
        return new URI(scheme + ":" + nPath);
    } catch (URISyntaxException wontHappen) {
        throw new Error(wontHappen);
    }
}

From source file:com.orange.oidc.secproxy_service.HttpOpenidConnect.java

/**
 * Apply normalization rules to the identifier supplied by the End-User 
 * to determine the Resource and Host. Then make an HTTP GET request to
 * the host's WebFinger endpoint to obtain the location of the requested 
 * service//w w w.  j  ava  2  s  . c  o m
 * return the issuer location ("href")
 * @param user_input , domain
 * @return
 */

public static String webfinger(String userInput, String serverUrl) {
    // android.os.Debug.waitForDebugger();

    String result = ""; // result of the http request (a json object
    // converted to string)
    String postUrl = "";
    String host = null;
    String href = null;

    // URI identifying the type of service whose location is being requested
    final String rel = "http://openid.net/specs/connect/1.0/issuer";

    if (!isEmpty(userInput)) {

        try {
            // normalizes this URI's path
            URI uri = new URI(userInput).normalize();
            String[] parts = uri.getRawSchemeSpecificPart().split("@");

            if (!isEmpty(serverUrl)) {
                // use serverUrl if specified
                if (serverUrl.startsWith("https://")) {
                    host = serverUrl.substring(8);
                } else if (serverUrl.startsWith("http://")) {
                    host = serverUrl.substring(7);
                } else {
                    host = serverUrl;
                }
            } else if (parts.length > 1) {
                // the user is using an E-Mail Address Syntax
                host = parts[parts.length - 1];
            } else {
                // the user is using an other syntax
                host = uri.getHost();
            }

            // check if host is valid
            if (host == null) {
                return null;
            }

            if (!host.endsWith("/"))
                host += "/";
            postUrl = "https://" + host + ".well-known/webfinger?resource=" + userInput + "&rel=" + rel;

            // log the request
            Logd(TAG, "Web finger request\n GET " + postUrl + "\n HTTP /1.1" + "\n Host: " + host);
            // Send an HTTP get request with the resource and rel parameters
            HttpURLConnection huc = getHUC(postUrl);
            huc.setDoOutput(true);
            huc.setRequestProperty("Content-Type", "application/jrd+json");
            huc.connect();

            try {

                int responseCode = huc.getResponseCode();
                Logd(TAG, "webfinger responseCode: " + responseCode);
                // if 200, read http body
                if (responseCode == 200) {
                    InputStream is = huc.getInputStream();
                    result = convertStreamToString(is);
                    is.close();
                    Logd(TAG, "webfinger result: " + result);

                    // The response is a json object and the issuer location
                    // is returned as the value of the href member
                    // a links array element with the rel member value
                    // http://openid.net/specs/connect/1.0/issuer
                    JSONObject jo = new JSONObject(result);
                    JSONObject links = jo.getJSONArray("links").getJSONObject(0);
                    href = links.getString("href");
                    Logd(TAG, "webfinger reponse href: " + href);

                } else {
                    // why the request didn't succeed
                    href = huc.getResponseMessage();
                }

                // close connection
                huc.disconnect();
            } catch (IOException ioe) {
                Logd(TAG, "webfinger io exception: " + huc.getErrorStream());
                ioe.printStackTrace();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    } else {
        // the user_input is empty
        href = "no identifier detected!!\n";
    }
    return href;
}

From source file:org.cryptomator.ui.util.mount.LinuxGvfsWebDavMounter.java

@Override
public WebDavMount mount(URI uri) throws CommandFailedException {
    final Script mountScript = Script
            .fromLines("set -x", "gvfs-mount \"dav:$DAV_SSP\"", "xdg-open \"dav:$DAV_SSP\"")
            .addEnv("DAV_SSP", uri.getRawSchemeSpecificPart());
    final Script unmountScript = Script.fromLines("set -x", "gvfs-mount -u \"dav:$DAV_SSP\"").addEnv("$DAV_SSP",
            uri.getRawSchemeSpecificPart());
    mountScript.execute();/*from   ww  w .j a  v  a  2s. c o m*/
    return new WebDavMount() {
        @Override
        public void unmount() throws CommandFailedException {
            unmountScript.execute();
        }
    };
}