List of usage examples for java.net URI getPath
public String getPath()
From source file:org.eclipse.aether.transport.http.UriUtils.java
public static URI resolve(URI base, URI ref) { String path = ref.getRawPath(); if (path != null && path.length() > 0) { path = base.getRawPath();/*from www . j a va2s.c o m*/ if (path == null || !path.endsWith("/")) { try { base = new URI(base.getScheme(), base.getAuthority(), base.getPath() + '/', null, null); } catch (URISyntaxException e) { throw new IllegalStateException(e); } } } return URIUtils.resolve(base, ref); }
From source file:com.akamai.edgegrid.signer.EdgeGridV1Signer.java
private static String getRelativePathWithQuery(URI uri) { StringBuilder sb = new StringBuilder(uri.getPath()); if (uri.getQuery() != null) { sb.append("?").append(uri.getQuery()); }//from w w w. j a v a 2s. c o m return sb.toString(); }
From source file:net.sf.jasperreports.eclipse.wizard.project.ProjectUtil.java
/** * Deletes the content of a possible project. Also the project folder is * deleted./*from w w w . j a v a 2s . c o m*/ * * @param prjName * the project name */ public static void deleteProjectFolder(String prjName) { try { URI rootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocationURI(); URI prjLocation = new URI(rootLocation.getScheme(), null, Path.fromPortableString(rootLocation.getPath()).append(prjName).toString(), null); File prjDir = new File(prjLocation); if (prjDir.exists()) { FileUtils.deleteDirectory(prjDir); } } catch (URISyntaxException e) { JasperReportsPlugin.getDefault().logError(e); } catch (IOException e) { JasperReportsPlugin.getDefault().logError(e); } }
From source file:com.marklogic.contentpump.SingleDocumentWriter.java
protected static String getPathFromURI(DocumentURI uri) { String uriStr = uri.getUri(); try {// w w w. jav a 2 s .co m URI child = new URI(uriStr); String childPath; if (child.isOpaque()) { childPath = child.getSchemeSpecificPart(); } else { childPath = child.getPath(); } return childPath; } catch (Exception ex) { LOG.error("Error parsing URI " + uriStr + "."); return uriStr; } }
From source file:de.uniko.west.winter.core.serializing.JSONResultProcessor.java
private static Map<String, Set<Object>> convertJson2Map(JSONObject jsonResultObj) throws WinterException { JSONObject headObj = null;// w ww. ja va 2 s.c om JSONObject resultObj = null; JSONArray vars = null; JSONArray results = null; try { headObj = jsonResultObj.getJSONObject(KEY_HEAD); resultObj = jsonResultObj.getJSONObject(KEY_RESULTS); vars = headObj.getJSONArray(KEY_VARS); results = resultObj.getJSONArray(KEY_BINDINGS); if (headObj == null || resultObj == null || vars == null || results == null) { throw new NullPointerException("Essential elements in JSONObject are null!"); } } catch (Exception e) { throw new WinterException("Missing essential elements in JSON result object!", e); } Map<String, Set<Object>> bindingMap = new HashMap<String, Set<Object>>(); for (int j = 0; j < results.length(); j++) { for (int i = 0; i < vars.length(); i++) { Object value = null; String key = null; try { key = vars.getString(i); if (!bindingMap.containsKey(key)) { bindingMap.put(key, new HashSet<Object>()); } String valueString = results.getJSONObject(j).getJSONObject(key).getString("value"); String type = results.getJSONObject(j).getJSONObject(key).getString("type"); if (type.equalsIgnoreCase("uri")) { value = new URI(valueString); } else if (type.equalsIgnoreCase("literal")) { value = valueString; } else if (type.equalsIgnoreCase("typed-literal")) { URI typeURI = new URI(results.getJSONObject(j).getJSONObject(key).getString("datatype")); String datatype = ((String) typeURI.getPath() .substring(typeURI.getPath().lastIndexOf("/") + 1)).trim(); // Trying java primitives // creating new primitive wrapper object by using its constructor with String parameter // e.g. Integer: value = new Integer(valueString); value = Class .forName( "java.lang." + datatype.substring(0, 1).toUpperCase() + datatype.substring(1).toLowerCase(), true, ClassLoader.getSystemClassLoader()) .getConstructor(String.class).newInstance(valueString); } else { throw new WinterException("Wrong Type"); } } catch (Exception e) { e.printStackTrace(); } if (key != null && value != null) { bindingMap.get(key).add(value); } } } // remove entries with empty set for (int i = 0; i < bindingMap.size(); i++) { Object key = bindingMap.keySet().toArray()[i]; if (bindingMap.get(key).isEmpty()) { bindingMap.remove(key); i--; } } return bindingMap; }
From source file:com.ery.ertc.estorm.util.ToolUtil.java
public static String getPath(Path path) { try {//from ww w. ja v a 2s .c om URI aUri = new URI(path.toString()); return aUri.getPath(); } catch (URISyntaxException e) { return path.toString(); } }
From source file:org.onebusaway.io.client.test.UriAssert.java
/** * Check request for matching Uri./*from ww w.j a v a 2 s . co m*/ * * @param expectedUri The Uri the test should expect (query values are ignored, use * expectedQuery) * @param expectedQuery A Map of query key/values required to be in the Uri. * Use asterisk to require key, but ignore value. Order is irrelevant. * The list is not exhaustive, extra key/values are ignored. */ public static void assertUriMatch(URI expectedUri, Map<String, String> expectedQuery, URI actualUri) { assertEquals(expectedUri.getHost(), actualUri.getHost()); assertEquals(expectedUri.getScheme(), actualUri.getScheme()); assertEquals(expectedUri.getPath(), actualUri.getPath()); List<NameValuePair> actualParams = URLEncodedUtils.parse(actualUri, "UTF-8"); if (expectedQuery != null) { for (Map.Entry<String, String> entry : expectedQuery.entrySet()) { String expectedValue = entry.getValue(); String actualValue = null; // Find actual param for (NameValuePair pair : actualParams) { if (pair.getName().equalsIgnoreCase(entry.getKey())) { actualValue = pair.getValue(); } } if ("*".equals(expectedValue)) { assertNotNull("URI missing key \"" + entry.getKey() + "\"", actualValue); } else { assertEquals("URI mismatch on query key \"" + entry.getKey() + "\"", expectedValue, actualValue); } } } }
From source file:org.wrml.runtime.rest.RestUtils.java
public static final String getLastPathElement(final URI uri) { final String path = uri.getPath(); if (StringUtils.isEmpty(path)) { return path; }//from w w w .ja v a 2s .c o m String lastPathElement = StringUtils.substringAfterLast(path, "/"); lastPathElement = StringUtils.substringBefore(lastPathElement, "?"); return lastPathElement; }
From source file:eu.eubrazilcc.lvl.core.util.UrlUtils.java
/** * Gets the path part of an URI.// ww w . jav a 2s .co m * @param uri - input URI * @return the path part of the specified URI or an empty string if one does not exist. * @throws IllegalArgumentException If a malformed URI occurs. */ public static String getPath(final URI uri) { checkArgument(uri != null, "Uninitialized URI"); try { final URI nUri = uri.normalize(); final URL url = nUri.isAbsolute() ? nUri.toURL() : new URL(new URL("http://example.org/"), nUri.getPath()); return url.getPath(); } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed URI", e); } }
From source file:io.syndesis.rest.v1.handler.credential.CredentialHandler.java
static URI addFragmentTo(final URI uri, final CallbackStatus status) { try {//from ww w.j a va 2s . c om final String fragment = SERIALIZER.writeValueAsString(status); return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), fragment); } catch (JsonProcessingException | URISyntaxException e) { throw new IllegalStateException("Unable to add fragment to URI: " + uri + ", for state: " + status, e); } }