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:UriUtils.java

/**
 * Returns the filename for the specified URI.
 * <p/>/*from www .  j  a  v  a  2  s . c o m*/
 * For example, applyign this method to the URI &quot;<tt>http://www.site.com/articles/article.html</tt>&quot; will
 * return &quot;<tt>article.html</tt>&quot;.
 *
 * @param uri The URI for which to return the filename.
 * @return The filename of the resource represented by the specified URI.
 * @throws IllegalArgumentException <ul><li>The URI cannot be null.</li><li>A separator character could not be found
 *                                  in the specified URI.</li><li>The specified URI does not point to a file
 *                                  resource.</li></ul>
 */
public static String getFilename(final URI uri) throws IllegalArgumentException {
    if (uri == null)
        throw new IllegalArgumentException("The URI cannot be null.");

    final String path = uri.getRawPath();
    final int finalSeparator = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
    if (finalSeparator == -1)
        throw new IllegalArgumentException("A separator character could not found in the specified URI.");
    if (finalSeparator == path.length() - 1)
        throw new IllegalArgumentException("The specified URI does not point to a file resource.");
    return path.substring(finalSeparator + 1);
}

From source file:org.springframework.security.ldap.LdapUtils.java

/**
 * Works out the root DN for an LDAP URL.
 * <p>//from www  .  ja v a  2  s. c o  m
 * For example, the URL <tt>ldap://monkeymachine:11389/dc=springframework,dc=org</tt>
 * has the root DN "dc=springframework,dc=org".
 * </p>
 *
 * @param url the LDAP URL
 *
 * @return the root DN
 */
public static String parseRootDnFromUrl(String url) {
    Assert.hasLength(url, "url must have length");

    String urlRootDn;

    if (url.startsWith("ldap:") || url.startsWith("ldaps:")) {
        URI uri = parseLdapUrl(url);
        urlRootDn = uri.getRawPath();
    } else {
        // Assume it's an embedded server
        urlRootDn = url;
    }

    if (urlRootDn.startsWith("/")) {
        urlRootDn = urlRootDn.substring(1);
    }

    return urlRootDn;
}

From source file:com.netflix.iep.http.ClientConfig.java

/** Create relative uri string with the path and query. */
static String relative(URI uri) {
    String r = uri.getRawPath();
    if (r == null) {
        r = "/";/*from  w  ww. j  a v  a  2  s.c  o  m*/
    } else if (r.startsWith("//")) {
        r = r.substring(1);
    }
    if (uri.getRawQuery() != null) {
        r += "?" + uri.getRawQuery();
    }
    return r;
}

From source file:com.kolich.aws.services.AbstractAwsService.java

/**
 * Given a {@link URI} returns the path component of that
 * {@link URI}.  The path of a URI is the piece of the URI after
 * the hostname, not including the query parameters.  If the URI
 * is null, a single "/" is returned.  If the URI is not null, but
 * the path is empty, an "" empty string is returned.
 * @param uri the URI to extract the path from
 * @return/*w w  w .  j  ava  2s .  c  o m*/
 */
private static final String getPath(final URI uri) {
    if (uri == null) {
        return SLASH_STRING;
    } else {
        final String path = uri.getRawPath();
        return (path == null) ? EMPTY_STRING : path;
    }
}

From source file:annis.CommonHelper.java

public static List<String> getCorpusPath(URI uri) {
    String rawPath = StringUtils.strip(uri.getRawPath(), "/ \t");

    // split on raw path (so "/" in corpus names are still encoded)
    String[] path = rawPath.split("/");

    // decode every single part by itself
    ArrayList<String> result = new ArrayList<String>(path.length);
    for (int i = 0; i < path.length; i++) {
        try {//  w  w  w. java2s.co m
            result.add(URLDecoder.decode(path[i], "UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            log.error(null, ex);
            // fallback
            result.add(path[i]);
        }
    }

    return result;
}

From source file:org.hippoecm.frontend.service.restproxy.RestProxyServicePlugin.java

static String createRestURI(String value, final HttpServletRequest request) {
    if (StringUtils.isEmpty(value)) {
        throw new IllegalStateException(
                "No REST service URI configured. Please set the plugin configuration property '"
                        + CONFIG_REST_URI + "'");
    }/*from w  ww  .j  av  a  2  s  . c o m*/
    try {
        URI u = new URI(value);
        final int portNumber;
        if (u.getPort() == -1) {
            portNumber = request.getLocalPort();
        } else {
            portNumber = u.getPort();
        }
        return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), portNumber, u.getRawPath(), u.getRawQuery(),
                u.getRawFragment()).toString();

    } catch (URISyntaxException e) {
        throw new IllegalStateException(
                "Invalid REST service URI configured. Please correct the plugin configuration property '"
                        + CONFIG_REST_URI + "'",
                e);
    }
}

From source file:sf.net.experimaestro.scheduler.ResourceLocator.java

public static ResourceLocator parse(String idString) {
    try {/*from w  w  w . ja  v a 2 s  .  c om*/
        final URI uri = new URI(idString);
        StringBuilder connectorId = new StringBuilder();
        StringBuilder path = new StringBuilder();

        connectorId.append(uri.getScheme());
        connectorId.append("://");
        if (uri.getRawAuthority() != null)
            connectorId.append(uri.getRawAuthority());

        path.append(uri.getRawPath());

        return new ResourceLocator(connectorId.toString(), path.toString());
    } catch (URISyntaxException e) {
        throw new XPMRuntimeException("Could not parse locator URI [%s]", idString);
    }
}

From source file:co.cask.cdap.metrics.query.MetricsRequestParser.java

static ImmutablePair<MetricsRequest, MetricsRequestContext> parseRequestAndContext(URI requestURI)
        throws MetricsPathException {
    MetricsRequestBuilder builder = new MetricsRequestBuilder(requestURI);

    // metric will be at the end.
    String uriPath = requestURI.getRawPath();
    int index = uriPath.lastIndexOf("/");
    builder.setMetricPrefix(urlDecode(uriPath.substring(index + 1)));

    // strip the metric from the end of the path
    String strippedPath = uriPath.substring(0, index);

    MetricsRequestContext metricsRequestContext;
    if (strippedPath.startsWith("/system/cluster")) {
        builder.setContextPrefix(CLUSTER_METRICS_CONTEXT);
        builder.setScope(MetricsScope.SYSTEM);
        metricsRequestContext = new MetricsRequestContext.Builder().build();
    } else if (strippedPath.startsWith("/system/transactions")) {
        builder.setContextPrefix(TRANSACTION_METRICS_CONTEXT);
        builder.setScope(MetricsScope.SYSTEM);
        metricsRequestContext = new MetricsRequestContext.Builder().build();
    } else {//from  www . j  a v a 2  s. c o  m
        metricsRequestContext = parseContext(strippedPath, builder);
    }
    parseQueryString(requestURI, builder);
    return new ImmutablePair<MetricsRequest, MetricsRequestContext>(builder.build(), metricsRequestContext);
}

From source file:com.zimbra.common.util.HttpUtil.java

/**
 * Returns the decoded fragments of an url.
 * @param uri/*  w  w w .jav a 2s  .  c  o m*/
 * @return
 */

public static String[] getPathFragments(URI uri) {
    List<String> fragments = new ArrayList<String>();
    String[] encodedFragments = uri.getRawPath().split("/");
    for (String encodedFragment : encodedFragments) {
        if (!encodedFragment.isEmpty()) {
            fragments.add(urlUnescape(encodedFragment));
        }
    }
    return fragments.toArray(new String[0]);
}

From source file:com.gamesalutes.utils.WebUtils.java

/**
 * Adds the query parameters to the uri <code>path</code>.
 * /* w w  w  . j av a2s  . c  om*/
 * @param path the uri
 * @param parameters the query parameters to set for the uri
 * @return <code>path</code> with the query parameters added
 */
public static URI setQueryParameters(URI path, Map<String, String> parameters) {
    try {
        return new URI(path.getScheme(), path.getRawUserInfo(), path.getHost(), path.getPort(),
                path.getRawPath(), urlEncode(parameters, false), path.getRawFragment());
    } catch (URISyntaxException e) {
        // shouldn't happen
        throw new AssertionError(e);
    }

}