UrlUtil { public static boolean isValid(String theUrl) { if (theUrl == null || theUrl.length() < 8) { return false; } String url = theUrl.toLowerCase(); if (url.charAt(0) != 'h') { return false; } if (url.charAt(1) != 't') { return false; } if (url.charAt(2) != 't') { return false; } if (url.charAt(3) != 'p') { return false; } int slashOffset; if (url.charAt(4) == ':') { slashOffset = 5; } else if (url.charAt(4) == 's') { if (url.charAt(5) != ':') { return false; } slashOffset = 6; } else { return false; } if (url.charAt(slashOffset) != '/') { return false; } if (url.charAt(slashOffset + 1) != '/') { return false; } return true; }  static String constructAbsoluteUrl(String theBase, String theEndpoint); static boolean isAbsolute(String theValue); static String constructRelativeUrl(String theParentExtensionUrl, String theExtensionUrl); static boolean isValid(String theUrl); static String unescape(String theString);  }
@Test public void testIsValid() { assertTrue(UrlUtil.isValid("http: assertTrue(UrlUtil.isValid("https: assertTrue(UrlUtil.isValid("HTTP: assertTrue(UrlUtil.isValid("HTTPS: assertFalse(UrlUtil.isValid("file: assertFalse(UrlUtil.isValid(": assertFalse(UrlUtil.isValid("http:/ss")); assertFalse(UrlUtil.isValid("http:/")); assertFalse(UrlUtil.isValid("http:")); assertFalse(UrlUtil.isValid("h")); assertFalse(UrlUtil.isValid("")); assertFalse(UrlUtil.isValid(null)); }