URIUtil { public static boolean isValidURIReference(String uriRef) { boolean valid = !unicodeControlCharPattern.matcher(uriRef).matches(); if (valid) { final String escaped = escapeExcludedChars(uriRef); try { final java.net.URI uri = new java.net.URI(escaped); valid = uri.isAbsolute(); } catch (URISyntaxException e) { valid = false; } } return valid; }  static int getLocalNameIndex(String uri); static boolean isCorrectURISplit(String namespace, String localName); static boolean isValidURIReference(String uriRef);  }
@Test public void testIsValidURIReference() throws Exception { assertTrue(URIUtil.isValidURIReference("http: assertTrue("whitespace should be allowed", URIUtil.isValidURIReference("http: assertTrue("unwise chars should be allowed", URIUtil.isValidURIReference("http: assertTrue("query params in single quotes should be allowed", URIUtil.isValidURIReference("http: assertTrue("query params in double quotes should be allowed", URIUtil.isValidURIReference("http: assertTrue("short simple urns should be allowed", URIUtil.isValidURIReference("urn:p1")); assertTrue("Escaped special char should be allowed", URIUtil.isValidURIReference("http: assertTrue("fragment identifier should be allowed", URIUtil.isValidURIReference("http: assertTrue("Unescaped special char should be allowed", URIUtil.isValidURIReference("http: assertFalse("control char should not be allowed", URIUtil.isValidURIReference("http: assertFalse("relative uri should fail", URIUtil.isValidURIReference("foo/bar/")); assertFalse("single column is not a valid uri", URIUtil.isValidURIReference(":")); assertTrue("reserved char is allowed in non-conflicting spot", URIUtil.isValidURIReference("http: assertFalse("reserved char should not be allowed in conflicting spot", URIUtil.isValidURIReference("http;: }
@Test public void controlCharacterInURI() { assertFalse("URI containing Unicode control char should be invalid", URIUtil.isValidURIReference("http: }