Example usage for java.net URL getPath

List of usage examples for java.net URL getPath

Introduction

In this page you can find the example usage for java.net URL getPath.

Prototype

public String getPath() 

Source Link

Document

Gets the path part of this URL .

Usage

From source file:org.sonatype.nexus.testsuite.NexusHttpsITSupport.java

/**
 * @return the expected cookie path value of our session cookie from the given base URL
 *//* ww w  .  j a v a2 s .c  o  m*/
protected String cookiePath(final URL url) {
    final String path = url.getPath();
    return path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length() - 1) : path;
}

From source file:edu.uci.ics.crawler4j.robotstxt.RobotstxtServer.java

public boolean allows(WebURL webURL) {
    if (!config.isEnabled()) {
        return true;
    }/*  www. j  a  v  a2 s  .com*/
    try {
        URL url = new URL(webURL.getURL());
        String host = getHost(url);
        String path = url.getPath();
        HostDirectives directives = host2directivesCache.get(host);
        if (directives != null && directives.needsRefetch()) {
            synchronized (host2directivesCache) {
                host2directivesCache.remove(host);
                directives = null;
            }
        }
        if (directives == null) {
            directives = fetchDirectives(url);
        }
        return directives.allows(path);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:br.bireme.tb.URLS.java

static URL withDomain(final URL furl, final String url) throws IOException {
    assert furl != null;
    assert url != null;

    final String url2 = url.trim();
    final URL ret;

    if (url2.startsWith("http://") || (url2.startsWith("www"))) {
        ret = new URL(url2);
    } else {//from  w  w  w .j a v  a  2 s. c o  m
        if (url2.charAt(0) == '/') {
            ret = new URL(furl.getProtocol() + "://" + furl.getHost() + url2);
        } else {
            final String path0 = furl.getPath();
            final String path = path0.substring(0, path0.lastIndexOf('/'));
            ret = new URL(furl.getProtocol() + "://" + furl.getHost() + path + "/" + url2);
        }
    }
    return ret;
}

From source file:ai.baby.util.Parameter.java

public String toURL() {
    try {/* w ww  .  j  ava 2s . c o  m*/
        final URL url = new URL(parameterString.getObjectAsValid());
        final URI returnVal = new URI(url.getProtocol(), null, url.getHost(), 80, url.getPath(), url.getQuery(),
                null);
        return returnVal.toString();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.italiangrid.storm.webdav.authz.CopyMoveAuthzVoter.java

private StorageAreaInfo getSAFromPath(String destinationURL) throws MalformedURLException {

    URL url = new URL(destinationURL);

    String path = dropSlashWebdavFromPath(url.getPath());

    for (StorageAreaInfo sa : saConfig.getStorageAreaInfo()) {
        for (String ap : sa.accessPoints()) {
            if (path.startsWith(ap)) {
                return sa;
            }/*  w w w. j  av  a2s.c  o  m*/
        }
    }

    return null;
}

From source file:com.wealdtech.jetty.config.JettySslConfiguration.java

private String resolvePath(final String input) {
    String result = input;//from   ww w. j a  v  a2  s. c o  m
    if (!input.startsWith("/")) {
        // This is a relative path so look for the file in our resources are
        final URL resourceUrl = ResourceLoader.getResource(input);
        if (resourceUrl != null) {
            result = resourceUrl.getPath();
        }
    }
    LOGGER.debug("Resolved path from \"{}\" to \"{}\"", input, result);
    return result;
}

From source file:us.askplatyp.kb.lucene.wikimedia.rest.WikimediaREST.java

private URL getURLForPageAction(String action, String pageIRI) throws MalformedURLException {
    URL pageURL = new URL(pageIRI);
    return UriBuilder.fromUri("https://host/api/rest_v1/page/").host(pageURL.getHost())
            .segment(action, pageURL.getPath().replaceFirst("/wiki/", "")).queryParam("redirect", "false")
            .build().toURL();/*ww  w. j a va  2s  . co m*/
}

From source file:com.beyondjservlet.gateway.servlet.ProxyDetails.java

public ProxyDetails(boolean valid, String stringProxyURL, HttpProxyRule proxyRule) {
    this.valid = valid;
    this.stringProxyURL = stringProxyURL;
    this.proxyRule = proxyRule;

    int port = 0;
    String host = "";

    try {/*from  w  ww.j  a  v a2s  .c om*/
        URL url = new URL(stringProxyURL);
        proxyPath = url.getPath();
        protocol = url.getProtocol();
        proxyHostAndPort = url.getHost() + ":" + url.getPort();
    } catch (Exception e) {
        while (proxyHostAndPort.startsWith("/")) {
            proxyHostAndPort = proxyHostAndPort.substring(1);
        }
        host = proxyHostAndPort;
        int idx = indexOf(proxyHostAndPort, ":", "/");
        if (idx > 0) {
            host = proxyHostAndPort.substring(0, idx);
            String portText = proxyHostAndPort.substring(idx + 1);
            idx = portText.indexOf("/");
            if (idx >= 0) {
                proxyPath = portText.substring(idx);
                portText = portText.substring(0, idx);
            }

            if (StringUtils.isNotBlank(portText)) {
                // portText may be a port unless its default
                try {
                    port = Integer.parseInt(portText);
                    proxyHostAndPort = host + ":" + port;
                } catch (NumberFormatException ex) {
                    port = 80;
                    // we do not have a port, so proxyPath is the portText
                    proxyPath = "/" + portText + proxyPath;
                    proxyHostAndPort = host;
                }
            } else {
                proxyHostAndPort = host;
            }
        }
    }
}

From source file:com.cladonia.xngreditor.URLUtilities.java

public static String getPath(URL url) {
    String path = url.getPath();

    if (!path.endsWith("/")) {
        int index = path.lastIndexOf('/');

        if (index != -1) {
            path = path.substring(0, index);
        }//from  w w w .java 2  s .  c o  m
    }

    return path;
}

From source file:cn.vlabs.duckling.vwb.service.url.impl.UrlServiceImpl.java

@Override
public String getBasePath() {
    String basePath;//from  w ww  . jav a  2s. c om
    try {
        URL url = new URL(getBaseURL());
        basePath = url.getPath();
    } catch (MalformedURLException e) {
        basePath = "/dct";
    }
    return basePath;
}