List of usage examples for java.net URI getPath
public String getPath()
From source file:Main.java
public static void printURIDetails(URI uri) { System.out.println("URI:" + uri); System.out.println("Normalized:" + uri.normalize()); String parts = "[Scheme=" + uri.getScheme() + ", Authority=" + uri.getAuthority() + ", Path=" + uri.getPath() + ", Query:" + uri.getQuery() + ", Fragment:" + uri.getFragment() + "]"; System.out.println(parts);/*from w w w . j a v a 2 s . c om*/ System.out.println(); }
From source file:fr.dutra.confluence2wordpress.util.UrlUtils.java
/** * Extracts the URL part relative to Confluence's root URL, given a variety of input formats, e.g.: * <ol>/*w ww.ja v a 2 s. com*/ * <li><code>/confluence/download/attachments/983042/image.png?version=1&modificationDate=1327402370523</code> (image)</li> * <li><code>/confluence/download/thumbnails/983042/image.png</code> (thumbnail)</li> * <li><code>http://localhost:1990/confluence/download/attachments/983042/image.png</code> (image)</li> * <li><code>/confluence/download/attachments/983042/pom.xml?version=1&modificationDate=1327402370710</code> (attachment)</li> * <li><code>/confluence/download/attachments/983042/armonia.png?version=1&modificationDate=1327402370523</code> (image as attachment)</li> * </ol> */ public static String extractConfluenceRelativePath(String url, String confluenceRootUrl) { try { URL context = new URL(confluenceRootUrl); URL absolute = new URL(context, url); URI relative = context.toURI().relativize(absolute.toURI()); URI confluencePath = ROOT.resolve(relative); return confluencePath.getPath(); } catch (MalformedURLException e) { return url; } catch (URISyntaxException e) { return url; } }
From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilder.java
public static <T> ResponseEntity<T> created(final boolean noContent, final String uriTemplate, final String... keyValues) { URI resourceUri = UriTemplateUtils.expand(uriTemplate, keyValues); return created(resourceUri.getPath(), noContent); }
From source file:com.jaeksoft.searchlib.util.LinkUtils.java
public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList, boolean removeFragment) { if (href == null) return null; href = href.trim();/*w ww . ja v a 2s .c o m*/ if (href.length() == 0) return null; String fragment = null; try { URI u = URIUtils.resolve(currentURL.toURI(), href); href = u.toString(); href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList); URI uri = URI.create(href); uri = uri.normalize(); String p = uri.getPath(); if (p != null) if (p.contains("/./") || p.contains("/../")) return null; if (!removeFragment) fragment = uri.getRawFragment(); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), fragment).normalize().toURL(); } catch (MalformedURLException e) { Logging.info(e.getMessage()); return null; } catch (URISyntaxException e) { Logging.info(e.getMessage()); return null; } catch (IllegalArgumentException e) { Logging.info(e.getMessage()); return null; } }
From source file:edu.tum.cs.mylyn.provisioning.git.GitProvisioningUtil.java
public static String getProjectName(URIish cloneUri) { if (cloneUri != null) { try {/*from w w w . j a v a 2s. c om*/ URI uri = new URI(cloneUri.toString()); String path = uri.getPath(); String projectName = path.substring(path.lastIndexOf('/') + 1); if (projectName.length() == 0) { path = path.substring(0, path.length() - 1); projectName = path.substring(path.lastIndexOf('/') + 1); } if (projectName.length() < 4) { return GitProvisioningUtil.getProjectNameFallback(cloneUri); } return projectName; } catch (URISyntaxException e) { return GitProvisioningUtil.getProjectNameFallback(cloneUri); } } return GitProvisioningUtil.getProjectNameFallback(cloneUri); }
From source file:com.ibm.jaggr.core.util.PathUtil.java
/** * Returns the module name for the specified URI. This is the name part of * the URI with path information removed, and with the .js extension removed * if present./*from w w w.j a v a2 s . co m*/ * * @param uri * the uri to return the name for * @return the module name */ public static String getModuleName(URI uri) { String name = uri.getPath(); if (name.endsWith("/")) { //$NON-NLS-1$ name = name.substring(0, name.length() - 1); } int idx = name.lastIndexOf("/"); //$NON-NLS-1$ if (idx != -1) { name = name.substring(idx + 1); } if (name.endsWith(".js")) { //$NON-NLS-1$ name = name.substring(0, name.length() - 3); } return name; }
From source file:com.cooksys.httpserver.ParsedHttpRequest.java
public static ParsedHttpRequest parseHttpRequest(HttpRequest request, String messageBody) { ParsedHttpRequest parsedRequest = new ParsedHttpRequest(); parsedRequest.requestLine = request.getRequestLine().toString(); parsedRequest.method = request.getRequestLine().getMethod(); try {//from w w w . ja v a 2 s . c o m //Parse the URI URI uri = new URI(request.getRequestLine().getUri()); parsedRequest.uriPath = uri.getPath(); parsedRequest.uriParams = parseUrlParameters(uri); parsedRequest.headers = (parseHeaders(request)); parsedRequest.messageBody = messageBody; } catch (URISyntaxException | ParseException ex) { Logger.getLogger(ParsedHttpRequest.class.getName()).log(Level.SEVERE, null, ex); } return parsedRequest; }
From source file:com.atlassian.jira.rest.client.TestUtil.java
public static String getLastPathSegment(URI uri) { final String path = uri.getPath(); final int index = path.lastIndexOf('/'); if (index == -1) { return path; }/*from w w w . ja v a 2s .c om*/ if (index == path.length()) { return ""; } return path.substring(index + 1); }
From source file:org.apache.sling.testing.clients.util.HttpUtils.java
/** * Get the first 'Location' header and verify it's a valid URI. * * @param response HttpResponse the http response * @return the location path//from ww w . jav a 2 s .c o m * @throws ClientException never (kept for uniformity) */ public static String getLocationHeader(HttpResponse response) throws ClientException { if (response == null) throw new ClientException("Response must not be null!"); String locationPath = null; Header locationHeader = response.getFirstHeader("Location"); if (locationHeader != null) { String location = locationHeader.getValue(); URI locationURI = URI.create(location); locationPath = locationURI.getPath(); } if (locationPath == null) { throw new ClientException("not able to determine location path"); } return locationPath; }
From source file:com.aliyun.odps.volume.VolumeFSUtil.java
/** * Probe for a path being a parent of another * /* w w w . j av a2s .c om*/ * @param parent parent path * @param child possible child path * @return true if the parent's path matches the start of the child's */ public static boolean isParentOf(Path parent, Path child) { URI parentURI = parent.toUri(); String parentPath = parentURI.getPath(); if (!parentPath.endsWith("/")) { parentPath += "/"; } URI childURI = child.toUri(); String childPath = childURI.getPath(); return childPath.startsWith(parentPath); }