List of usage examples for java.net URI getPath
public String getPath()
From source file:main.java.miro.validator.fetcher.RsyncFetcher.java
public String getRelativePath(URI uri) { return baseDirectory + uri.getHost() + uri.getPath(); }
From source file:com.aurel.track.util.PluginUtils.java
/** * Gets a file with a given path relativ to classes directory from the WEB-INF * @param url/*w w w .j a v a 2 s . c o m*/ * @return */ public static File getFileFromURL(URL url) { File file; if (url == null) { return null; } if (url.getPath() != null) { file = new File(url.getPath()); if (file.exists()) { //valid url return file; } } //valid file through URI? //see Bug ID: 4466485 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4466485) URI uri = null; try { //get rid of spaces uri = new URI(url.toString()); } catch (URISyntaxException e1) { } if (uri == null) { return null; } if (uri.getPath() != null) { file = new File(uri.getPath()); if (file.exists()) { return file; } } //back to URL from URI try { url = uri.toURL(); } catch (MalformedURLException e) { } if (url != null && url.getPath() != null) { file = new File(url.getPath()); if (file.exists()) { //valid url return file; } } return null; }
From source file:com.splunk.shuttl.archiver.archive.ArchiveConfigurationTest.java
public void getTmpDirectory_givenArchiverRootUri_pathIsAChildOfTheArchivingRootURI() { String archiverRoot = "valid:/uri/archiver/data"; when(mBean.getArchiverRootURI()).thenReturn(archiverRoot); URI tmpDirectory = createConfiguration().getTmpDirectory(); String tmpDirectoryName = FilenameUtils.getName(tmpDirectory.getPath()); URI expected = URI.create(archiverRoot + "/" + tmpDirectoryName); assertEquals(expected, tmpDirectory); }
From source file:com.gopivotal.cla.repository.RepositoryConfiguration.java
@Bean DataSource dataSource() {// w w w .j a v a 2 s. co m URI dbUri = URI.create(this.databaseUrl); String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); BoneCPDataSource dataSource = new BoneCPDataSource(); dataSource.setDriverClass(Driver.class.getCanonicalName()); dataSource.setJdbcUrl(dbUrl); String[] userInfoTokens = dbUri.getUserInfo().split(":"); dataSource.setUsername(userInfoTokens.length > 0 ? userInfoTokens[0] : ""); dataSource.setPassword(userInfoTokens.length > 1 ? userInfoTokens[1] : ""); dataSource.setMaxConnectionsPerPartition(2); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setLocations("META-INF/db/migration"); flyway.migrate(); return dataSource; }
From source file:org.mobicents.servlet.restcomm.cache.DiskCache.java
private String extension(final URI uri) { final String path = uri.getPath(); return path.substring(path.lastIndexOf(".") + 1); }
From source file:com.linkedin.d2.balancer.util.LoadBalancerClientCli.java
public static <T> PropertyStore<T> getStore(ZKConnection zkclient, String store, PropertySerializer<T> serializer) throws URISyntaxException, IOException, PropertyStoreException { URI storeUri = URI.create(store); if (storeUri.getScheme() != null) { if (storeUri.getScheme().equals("zk")) { ZooKeeperPermanentStore<T> zkStore = new ZooKeeperPermanentStore<T>(zkclient, serializer, storeUri.getPath()); startStore(zkStore);//from w ww. ja v a2 s .co m return zkStore; } else { throw new URISyntaxException(store, "Unable to parse store uri. Only zk and file stores are supported."); } } else { // assume it's a local file return new FileStore<T>(storeUri.getPath(), ".json", serializer); } }
From source file:kuona.jenkins.analyser.JenkinsClient.java
/** * Create an unauthenticated Jenkins HTTP client * * @param uri Location of the jenkins server (ex. http://localhost:8080) * @param defaultHttpClient Configured DefaultHttpClient to be used *//*w w w .j a va2s . c o m*/ public JenkinsClient(Project project, URI uri, DefaultHttpClient defaultHttpClient) { this.context = uri.getPath(); if (!context.endsWith("/")) { context += "/"; } this.uri = uri; this.project = project; this.client = defaultHttpClient; this.httpResponseValidator = new HttpResponseValidator(); }
From source file:de.betterform.connector.xmlrpc.XMLRPCSubmissionHandler.java
/** * Parses the URI into three elements.//from www. j a va 2 s . c om * The xmlrpc URL, the function and the params * * @return a Vector */ private Vector parseURI(URI uri) { String host = uri.getHost(); int port = uri.getPort(); String path = uri.getPath(); String query = uri.getQuery(); /* Split the path up into basePath and function */ int finalSlash = path.lastIndexOf('/'); String basePath = ""; if (finalSlash > 0) { basePath = path.substring(1, finalSlash); } String function = path.substring(finalSlash + 1, path.length()); String rpcURL = "http://" + host + ":" + port + "/" + basePath; log.debug("New URL = " + rpcURL); log.debug("Function = " + function); Hashtable paramHash = new Hashtable(); if (query != null) { String[] params = query.split("&"); for (int i = 0; i < params.length; i++) { log.debug("params[" + i + "] = " + params[i]); String[] keyval = params[i].split("="); log.debug("\t" + keyval[0] + " -> " + keyval[1]); paramHash.put(keyval[0], keyval[1]); } } Vector ret = new Vector(); ret.add(rpcURL); ret.add(function); ret.add(paramHash); return ret; }
From source file:com.ge.predix.acs.service.policy.admin.PolicyManagementController.java
@ApiOperation(value = "Creates/Updates a policy set for the given zone.", tags = { "Policy Set Management" }) @ApiResponses(value = {/*from w w w .jav a 2 s. c o m*/ @ApiResponse(code = 201, message = "Policy set creation successful. Policy set URI is returned in 'Location' header."), }) @RequestMapping(method = PUT, value = POLICY_SET_URL, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> createPolicySet(@RequestBody final PolicySet policySet, @PathVariable("policySetId") final String policySetId) { validatePolicyIdOrFail(policySet, policySetId); try { this.service.upsertPolicySet(policySet); URI policySetUri = UriTemplateUtils.expand(POLICY_SET_URL, "policySetId:" + policySet.getName()); return created(policySetUri.getPath()); } catch (PolicyManagementException e) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e.getMessage(), e); } }
From source file:kuona.client.JenkinsHttpClient.java
/** * Create an unauthenticated Jenkins HTTP client * * @param uri Location of the jenkins server (ex. http://localhost:8080) * @param defaultHttpClient Configured DefaultHttpClient to be used *///from w w w. ja v a2s . c o m public JenkinsHttpClient(Project project, URI uri, DefaultHttpClient defaultHttpClient) { this.context = uri.getPath(); if (!context.endsWith("/")) { context += "/"; } this.uri = uri; this.project = project; this.client = defaultHttpClient; this.httpResponseValidator = new HttpResponseValidator(); }