/** * Creates a new URI instance by parsing the given string {@code relative} * and resolves the created URI against the URI represented by this * instance. * * @param relative * the given string to create the new URI instance which has to * be resolved later on. * @return the created and resolved URI. */ public URI resolve(String relative) { return resolve(create(relative)); }
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); } }
if (new URI(uri).isAbsolute()) { return uri; return new URI(parentUri).resolve(uri).toString(); } catch (URISyntaxException e) { return null;
@GET @Produces(MediaType.TEXT_HTML) @Path("index.html") public String index(@Context HttpHeaders httpHeaders) throws IOException { final URL templateUrl = this.getClass().getResource("/swagger/index.html.template"); final String template = Resources.toString(templateUrl, StandardCharsets.UTF_8); final Map<String, Object> model = ImmutableMap.of( "baseUri", RestTools.buildExternalUri(httpHeaders.getRequestHeaders(), httpConfiguration.getHttpExternalUri()).resolve(HttpConfiguration.PATH_API).toString()); return templateEngine.transform(template, model); }
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; }
/** * Resolves a URI reference against a base URI. Work-around for bug in * java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>) * * @param baseURI the base URI * @param reference the URI reference * @return the resulting URI */ public static URI resolve(final URI baseURI, URI reference){ if (baseURI == null) { throw new IllegalArgumentException("Base URI may nor be null"); } if (reference == null) { throw new IllegalArgumentException("Reference URI may nor be null"); } boolean emptyReference = reference.toString().length() == 0; if (emptyReference) { reference = URI.create("#"); } URI resolved = baseURI.resolve(reference); if (emptyReference) { String resolvedString = resolved.toString(); resolved = URI.create(resolvedString.substring(0, resolvedString.indexOf('#'))); } return resolved; }
public static URI resolve(URI base, String child) throws URISyntaxException URI childUri = new URI(child); URI ruri = base.resolve(childUri); if (childUri.equals(ruri) && !childUri.isAbsolute() && (base.getScheme().equals("jar") || base.getScheme().equals("zip"))) { String r = base.toString(); int lastslash = r.lastIndexOf('/'); r = r.substring(0,lastslash) + "/" + childUri; return URI.create(r); if (base.getPath().startsWith("//") && !ruri.getPath().startsWith("//")) String path = "///".concat(ruri.getPath()); try ruri = new URI("file", null, path, ruri.getQuery(), ruri.getFragment());
URI fragmentURI; try { fragmentURI = new URI(null, null, fragment); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid fragment: " + fragment + " in path: " + path); URI id = (parent == null || parent.getId() == null) ? URI.create(path) : parent.getId().resolve(path); String stringId = id.toString(); if (stringId.endsWith("#")) { try { id = new URI(stripEnd(stringId, "#")); } catch (URISyntaxException e) { throw new IllegalArgumentException("Bad path: " + stringId);
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); } }
private static String relativize(String relative, URI base) throws URISyntaxException { URI newUri; if (base.getPath().isEmpty()) { String uriString = base.toString(); int index = uriString.lastIndexOf('/'); newUri = new URI(uriString.substring(0, index + 1) + relative); } else { newUri = base.resolve(relative); } return toNormalizedURI(newUri); }
/** * 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; }
location = new URI(locationString); if (!location.isAbsolute()) { location = baseUri.resolve(location.normalize());
protected static List<byte[]> extractImages(Document ttml) throws XPathExpressionException, URISyntaxException, IOException { XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile("//*/@backgroundImage"); NodeList nl = (NodeList) expr.evaluate(ttml, XPathConstants.NODESET); LinkedHashMap<String, String> internalNames2Original = new LinkedHashMap<String, String>(); int p = 1; for (int i = 0; i < nl.getLength(); i++) { Node bgImageNode = nl.item(i); String uri = bgImageNode.getNodeValue(); String ext = uri.substring(uri.lastIndexOf(".")); String internalName = internalNames2Original.get(uri); if (internalName == null) { internalName = "urn:mp4parser:" + p++ + ext; internalNames2Original.put(internalName, uri); } bgImageNode.setNodeValue(internalName); } List<byte[]> images = new ArrayList<byte[]>(); if (!internalNames2Original.isEmpty()) { for (Map.Entry<String, String> internalName2Original : internalNames2Original.entrySet()) { URI pic = new URI(ttml.getDocumentURI()).resolve(internalName2Original.getValue()); images.add(streamToByteArray(pic.toURL().openStream())); } } return images; }
public MenuItem withUrl(String url) { try { this.url = new URI(Stapler.getCurrentRequest().getRequestURI()).resolve(new URI(url)).toString(); } catch (URISyntaxException x) { throw new IllegalArgumentException("Bad URI from " + Stapler.getCurrentRequest().getRequestURI() + " vs. " + url, x); } return this; }
/** * Resolve a child path against a parent path. * * @param parent * the parent path * @param child * the child path */ public Path(Path parent, Path child) { // Add a slash to parent's path so resolution is compatible with URI's URI parentUri = parent.uri; final String parentPath = parentUri.getPath(); if (!(parentPath.equals("/") || parentPath.equals(""))) { try { parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(), parentUri.getPath() + "/", null, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } if (child.uri.getPath().startsWith(Path.SEPARATOR)) { child = new Path(child.uri.getScheme(), child.uri.getAuthority(), child.uri.getPath().substring(1)); } final URI resolved = parentUri.resolve(child.uri); initialize(resolved.getScheme(), resolved.getAuthority(), normalizePath(resolved.getPath())); }
URI systemUri = new URI(systemId); if (!systemUri.isAbsolute() && !systemUri.isOpaque()) { URI baseUri = new URI(this.systemId); systemUri = baseUri.resolve(systemUri); systemId = systemUri.toString();