/** * Checks the syntax of the given URL. * * @param url The URL. * @return true, if valid. */ private boolean checkUrl(String url) { try { URI uri = new URI(url); return uri.isAbsolute(); } catch (URISyntaxException e) { return false; } } }
/** * Prepend a leading slash to given URI. * * @param uri URI to be modified. * @return URI with a leading slash prepended, if not absolute. */ private static URI slash(final URI uri) { final String strUri = uri.toString(); return (uri.isAbsolute() || strUri.charAt(0) == '/') ? uri : URI.create('/' + strUri); }
public URI getHarUri(URI original) throws URISyntaxException { URI relative = originalBase.relativize(original); if (relative.isAbsolute()) { throw new URISyntaxException("Could not create URI for location.", "Relative: " + relative + " Base: " + base + " OriginalBase: " + originalBase); } return base.resolve(relative); } }
Entry(String sourceId, JSONObject o, String baseURL) { this.sourceId = sourceId; this.name = Util.intern(o.getString("name")); this.version = Util.intern(o.getString("version")); // Trim this to prevent issues when the other end used Base64.encodeBase64String that added newlines // to the end in old commons-codec. Not the case on updates.jenkins-ci.org, but let's be safe. this.sha1 = Util.fixEmptyAndTrim(o.optString("sha1")); this.sha256 = Util.fixEmptyAndTrim(o.optString("sha256")); this.sha512 = Util.fixEmptyAndTrim(o.optString("sha512")); String url = o.getString("url"); if (!URI.create(url).isAbsolute()) { if (baseURL == null) { throw new IllegalArgumentException("Cannot resolve " + url + " without a base URL"); } url = URI.create(baseURL).resolve(url).toString(); } this.url = url; }
/** * Checks the correctness of the string representation of URI name. * The correctness is checked as pointed out in RFC 3280 p. 34. */ public static void checkURI(String uri) throws IOException { try { URI ur = new URI(uri); if (ur.getScheme() == null || ur.getRawSchemeSpecificPart().isEmpty()) { throw new IOException("No scheme or scheme-specific-part in uniformResourceIdentifier: " + uri); } if (!ur.isAbsolute()) { throw new IOException("Relative uniformResourceIdentifier: " + uri); } } catch (URISyntaxException e) { throw (IOException) new IOException("Bad representation of uniformResourceIdentifier: " + uri).initCause(e); } }
private String ensureRelativeUri( String mountPoint ) { try { URI result = new URI( mountPoint ); if ( result.isAbsolute() ) { return result.getPath(); } else { return result.toString(); } } catch ( URISyntaxException e ) { log.debug( "Unable to translate [%s] to a relative URI in ensureRelativeUri(String mountPoint)", mountPoint ); return mountPoint; } }
if (new URI(uri).isAbsolute()) { return uri; return new URI(parentUri).resolve(uri).toString(); } catch (URISyntaxException e) { return null;
private String getRealUrl(HttpContext httpContext){ Object target = httpContext.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); Object reqUri = httpContext.getAttribute(HttpCoreContext.HTTP_REQUEST); if (target==null||reqUri==null){ return null; } HttpHost t = (HttpHost) target; HttpUriRequest r = (HttpUriRequest)reqUri; return r.getURI().isAbsolute()?r.getURI().toString():t.toString()+r.getURI().toString(); } }
/** * Set input map path. * @param inputFile absolute input map path */ public void setInputFile(final URI inputFile) { assert inputFile.isAbsolute(); prop.put(PROPERTY_INPUT_MAP_URI, inputFile.toString()); // Deprecated since 2.1 if (inputFile.getScheme().equals("file")) { prop.put(PROPERTY_INPUT_MAP, new File(inputFile).getAbsolutePath()); } }
public static void deepCopyDocument(Document ttml, File target) throws IOException { try { 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); } }
/** * Set the concrete URI. * * @param uri the concrete URI (must not be {@code null}) * @return this builder */ public Builder setUri(final URI uri) { Assert.checkNotNullParam("uri", uri); final String fragment = uri.getFragment(); if (fragment != null && ! fragment.isEmpty()) { throw new IllegalArgumentException("Service URI " + uri + " may not have a fragment"); } if (! uri.isAbsolute()) { throw new IllegalArgumentException("Service URI " + uri + " must be absolute"); } final String query = uri.getQuery(); // sanitized URI try { this.uri = uri.isOpaque() ? new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null) : new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query != null && query.isEmpty() ? null : query, null); } catch (URISyntaxException e) { // should be impossible as the original URI was valid throw new IllegalStateException(e); } return this; }
/** * Resolve a target uri against a source. * * @param sourcePartUri * The source URI. * @param targetUri * The target URI. * @return The resolved URI. */ public static URI resolvePartUri(URI sourcePartUri, URI targetUri) { // log.info("source: " + sourcePartUri); // log.info("target: " + targetUri); URI uri; if (sourcePartUri == null || sourcePartUri.isAbsolute()) { throw new IllegalArgumentException("sourcePartUri"); } if (targetUri == null) { log.error("targetUri was null"); throw new IllegalArgumentException("targetUri"); } else if (targetUri.isAbsolute()) { log.error("targetUri " + targetUri.toString() + " is absolute!"); throw new IllegalArgumentException("targetUri"); } uri = sourcePartUri.resolve(targetUri); // log.info("RESULT: " + uri); return uri; }
public Builder overrideAbsolutesFromRequest( URI requestUri ) { // Find all default entries with absolute URIs and replace the corresponding host name entries with the one from the request uri. List<URIEntry> defaultEntries = entries.stream().filter( e -> e.uri.isAbsolute() && e.precedence == LOWEST ).collect( Collectors.toList() ); for ( URIEntry entry : defaultEntries ) { add( entry.key, entry.uri.getScheme(), requestUri.getHost(), entry.uri.getPort(), LOW ); } return this; }
location = new URI(locationString); if (!location.isAbsolute()) { location = baseUri.resolve(location.normalize());
public final URI makeAbsolute(URI uri) { if (uri.isAbsolute()) { return uri; } return URI.create(applicationProperties.getBaseUrl()).resolve(uri).normalize(); }
private URI buildUri( String uri ) { URI unprefixedUri = URI.create( uri ); if ( unprefixedUri.isAbsolute() ) { return unprefixedUri; } else { return URI.create( baseUri + uri ); } }
/** * Dump this URI to the log. * * @param description * @param dburi */ static void dump(String description, URI dburi) { String dumpString = String.format( "dump (%s)\n: isOpaque=%s, isAbsolute=%s Scheme=%s,\n SchemeSpecificPart=%s,\n Host=%s,\n Port=%s,\n Path=%s,\n Fragment=%s,\n Query=%s\n", description, dburi.isOpaque(), dburi.isAbsolute(), dburi.getScheme(), dburi.getSchemeSpecificPart(), dburi.getHost(), dburi.getPort(), dburi.getPath(), dburi.getFragment(), dburi.getQuery()); LOGGER.fine(dumpString); String query = dburi.getQuery(); if (null != query && !"".equals(query)) { String[] params = query.split("&"); Map<String, String> map = new HashMap<>(); for (String param : params) { String[] splits = param.split("="); String name = splits[0]; String value = null; if (splits.length > 1) { value = splits[1]; } map.put(name, value); LOGGER.fine(String.format("name=%s,value=%s\n", name, value)); } } // return map; }
@Override public InputStream fetch(URI source) throws IOException { URI relativeSourceUri = rootUri.relativize(source); if (!relativeSourceUri.isAbsolute()) { // Apply the redirect source = baseDirectoryUri.resolve(relativeSourceUri); } URIDownloader wrappedDownloader = downloaders.get(source.getScheme()); return wrappedDownloader.fetch(source); } };