List of usage examples for java.net URI getPath
public String getPath()
From source file:com.shazam.fork.reporter.gradle.JenkinsDownloader.java
@Nonnull private URL getArtifactUrl(Build build, Artifact artifact) { try {/*from ww w . j av a 2s.c o m*/ URI uri = new URI(build.getUrl()); String artifactPath = uri.getPath() + "artifact/" + artifact.getRelativePath(); URI artifactUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), artifactPath, "", ""); return artifactUri.toURL(); } catch (URISyntaxException | MalformedURLException e) { throw new GradleException("Error when trying to construct artifact URL for: " + build.getUrl(), e); } }
From source file:org.trustedanalytics.user.invite.EmailOrgUserInvitationService.java
private String getEmailHtml(String username) { final Context ctx = new Context(); ctx.setVariable("serviceName", "Trusted Analytics"); ctx.setVariable("username", username); URI authorizationUrl = URI.create(authorizationHost); String resetPasswordUrl = authorizationUrl.toString().replaceAll(authorizationUrl.getPath(), "/forgot_password"); ctx.setVariable("resetPasswordUrl", resetPasswordUrl); ctx.setVariable("consoleUrl", getConsoleUrl()); return templateEngine.process("invite_org", ctx); }
From source file:beadsan.AppConfig.java
@ConfigurationProperties("spring.datasource") @Bean(destroyMethod = "close") DataSource realDataSource() throws URISyntaxException { String url;//from w w w .j a v a 2 s .co m String username; String password; String databaseUrl = System.getenv("DATABASE_URL"); if (databaseUrl != null) { URI dbUri = new URI(databaseUrl); url = "jdbc:postgresql://" + dbUri.getHost() + ":" + dbUri.getPort() + dbUri.getPath(); username = dbUri.getUserInfo().split(":")[0]; password = dbUri.getUserInfo().split(":")[1]; } else { url = this.properties.getUrl(); username = this.properties.getUsername(); password = this.properties.getPassword(); } DataSourceBuilder factory = DataSourceBuilder.create(this.properties.getClassLoader()).url(url) .username(username).password(password); this.dataSource = factory.build(); return this.dataSource; }
From source file:de.vandermeer.skb.datatool.commons.DataUtilities.java
/** * Loads an data for an SKB link./* w w w. j a v a 2s.c o m*/ * @param skbLink the link to load an data for * @param loadedTypes loaded types as lookup for links * @return an object if successfully loaded, null otherwise * @throws IllegalArgumentException if any of the required arguments or map entries are not set or empty * @throws URISyntaxException if creating a URI for an SKB link failed */ public static Object loadLink(Object skbLink, LoadedTypeMap loadedTypes) throws URISyntaxException { if (skbLink == null) { throw new IllegalArgumentException("skb link null"); } if (loadedTypes == null) { throw new IllegalArgumentException("trying to load a link, but no loaded types given"); } URI uri = new URI(skbLink.toString()); if (!"skb".equals(uri.getScheme())) { throw new IllegalArgumentException("unknown scheme in link <" + skbLink + ">"); } String uriReq = uri.getScheme() + "://" + uri.getAuthority(); DataEntryType type = null; for (DataEntryType det : loadedTypes.keySet()) { if (uriReq.equals(det.getLinkUri())) { type = det; break; } } if (type == null) { throw new IllegalArgumentException( "no data entry type for link <" + uri.getScheme() + "://" + uri.getAuthority() + ">"); } @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) loadedTypes.getTypeMap(type); if (map == null) { throw new IllegalArgumentException("no entry for type <" + type.getType() + "> in link map"); } String key = StringUtils.substringAfterLast(uri.getPath(), "/"); Object ret = map.get(key); if (ret == null) { throw new IllegalArgumentException( "no entry for <" + uri.getAuthority() + "> key <" + key + "> in link map"); } return ret; }
From source file:com.splunk.shuttl.archiver.archive.ArchiveConfigurationTest.java
public void getTmpDirectory_givenArchiverRootUri_pathIsNotWithingetArchiverRoot() { when(mBean.getArchiverRootURI()).thenReturn("valid:/uri/archiver/data"); ArchiveConfiguration configuration = createConfiguration(); URI archivingRoot = configuration.getArchivingRoot(); URI tmpDirectory = configuration.getTmpDirectory(); assertFalse(tmpDirectory.getPath().contains(archivingRoot.getPath())); }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
private boolean isDifferentPage(URI url, URI nextUrl) throws IOException { return nextUrl.getPath() != null && !nextUrl.getPath().equals(url.getPath()); }
From source file:com.github.brandtg.pantopod.crawler.FileBasedCrawlingEventHandler.java
@Override protected void markError(URI url, int errorCode) throws IOException { File outputRoot = new File(outputDir, url.getHost() + File.separator + url.getPath()); FileUtils.forceMkdir(outputRoot);/*from ww w . ja v a 2 s . c om*/ File errFile = new File(outputRoot, ERR_FILE); if (!errFile.exists()) { try (OutputStream os = new FileOutputStream(errFile)) { IOUtils.write(String.valueOf(errorCode).getBytes(), os); } } }
From source file:com.github.brandtg.pantopod.crawler.FileBasedCrawlingEventHandler.java
@Override protected boolean handleData(URI url, byte[] data) throws IOException { File outputRoot = new File(outputDir, url.getHost() + File.separator + url.getPath()); FileUtils.forceMkdir(outputRoot);/*w w w. ja va 2s . c o m*/ File outputData = new File(outputRoot, DAT_FILE); if (!outputData.exists()) { try (OutputStream os = new FileOutputStream(outputData)) { IOUtils.write(data, os); LOG.info("Wrote {}", outputRoot); } return true; } return false; }
From source file:org.mulgara.scon.Connection.java
/** * Encodes a URI if it looks like it needs it. * @param u The URI to encode, if needed. * @return a minimally encoded URI.//ww w . j a va2 s .c o m */ private static final String enc(URI u) { try { // if there is no query, then just return the unencoded URI String query = u.getRawQuery(); if (query == null) return u.toString(); // encode the query, and add it to the end of the URI String encQuery = encode(query); String encU = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), encQuery, u.getFragment()).toString(); // if the partial encoding works, then return it if (decode(encU).equals(u.toString())) return encU; // nothing else worked, so encode it fully return encode(u.toString()); } catch (URISyntaxException e) { throw new IllegalArgumentException("Unable to encode a URI", e); } }
From source file:Fetch5.java
public boolean matches(URI uri) { if (hasExpired()) { return false; }/*from w w w . java2s . c om*/ String path = uri.getPath(); if (path == null) { path = "/"; } return path.startsWith(this.path); }