@Test public void testOrigin() { Origin.parse("http: assertTrue(Origin.isValid("http: Origin.parse("http: assertTrue(Origin.isValid("http: Origin.parse("http: assertTrue(Origin.isValid("http: Origin.parse("http: assertTrue(Origin.isValid("http: }
private Origin(String protocol, String host, String port, String resource) { String defaultPort; switch (protocol.toLowerCase()) { case "ftp": this.protocol = protocol; defaultPort = DEFAULT_FTP_PORT; break; case "http": this.protocol = protocol; defaultPort = DEFAULT_HTTP_PORT; break; case "https": this.protocol = protocol; defaultPort = DEFAULT_HTTPS_PORT; break; default: throw new IllegalStateException("Unsupported protocol: " + protocol); } if (host == null) { throw new IllegalStateException("Null host not allowed"); } boolean ipv6 = false; for (int i = 0; i < host.length(); i++) { char c = host.charAt(i); switch (c) { case '[': if (i == 0) { ipv6 = true; } else { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ']': if (!ipv6 || i != host.length() - 1) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ':': if (!ipv6) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; default: if (!Character.isLetterOrDigit(c) && c != '.' && c != '-') { throw new IllegalStateException("Illegal character in hostname: " + host); } break; } } this.host = host; if (port != null) { for (int i = 0; i < port.length(); i++) { char c = port.charAt(i); if (!Character.isDigit(c)) { throw new IllegalStateException("Illegal character in port: " + port); } } this.port = Integer.parseInt(port); } else { this.port = Integer.parseInt(defaultPort); } this.resource = resource; if (port == null) { base = protocol + ": optional = ":" + defaultPort; } else { base = protocol + ": optional = ""; } BASE = base.toUpperCase(); }
Origin { private Origin(String protocol, String host, String port, String resource) { String defaultPort; switch (protocol.toLowerCase()) { case "ftp": this.protocol = protocol; defaultPort = DEFAULT_FTP_PORT; break; case "http": this.protocol = protocol; defaultPort = DEFAULT_HTTP_PORT; break; case "https": this.protocol = protocol; defaultPort = DEFAULT_HTTPS_PORT; break; default: throw new IllegalStateException("Unsupported protocol: " + protocol); } if (host == null) { throw new IllegalStateException("Null host not allowed"); } boolean ipv6 = false; for (int i = 0; i < host.length(); i++) { char c = host.charAt(i); switch (c) { case '[': if (i == 0) { ipv6 = true; } else { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ']': if (!ipv6 || i != host.length() - 1) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ':': if (!ipv6) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; default: if (!Character.isLetterOrDigit(c) && c != '.' && c != '-') { throw new IllegalStateException("Illegal character in hostname: " + host); } break; } } this.host = host; if (port != null) { for (int i = 0; i < port.length(); i++) { char c = port.charAt(i); if (!Character.isDigit(c)) { throw new IllegalStateException("Illegal character in port: " + port); } } this.port = Integer.parseInt(port); } else { this.port = Integer.parseInt(defaultPort); } this.resource = resource; if (port == null) { base = protocol + ": optional = ":" + defaultPort; } else { base = protocol + ": optional = ""; } BASE = base.toUpperCase(); } }
Origin { private Origin(String protocol, String host, String port, String resource) { String defaultPort; switch (protocol.toLowerCase()) { case "ftp": this.protocol = protocol; defaultPort = DEFAULT_FTP_PORT; break; case "http": this.protocol = protocol; defaultPort = DEFAULT_HTTP_PORT; break; case "https": this.protocol = protocol; defaultPort = DEFAULT_HTTPS_PORT; break; default: throw new IllegalStateException("Unsupported protocol: " + protocol); } if (host == null) { throw new IllegalStateException("Null host not allowed"); } boolean ipv6 = false; for (int i = 0; i < host.length(); i++) { char c = host.charAt(i); switch (c) { case '[': if (i == 0) { ipv6 = true; } else { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ']': if (!ipv6 || i != host.length() - 1) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ':': if (!ipv6) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; default: if (!Character.isLetterOrDigit(c) && c != '.' && c != '-') { throw new IllegalStateException("Illegal character in hostname: " + host); } break; } } this.host = host; if (port != null) { for (int i = 0; i < port.length(); i++) { char c = port.charAt(i); if (!Character.isDigit(c)) { throw new IllegalStateException("Illegal character in port: " + port); } } this.port = Integer.parseInt(port); } else { this.port = Integer.parseInt(defaultPort); } this.resource = resource; if (port == null) { base = protocol + ": optional = ":" + defaultPort; } else { base = protocol + ": optional = ""; } BASE = base.toUpperCase(); } private  Origin(String protocol, String host, String port, String resource); }
Origin { private Origin(String protocol, String host, String port, String resource) { String defaultPort; switch (protocol.toLowerCase()) { case "ftp": this.protocol = protocol; defaultPort = DEFAULT_FTP_PORT; break; case "http": this.protocol = protocol; defaultPort = DEFAULT_HTTP_PORT; break; case "https": this.protocol = protocol; defaultPort = DEFAULT_HTTPS_PORT; break; default: throw new IllegalStateException("Unsupported protocol: " + protocol); } if (host == null) { throw new IllegalStateException("Null host not allowed"); } boolean ipv6 = false; for (int i = 0; i < host.length(); i++) { char c = host.charAt(i); switch (c) { case '[': if (i == 0) { ipv6 = true; } else { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ']': if (!ipv6 || i != host.length() - 1) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ':': if (!ipv6) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; default: if (!Character.isLetterOrDigit(c) && c != '.' && c != '-') { throw new IllegalStateException("Illegal character in hostname: " + host); } break; } } this.host = host; if (port != null) { for (int i = 0; i < port.length(); i++) { char c = port.charAt(i); if (!Character.isDigit(c)) { throw new IllegalStateException("Illegal character in port: " + port); } } this.port = Integer.parseInt(port); } else { this.port = Integer.parseInt(defaultPort); } this.resource = resource; if (port == null) { base = protocol + ": optional = ":" + defaultPort; } else { base = protocol + ": optional = ""; } BASE = base.toUpperCase(); } private  Origin(String protocol, String host, String port, String resource); static Origin parse(String text); static boolean isValid(String text); String protocol(); String host(); int port(); String resource(); boolean sameOrigin(String other); String encode(); @Override String toString(); }
Origin { private Origin(String protocol, String host, String port, String resource) { String defaultPort; switch (protocol.toLowerCase()) { case "ftp": this.protocol = protocol; defaultPort = DEFAULT_FTP_PORT; break; case "http": this.protocol = protocol; defaultPort = DEFAULT_HTTP_PORT; break; case "https": this.protocol = protocol; defaultPort = DEFAULT_HTTPS_PORT; break; default: throw new IllegalStateException("Unsupported protocol: " + protocol); } if (host == null) { throw new IllegalStateException("Null host not allowed"); } boolean ipv6 = false; for (int i = 0; i < host.length(); i++) { char c = host.charAt(i); switch (c) { case '[': if (i == 0) { ipv6 = true; } else { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ']': if (!ipv6 || i != host.length() - 1) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; case ':': if (!ipv6) { throw new IllegalStateException("Illegal character in hostname: " + host); } break; default: if (!Character.isLetterOrDigit(c) && c != '.' && c != '-') { throw new IllegalStateException("Illegal character in hostname: " + host); } break; } } this.host = host; if (port != null) { for (int i = 0; i < port.length(); i++) { char c = port.charAt(i); if (!Character.isDigit(c)) { throw new IllegalStateException("Illegal character in port: " + port); } } this.port = Integer.parseInt(port); } else { this.port = Integer.parseInt(defaultPort); } this.resource = resource; if (port == null) { base = protocol + ": optional = ":" + defaultPort; } else { base = protocol + ": optional = ""; } BASE = base.toUpperCase(); } private  Origin(String protocol, String host, String port, String resource); static Origin parse(String text); static boolean isValid(String text); String protocol(); String host(); int port(); String resource(); boolean sameOrigin(String other); String encode(); @Override String toString();  }