List of usage examples for java.net URI isAbsolute
public boolean isAbsolute()
From source file:Main.java
public static void main(String[] args) throws NullPointerException, URISyntaxException { URI uri = new URI("http://www.java2s.com"); System.out.println("URI : " + uri); System.out.println(uri.isAbsolute()); }
From source file:eu.planets_project.services.utils.DigitalObjectUtils.java
/** * These cases: <br/>// ww w.ja v a2 s .c o m * - A compound DO, zip as Content, with MD outside the zip, pointing into * it via Title. This is to pass between services.<br/> * - A zip file containing CDO, MD inside the zip, pointing to the binaries * via the Title. This is an pure file 'IP', in effect.<br/> * - A compound DO, pulled from such a CDO zip file, with inputstreams for * content. Okay, two formats, different contexts and packing/unpacking * options.<br/> * - (CDO[zip] or CDO) i.e. If no Content, look up to root and unpack?<br/> * - DOIP - a special ZIP file containing CDOs. <br/> * Operations:<br/> * - Packing one or more CDOs into a DOIP, optionally embedding referenced * resources. (Value) resources always to be embedded.<br/> * - Unpacking a DOIP and getting N CDOs out, optionally embedding binaries, * using ZipInputStreams, or unpacking into Files?<br/> * TODO Should DO use URI internally got Content.reference, to allow * relative resolution? */ public static void main(String args[]) { try { URI uri = new URI("FAQ.html"); System.out.println("Got " + uri); System.out.println("Got " + uri.isAbsolute()); uri = new URI("http://localhost/FAQ.html"); System.out.println("Got " + uri); System.out.println("Got " + uri.isAbsolute()); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.streams.util.schema.UriUtil.java
/** * resolve a remote schema safely./* ww w .j a v a 2 s. c o m*/ * @param absolute root URI * @param relativePart relative to root * @return URI if resolvable, or Optional.absent() */ public static Optional<URI> safeResolve(URI absolute, String relativePart) { if (!absolute.isAbsolute()) { return Optional.empty(); } try { return Optional.of(absolute.resolve(relativePart)); } catch (IllegalArgumentException ex) { return Optional.empty(); } }
From source file:Main.java
public static void deepCopyDocument(Document ttml, File target) throws IOException { try {/*from w w w. j a va 2 s . c o m*/ XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile("//*/@backgroundImage"); NodeList nl = (NodeList) expr.evaluate(ttml, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) { Node backgroundImage = nl.item(i); URI backgroundImageUri = URI.create(backgroundImage.getNodeValue()); if (!backgroundImageUri.isAbsolute()) { copyLarge(new URI(ttml.getDocumentURI()).resolve(backgroundImageUri).toURL().openStream(), new File(target.toURI().resolve(backgroundImageUri).toURL().getFile())); } } copyLarge(new URI(ttml.getDocumentURI()).toURL().openStream(), target); } catch (XPathExpressionException e) { throw new IOException(e); } catch (URISyntaxException e) { throw new IOException(e); } }
From source file:com.omnigon.aem.common.utils.url.SlingUrlBuilder.java
public static SlingUrlBuilder create(final String uri) { if (StringUtils.isNotBlank(uri)) { try {// w w w . j a va 2s .c o m URI u = URLUtils.createURI(uri); String path = u.getPath(); if (u.isAbsolute() || StringUtils.isBlank(path)) { return new AbsoluteUrlBuilder(u.toASCIIString()); } else { if (!StringUtils.startsWith(path, "/")) { path = "/" + path; } return create(new PathInfo(path)); } } catch (Exception e) { LOG.error(e.getMessage(), e); } } return new NullUrlBuilder(); }
From source file:com.microsoft.gittf.core.util.URIUtil.java
/** * Converts the specified string into a valid server URI. The method will * update the URI if needed when connecting to the hosted service, to make * sure that the connection is HTTPS and is to the default collection * /*from w w w .ja v a2 s . c o m*/ * @param serverURIString * the uri string to convert * @return * @throws Exception */ public static URI getServerURI(final String serverURIString) throws Exception { try { URI uri = new URI(serverURIString); if (!uri.isAbsolute() || uri.isOpaque()) { uri = null; } if (uri != null) { uri = updateIfNeededForHostedService(uri); } if (uri == null) { throw new Exception(Messages.formatString("URIUtil.InvalidURIFormat", serverURIString)); //$NON-NLS-1$ } return uri; } catch (Exception e) { log.warn("Could not parse URI", e); //$NON-NLS-1$ } throw new Exception(Messages.formatString("URIUtil.InvalidURIFormat", serverURIString)); //$NON-NLS-1$ }
From source file:org.yamj.core.tools.web.PoolingHttpClient.java
private static HttpHost determineTarget(HttpUriRequest request) throws ClientProtocolException { HttpHost target = null;/*from w w w .j av a 2 s . co m*/ 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.seajas.search.utilities.web.WebResourceLocators.java
/** * Gets a resource locator. The optional base URIs are used to resolve relative paths in order of appearance. * // w w w .ja v a2 s . com * @param uri * the serialized form. * @param baseURIs * the serialized forms. * @throws URISyntaxException * when all interpretation attempts have failed. */ public static URI parseURI(final String uri, final String... baseURIs) throws URISyntaxException { URI result = parseURI(uri); if (!result.isAbsolute() && baseURIs != null) { for (String base : baseURIs) { try { result = parseURI(base).resolve(result); if (result.isAbsolute()) break; } catch (URISyntaxException e) { if (logger.isDebugEnabled()) logger.debug(String.format("Skipping unparseable base URI %s for %s", base, uri), e); } } } return result; }
From source file:com.vaadin.sass.testcases.scss.W3ConformanceTests.java
protected static Collection<URI> scrapeIndexForTests(String url, String regexp, int maxTests, Collection<URI> excludeUrls) throws Exception { URI baseUrl = new URI(url); Document doc = Jsoup.connect(url).timeout(10000).get(); Elements elems = doc.select(String.format("a[href~=%s]", regexp)); LinkedHashSet<URI> tests = new LinkedHashSet<URI>(); for (Element e : elems) { URI testUrl = new URI(e.attr("href")); if (!testUrl.isAbsolute()) { testUrl = baseUrl.resolve(testUrl); }/* w ww . j a v a2 s . c om*/ if (tests.size() < maxTests) { if (!excludeUrls.contains(testUrl)) { tests.add(testUrl); } } else { break; } } return tests; }
From source file:com.seajas.search.utilities.web.WebFeeds.java
private static void ensureResourceIdentification(SyndEntry entry, SyndFeed feed) throws FeedException { try {// w w w . ja va2s .co m String uri = entry.getLink(); if (!StringUtils.hasText(uri)) uri = entry.getUri(); boolean generated = false; if (!StringUtils.hasText(uri)) { logger.debug("Entry has no resource identification"); int position = feed.getEntries().indexOf(entry); if (position < 0) uri = "#hash-" + entry.hashCode(); else uri = "#entry-" + position; generated = true; } URI parsed = WebResourceLocators.parseURI(uri, feed.getLink(), feed.getUri()); if (!parsed.isAbsolute()) { if (generated) throw new FeedException("No resource identification available"); else throw new FeedException("Relative resource: " + parsed); } uri = parsed.toASCIIString(); entry.setLink(uri); if (!StringUtils.hasText(entry.getUri())) entry.setUri(uri); } catch (URISyntaxException e) { throw new FeedException("Can't resolve resource", e); } }