public interface PacHelperMethodsNetscape
The JavaScript helper functions are defined in Java terms by this interface. The Java methods are named exactly as their JavaScript counterparts.
The documentation on each of the methods in the interface is more or less copied verbatim from Netscape's original documentation.
Beware that at the time when Netscape defined these functions IPv6 wasn't on the radar. Therefore the concensus among browser makers is that IPv4 is implied in all these functions.
Modifier and Type | Method and Description |
---|---|
boolean |
dateRange(Object... args)
Tests if current date is within a date range.
|
boolean |
dnsDomainIs(String host,
String domain)
Returns true if the domain of hostname matches.
|
int |
dnsDomainLevels(String host)
Returns the number of DNS domain levels (number of dots)
in the hostname.
|
String |
dnsResolve(String host)
Resolves the given DNS hostname into an IPv4 address,
and returns it in the dot separated format as a string.
|
boolean |
isInNet(String host,
String pattern,
String mask)
True if the IP address of the host matches the specified IP address
pattern.
|
boolean |
isPlainHostName(String host)
True if there is no domain name in the hostname (no dots).
|
boolean |
isResolvable(String host)
Tries to resolve the hostname.
|
boolean |
localHostOrDomainIs(String host,
String hostdom)
Is true if the hostname matches exactly the specified hostname, or if
there is no domain name part in the hostname, but the unqualified
hostname matches.
|
String |
myIpAddress()
Returns the IPv4 address of the host that the application is running on,
as a string in the dot-separated integer format.
|
boolean |
shExpMatch(String str,
String shexp)
Returns true if the string matches the specified shell expression.
|
boolean |
timeRange(Object... args)
Tests if current time is within a time range.
|
boolean |
weekdayRange(Object... args)
Tests if current day is within a day-of-week range.
|
boolean isPlainHostName(String host)
Examples:
isPlainHostName("www") is true. isPlainHostName("www.netscape.com") is false.
host
- host nameboolean dnsDomainIs(String host, String domain)
Examples:
dnsDomainIs("www.netscape.com", ".netscape.com") is true. dnsDomainIs("www", ".netscape.com") is false. dnsDomainIs("www.mcom.com", ".netscape.com") is false.
host
- the host name from the URL.domain
- the domain name to test the host name against.boolean localHostOrDomainIs(String host, String hostdom)
Examples of usage from JavaScript:
localHostOrDomainIs("www.netscape.com", "www.netscape.com") is true (exact match). localHostOrDomainIs("www", "www.netscape.com") is true (hostname match, domain not specified). localHostOrDomainIs("www.mcom.com", "www.netscape.com") is false (domain name mismatch). localHostOrDomainIs("home.netscape.com", "www.netscape.com") is false (hostname mismatch).
host
- the hostname from the URL.hostdom
- fully qualified hostname to match against.boolean isResolvable(String host)
true
if the argument can be
resolved into an IPv4 address.
Examples of usage from JavaScript:
isResolvable("www.netscape.com") is true (unless DNS fails to resolve it due to a firewall or some other reason). isResolvable("bogus.domain.foobar") is false.
host
- String dnsResolve(String host)
Example of usage from JavaScript:
dnsResolve("home.netscape.com") returns the string "198.95.249.79".
host
- String myIpAddress()
Example of usage from JavaScript:
myIpAddress() would return the string "198.95.249.79" if you were running the the application on that host.
boolean isInNet(String host, String pattern, String mask)
Examples of usage from JavaScript:
isInNet(host, "198.95.249.79", "255.255.255.255") is true if the IP address of host matches exactly 198.95.249.79. isInNet(host, "198.95.0.0", "255.255.0.0") is true if the IP address of the host matches 198.95.*.*.
host
- a DNS hostname or IPv4 address. If a hostname is passed, it
will be resolved into an IP address by this function.pattern
- an IPv4 address pattern in the dot-separated format.mask
- mask for the IP address pattern informing which parts of the
IP address should be matched against. 0 means ignore, 255 means match.int dnsDomainLevels(String host)
Examples of usage from JavaScript:
dnsDomainLevels("www") returns 0. dnsDomainLevels("www.netscape.com") returns 2.
host
- hostnameboolean shExpMatch(String str, String shexp)
Examples of usage from JavaScript:
shExpMatch("http://home.netscape.com/people/ari/index.html", "*/ari/*") is true. shExpMatch("http://home.netscape.com/people/montulli/index.html", "*/ari/*") is false.
str
- shexp
- shell expressionboolean weekdayRange(Object... args)
There are several forms of this method from JavaScript:
weekdayRange(wd1) weekdayRange(wd1, gmt) weekdayRange(wd1, wd2) weekdayRange(wd1, wd2, gmt)Parameters:
wd1
and wd2
are weekday specifications. gmt
is either the string "GMT", which makes time comparison
occur in GMT timezone; or if not present, times are taken to
be in the local timezone. If this parameter exists it
must always be the last parameter.
If only wd1
is present, the function yields a true value on the
weekday that the parameter represents. If both wd1
and
wd2
are specified, the condition is true if the current weekday
is in between those two weekdays. Bounds are inclusive.
The weekday abbreviations used in wd1
and wd2
must be
one of the following:
MON TUE WED THU FRI SAT SUN
Examples of usage from JavaScript:
weekdayRange("MON", "FRI") Returns true Monday through Friday (local time zone). weekdayRange("MON", "FRI", "GMT") Returns true Monday through Friday, in Greenwich Mean Time. weekdayRange("SAT") Returns true on Saturdays, local time. weekdayRange("SAT", "GMT") Returns true on Saturdays, in Greenwich Mean Time. weekdayRange("FRI", "MON") Returns true Friday through Monday (the order is important) weekdayRange("WED", "TUE") Returns true always, all 7 days a week (although an alien way of specifying it)
args
- up to max 3 argumentsnetwork.proxy.pac.datetime.PacUtilsDateTime
boolean dateRange(Object... args)
There are several forms of this method from JavaScript:
dateRange(day) dateRange(day1, day2) dateRange(mon) dateRange(month1, month2) dateRange(year) dateRange(year1, year2) dateRange(day1, month1, day2, month2) dateRange(month1, year1, month2, year2) dateRange(day1, month1, year1, day2, month2, year2) dateRange(day1, month1, year1, day2, month2, year2, gmt)Even if not shown above, the
gmt
parameter can always be
added as an (optional) last parameter.
day
is the day of month between 1 and 31 (as an integer).
month
is one of the month strings: JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
year
is the full year number with 4 digits, for example 1995. (as an integer)
gmt
is either the string "GMT", which makes time comparison
occur in GMT timezone; or if not present, times are taken to
be in the local timezone. If this parameter exists it
must always be the last parameter.
Examples of usage from JavaScript:
dateRange(1) true on the first day of each month, local timezone. dateRange(1, "GMT") true on the first day of each month, GMT timezone. dateRange(1, 15) true on the first half of each month. dateRange(24, "DEC") true on 24th of December each year. dateRange(24, "DEC", 1995) true on 24th of December, 1995. dateRange("JAN", "MAR") true on the first quarter of the year. dateRange(1, "JUN", 15, "AUG") true from June 1st until August 15th, each year (including June 1st and August 15th). dateRange(1, "JUN", 15, 1995, "AUG", 1995) true from June 1st, 1995, until August 15th, same year. dateRange("OCT", 1995, "MAR", 1996) true from October 1995 until March 1996 (including the entire month of October 1995 and March 1996). dateRange(1995) true during the entire year 1995. dateRange(1995, 1997) true from beginning of year 1995 until the end of year 1997.
args
- network.proxy.pac.datetime.PacUtilsDateTime
boolean timeRange(Object... args)
There are several forms of this method from JavaScript:
timeRange(hour) timeRange(hour1, hour2) timeRange(hour1, min1, hour2, min2) timeRange(hour1, min1, sec1, hour2, min2, sec2) timeRange(hour1, min1, sec1, hour2, min2, sec2, gmt)Even if not shown above, the
gmt
parameter can always be
added as an (optional) last parameter.
hour
is the hour from 0 to 23. (0 is midnight, 23 is 11 pm.)
min
minutes from 0 to 59.
sec
seconds from 0 to 59.
gmt
is either the string "GMT", which makes time comparison
occur in GMT timezone; or if not present, times are taken to
be in the local timezone. If this parameter exists it
must always be the last parameter.
Examples of usage from JavaScript:
timeRange(12, 13) This statement is true from noon to 1:00 p.m. timeRange(12, "GMT") This statement is true noon to 12:59 p.m. GMT. timeRange(9, 17) This statement is true from 9:00 a.m. to 5:00 p.m. timeRange(0, 0, 0, 0, 0, 30) true between midnight and 30 seconds past midnight.
args
- anywhere between 1 and 7 arguments