Example usage for java.net URI getRawPath

List of usage examples for java.net URI getRawPath

Introduction

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

Prototype

public String getRawPath() 

Source Link

Document

Returns the raw path component of this URI.

Usage

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

@Override
public WebDavMount mount(URI uri) throws CommandFailedException {
    final String path = "/Volumes/Cryptomator" + uri.getRawPath().replace('/', '_');
    final Script mountScript = Script
            .fromLines("mkdir \"$MOUNT_PATH\"",
                    "mount_webdav -S -v Cryptomator \"[::1]:$PORT$DAV_PATH\" \"$MOUNT_PATH\"",
                    "open \"$MOUNT_PATH\"")
            .addEnv("PORT", String.valueOf(uri.getPort())).addEnv("DAV_PATH", uri.getRawPath())
            .addEnv("MOUNT_PATH", path);
    final Script unmountScript = Script.fromLines("umount $MOUNT_PATH").addEnv("MOUNT_PATH", path);
    mountScript.execute();//  ww  w  .  j  av  a 2  s .co  m
    return new WebDavMount() {
        @Override
        public void unmount() throws CommandFailedException {
            unmountScript.execute();
        }
    };
}

From source file:org.soyatec.windowsazure.internal.MessageCanonicalizer.java

private static String getCanonicalizedResource(URI address, ResourceUriComponents uriComponents) {
    // Algorithem is as follows
    // 1. Start with the empty string ("")
    // 2. Append the account name owning the resource preceded by a /. This
    // is not// www .  ja v  a 2  s.  c o  m
    // the name of the account making the request but the account that owns
    // the
    // resource being accessed.
    // 3. Append the path part of the un-decoded HTTP Request-URI, up-to but
    // not
    // including the query string.
    // 4. If the request addresses a particular component of a resource,
    // like?comp=
    // metadata then append the sub-resource including question mark (like
    // ?comp=
    // metadata)
    StringBuilder canonicalizedResource = new StringBuilder(ConstChars.Slash);
    canonicalizedResource.append(uriComponents.getAccountName());

    // Note that AbsolutePath starts with a '/'  

    String path = address.getRawPath();
    //      path = path.replaceAll(" ", "%20");
    //      path = java.net.URLEncoder.encode(path);
    canonicalizedResource.append(path);

    NameValueCollection queryVariables = HttpUtilities.parseQueryString(address.getQuery());

    String compQueryParameterValue = queryVariables.getSingleValue(QueryParams.QueryParamComp);
    if (compQueryParameterValue != null) {
        canonicalizedResource.append(ConstChars.QuestionMark);
        canonicalizedResource.append(QueryParams.QueryParamComp);
        canonicalizedResource.append(QueryParams.SeparatorForParameterAndValue);
        canonicalizedResource.append(compQueryParameterValue);
    }

    return canonicalizedResource.toString();
}

From source file:com.ksc.http.apache.client.impl.ApacheDefaultHttpRequestFactoryTest.java

@Test
public void uri_resourcepath_escapes_double_slash() throws IOException, URISyntaxException {

    final Request<Object> request = newDefaultRequest(HttpMethodName.GET);
    request.setResourcePath("//foo");
    request.setEndpoint(new URI(ENDPOINT));
    HttpRequestBase requestBase = requestFactory.create(request, settings);
    URI expectredUri = requestBase.getURI();
    Assert.assertEquals("/%2Ffoo", expectredUri.getRawPath());
}

From source file:org.freeplane.view.swing.features.filepreview.VideoViewerFactory.java

public boolean accept(final URI uri) {
    return uri.getRawPath().endsWith(".mp4");
}

From source file:org.freeplane.view.swing.features.filepreview.AudioViewerFactory.java

public boolean accept(final URI uri) {
    return uri.getRawPath().endsWith(".mp3");
}

From source file:org.github.oauth2.AccessTokenClient.java

/**
 * Get access token using given code//from w  w w . j  a va 2s.co m
 * 
 * @param code
 * @return fetched token
 * @throws IOException
 */
public String fetch(final String code) throws IOException {
    URI uri = URI.create(client.getAccessTokenUrl());
    HttpHost target = URIUtils.extractHost(uri);
    List<NameValuePair> params = getParams(code);
    HttpPost request = new HttpPost(uri.getRawPath());
    if (params != null && !params.isEmpty())
        request.setEntity(new UrlEncodedFormEntity(params));
    HttpResponse response = execute(target, request);
    String token = getToken(response.getEntity());
    if (token == null)
        throw new IOException("Access token not present in response"); //$NON-NLS-1$
    return token;
}

From source file:org.apache.atlas.LocalAtlasClientTest.java

@Test
@Inject//  w  w  w. ja  va2 s .  com
public void testGetLocationURI() {
    final String guid = "123";
    URI uri = entityResource.getLocationURI(new ArrayList<String>() {
        {
            add(guid);
        }
    });
    uri.getRawPath().equals(AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS + "/"
            + AtlasClient.API.GET_ENTITY.getPath() + "/" + guid);
}

From source file:org.unitedinternet.cosmo.dav.StandardResourceLocatorFactory.java

public DavResourceLocator createResourceLocatorByUri(URL context, String raw) throws CosmoDavException {
    try {// ww w  .java 2  s  .  co  m
        URI uri = new URI(raw);

        URL url = null;
        if (raw.startsWith("/")) {
            // absolute-path relative URL
            url = new URL(context, uri.getRawPath());
        } else {
            // absolute URL
            url = new URL(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getRawPath());

            // make sure that absolute URLs use the same scheme and
            // authority (host:port)
            if (url.getProtocol() != null && !url.getProtocol().equals(context.getProtocol())) {
                throw new BadRequestException("target " + uri + " does not specify same scheme " + "as context "
                        + context.toString());
            }

            // look at host
            if (url.getHost() != null && !url.getHost().equals(context.getHost())) {
                throw new BadRequestException(
                        "target " + uri + " does not specify same host " + "as context " + context.toString());
            }

            // look at ports
            // take default ports 80 and 443 into account so that
            // https://server is the same as https://server:443
            int port1 = translatePort(context.getProtocol(), context.getPort());
            int port2 = translatePort(url.getProtocol(), url.getPort());

            if (port1 != port2) {
                throw new BadRequestException(
                        "target " + uri + " does not specify same port " + "as context " + context.toString());
            }
        }

        if (!url.getPath().startsWith(context.getPath())) {
            throw new BadRequestException(uri + " does not specify correct dav path " + context.getPath());
        }

        // trim base path
        String path = url.getPath().substring(context.getPath().length()) + "/";
        path = path.replaceAll("/{2,}", "/");

        return new StandardResourceLocator(context, path, this);
    } catch (URISyntaxException | MalformedURLException e) {
        throw new BadRequestException("Invalid URL: " + e.getMessage());
    }
}

From source file:com.subgraph.vega.internal.http.requests.HttpRequestBuilder.java

private void setPathFromUri(URI uri) {
    path = uri.getRawPath();
    if (path != null) {
        if (path.length() == 0 || path.charAt(0) != '/') {
            path = '/' + path;
        }// www .  jav a 2  s  . c o  m
    } else {
        path = "";
    }
    if (uri.getRawQuery() != null) {
        path += '?' + uri.getRawQuery();
    }
    if (uri.getRawFragment() != null) {
        path += '#' + uri.getRawFragment();
    }
}

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

@Override
public WebDavMount mount(URI uri) throws CommandFailedException {
    final Script mountScript = fromLines(
            "net use * http://0--1.ipv6-literal.net:%PORT%%DAV_PATH% /persistent:no")
                    .addEnv("PORT", String.valueOf(uri.getPort())).addEnv("DAV_PATH", uri.getRawPath());
    final CommandResult mountResult = mountScript.execute(30, TimeUnit.SECONDS);
    final String driveLetter = getDriveLetter(mountResult.getStdOut());
    final Script unmountScript = fromLines("net use " + driveLetter + " /delete").addEnv("DRIVE_LETTER",
            driveLetter);/*from www.j  a v  a  2  s .  c  o  m*/
    return new WebDavMount() {
        @Override
        public void unmount() throws CommandFailedException {
            unmountScript.execute();
        }
    };
}