/** * Resolves a URI reference against a base URI. Work-around for bugs in * java.net.URI (e.g. <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, final URI reference){ Args.notNull(baseURI, "Base URI"); Args.notNull(reference, "Reference URI"); URI ref = reference; final String s = ref.toString(); if (s.startsWith("?")) { return resolveReferenceStartingWithQueryString(baseURI, ref); } final boolean emptyReference = s.length() == 0; if (emptyReference) { ref = URI.create("#"); } URI resolved = baseURI.resolve(ref); if (emptyReference) { final String resolvedString = resolved.toString(); resolved = URI.create(resolvedString.substring(0, resolvedString.indexOf('#'))); } return normalizeSyntax(resolved); }