@Test public void testValid() { for (final String sValid : VALID1) assertTrue("Expected '" + sValid + "' to be valid", URLValidator.isValid(sValid)); for (final String sValid : VALID2) assertTrue("Expected '" + sValid + "' to be valid", URLValidator.isValid(sValid)); for (final String sInvalid : INVALID) assertFalse("Expected '" + sInvalid + "' to be invalid", URLValidator.isValid(sInvalid)); }
protected ModuleSource loadFromActualUri(URI uri, URI base, Object validator) throws IOException { final URL url = uri.toURL(); final long request_time = System.currentTimeMillis(); final URLConnection urlConnection = openUrlConnection(url); final URLValidator applicableValidator; if (validator instanceof URLValidator) { final URLValidator uriValidator = ((URLValidator) validator); applicableValidator = uriValidator.appliesTo(uri) ? uriValidator : null; } else { applicableValidator = null; } if (applicableValidator != null) { applicableValidator.applyConditionals(urlConnection); } try { urlConnection.connect(); if (applicableValidator != null && applicableValidator.updateValidator( urlConnection, request_time, urlConnectionExpiryCalculator)) { close(urlConnection); return NOT_MODIFIED; } return new ModuleSource( getReader(urlConnection), getSecurityDomain(urlConnection), uri, base, new URLValidator(uri, urlConnection, request_time, urlConnectionExpiryCalculator)); } catch (FileNotFoundException e) { return null; } catch (RuntimeException e) { close(urlConnection); throw e; } catch (IOException e) { close(urlConnection); throw e; } }