|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package com.sun.jndi.dns; |
|
|
|
|
|
import java.net.MalformedURLException; |
|
import java.util.Hashtable; |
|
import java.util.StringTokenizer; |
|
|
|
import com.sun.jndi.toolkit.url.Uri; |
|
import com.sun.jndi.toolkit.url.UrlUtil; |
|
|
|
|
|
/** |
|
* A DnsUrl represents a DNS pseudo-URL of the form |
|
* <pre> |
|
* dns://[host][:port][/[domain]] |
|
* or |
|
* dns:[/][domain] |
|
* </pre> |
|
* The host names a DNS server. If the host is not provided, it |
|
* indicates that the underlying platform's DNS server(s) should be |
|
* used if possible, or that "localhost" should be used otherwise. If |
|
* the port is not provided, the DNS default port 53 will be used. |
|
* The domain indicates the domain name of the context, and is not |
|
* necessarily related to the domain of the server; if it is not |
|
* provided, the root domain "." is used. Special characters in |
|
* the domain name must be %-escaped as described in RFC 2396. |
|
* |
|
* @author Scott Seligman |
|
*/ |
|
|
|
|
|
public class DnsUrl extends Uri { |
|
|
|
private String domain; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static DnsUrl[] fromList(String urlList) |
|
throws MalformedURLException { |
|
|
|
DnsUrl[] urls = new DnsUrl[(urlList.length() + 1) / 2]; |
|
int i = 0; |
|
StringTokenizer st = new StringTokenizer(urlList, " "); |
|
|
|
while (st.hasMoreTokens()) { |
|
urls[i++] = new DnsUrl(st.nextToken()); |
|
} |
|
DnsUrl[] trimmed = new DnsUrl[i]; |
|
System.arraycopy(urls, 0, trimmed, 0, i); |
|
return trimmed; |
|
} |
|
|
|
public DnsUrl(String url) throws MalformedURLException { |
|
super(url); |
|
|
|
if (!scheme.equals("dns")) { |
|
throw new MalformedURLException( |
|
url + " is not a valid DNS pseudo-URL"); |
|
} |
|
|
|
domain = path.startsWith("/") |
|
? path.substring(1) |
|
: path; |
|
domain = domain.equals("") |
|
? "." |
|
: UrlUtil.decode(domain); |
|
|
|
// Debug |
|
// System.out.println("host=" + host + " port=" + port + |
|
// " domain=" + domain); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public String getDomain() { |
|
return domain; |
|
} |
|
|
|
|
|
/* |
|
// Debug |
|
public static void main(String args[]) throws MalformedURLException { |
|
DnsUrl[] urls = fromList(args[0]); |
|
for (int i = 0; i < urls.length; i++) { |
|
System.out.println(urls[i].toString()); |
|
} |
|
} |
|
*/ |
|
} |