List of usage examples for java.net URI isAbsolute
public boolean isAbsolute()
From source file:co.paralleluniverse.fibers.httpclient.FiberHttpClient.java
private static HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException { // A null target may be acceptable if there is a default target. // Otherwise, the null target is detected in the director. HttpHost target = null;/*from w w w .j ava 2 s. co m*/ final URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = URIUtils.extractHost(requestURI); if (target == null) throw new ClientProtocolException("URI does not specify a valid host name: " + requestURI); } return target; }
From source file:com.jtstand.swing.Main.java
public static URI resolve(String uristr, URI baseuri) { if (uristr.equals(".") || uristr.equals("this")) { return baseuri; }//from ww w .j a v a2s . c om URI uri = null; try { uri = new URI(uristr); } catch (URISyntaxException ex) { return null; } if (uri.isAbsolute()) { return uri; } return baseuri.resolve(uri); }
From source file:org.sonatype.nexus.repository.httpclient.FilteredHttpClient.java
private static HttpHost determineTarget(final HttpUriRequest request) throws ClientProtocolException { HttpHost target = null;// ww w. ja va 2s . c o m final URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = URIUtils.extractHost(requestURI); if (target == null) { throw new ClientProtocolException("URI does not specify a valid host name: " + requestURI); } } return target; }
From source file:cat.calidos.morfeu.model.injection.URIToParsedModule.java
@Produces @Named("FetchedRawContent") public static InputStream fetchedRawContent(@Named("FetchableContentURI") URI uri) throws FetchingException { // if uri is absolute we retrieve it, otherwise we assume it's a local relative file try {//from www . j a v a 2s. c o m if (uri.isAbsolute()) { log.info("Fetching absolute content uri '{}' to parse", uri); return IOUtils.toInputStream(IOUtils.toString(uri, Config.DEFAULT_CHARSET), Config.DEFAULT_CHARSET); } else { log.info("Fetching relative content uri '{}' to parse, assuming file", uri); return FileUtils.openInputStream(new File(uri.toString())); } } catch (IOException e) { log.error("Could not fetch '{}' ({}", uri, e); throw new FetchingException("Problem when fetching '" + uri + "'", e); } }
From source file:com.epam.reportportal.apache.http.impl.execchain.MinimalClientExec.java
static void rewriteRequestURI(final HttpRequestWrapper request, final HttpRoute route) throws ProtocolException { try {// www. j a v a 2s.c o m URI uri = request.getURI(); if (uri != null) { // Make sure the request URI is relative if (uri.isAbsolute()) { uri = URIUtils.rewriteURI(uri, null, true); } else { uri = URIUtils.rewriteURI(uri); } request.setURI(uri); } } catch (final URISyntaxException ex) { throw new ProtocolException("Invalid URI: " + request.getRequestLine().getUri(), ex); } }
From source file:org.yamj.api.common.http.HttpClientWrapper.java
protected static HttpHost determineTarget(HttpUriRequest request) throws ClientProtocolException { HttpHost target = null;// www . java2s.com URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { target = URIUtils.extractHost(requestURI); if (target == null) { throw new ClientProtocolException("URI does not specify a valid host name: " + requestURI); } } return target; }
From source file:org.apache.accumulo.start.classloader.AccumuloClassLoader.java
/** * Populate the list of URLs with the items in the classpath string *//*w ww .j a va 2 s . c om*/ @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "class path configuration is controlled by admin, not unchecked user input") private static void addUrl(String classpath, ArrayList<URL> urls) throws MalformedURLException { classpath = classpath.trim(); if (classpath.length() == 0) return; classpath = replaceEnvVars(classpath, System.getenv()); // Try to make a URI out of the classpath URI uri = null; try { uri = new URI(classpath); } catch (URISyntaxException e) { // Not a valid URI } if (uri == null || !uri.isAbsolute() || (uri.getScheme() != null && uri.getScheme().equals("file://"))) { // Then treat this URI as a File. // This checks to see if the url string is a dir if it expand and get all jars in that // directory final File extDir = new File(classpath); if (extDir.isDirectory()) urls.add(extDir.toURI().toURL()); else { if (extDir.getParentFile() != null) { File[] extJars = extDir.getParentFile() .listFiles((dir, name) -> name.matches("^" + extDir.getName())); if (extJars != null && extJars.length > 0) { for (File jar : extJars) urls.add(jar.toURI().toURL()); } else { log.debug("ignoring classpath entry {}", classpath); } } else { log.debug("ignoring classpath entry {}", classpath); } } } else { urls.add(uri.toURL()); } }
From source file:models.NotificationMail.java
/** * Make every link to be absolute and to have 'rel=noreferrer' if * necessary.//from w w w.j a va2s . c o m */ public static void handleLinks(Document doc) { String hostname = Config.getHostname(); String[] attrNames = { "src", "href" }; Boolean noreferrer = play.Configuration.root().getBoolean("application.noreferrer", false); for (String attrName : attrNames) { Elements tags = doc.select("*[" + attrName + "]"); for (Element tag : tags) { boolean isNoreferrerRequired = false; String uriString = tag.attr(attrName); if (noreferrer && attrName.equals("href")) { isNoreferrerRequired = true; } try { URI uri = new URI(uriString); if (!uri.isAbsolute()) { tag.attr(attrName, Url.create(uriString)); } if (uri.getHost() == null || uri.getHost().equals(hostname)) { isNoreferrerRequired = false; } } catch (URISyntaxException e) { play.Logger.info("A malformed URI is detected while" + " checking an email to send", e); } if (isNoreferrerRequired) { tag.attr("rel", tag.attr("rel") + " noreferrer"); } } } }
From source file:tds.itemrenderer.processing.ITSUrlResolver.java
/** * If the path is an absolute url, returns the path. * Otherwise, create a relative path given this webapp's context. * @see javax.servlet.ServletContext#getContextPath * * note: sanitizing path which may contain a leading tilda *///w ww . ja v a 2 s.c o m private static String resolveUrl(final String contextPath, final String path) { try { final URI uri = new URI(path); if (uri.isAbsolute()) { return path; } } catch (URISyntaxException e) { } if (StringUtils.isBlank(path)) { return String.format("%s/", contextPath); } else { String relativePath = StringUtils.removeStart(path, "~/"); relativePath = StringUtils.removeStart(relativePath, "/"); return String.format("%s/%s", contextPath, relativePath); } }
From source file:org.asynchttpclient.test.TestUtils.java
public static File resourceAsFile(String path) throws URISyntaxException, IOException { ClassLoader cl = TestUtils.class.getClassLoader(); URI uri = cl.getResource(path).toURI(); if (uri.isAbsolute() && !uri.isOpaque()) { return new File(uri); } else {//from ww w.j a v a2 s . c o m File tmpFile = File.createTempFile("tmpfile-", ".data", TMP_DIR); tmpFile.deleteOnExit(); try (InputStream is = cl.getResourceAsStream(path)) { FileUtils.copyInputStreamToFile(is, tmpFile); return tmpFile; } } }