mirror of
https://github.com/rn10950/RetroZilla.git
synced 2024-11-14 03:30:17 +01:00
131 lines
3.8 KiB
HTML
131 lines
3.8 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<title>URL manipulation</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
|
|
|
<script type="text/javascript">
|
|
var gIOService = null;
|
|
function getIOService()
|
|
{
|
|
if (gIOService)
|
|
return gIOService;
|
|
|
|
try {
|
|
gIOService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
.getService(Components.interfaces.nsIIOService);
|
|
} catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }
|
|
|
|
return gIOService;
|
|
}
|
|
|
|
function getnsIURL(inURLString)
|
|
{
|
|
var URL = null;
|
|
var ioserv = getIOService();
|
|
try {
|
|
var URI = ioserv.newURI(inURLString, "", null);
|
|
URL = URI.QueryInterface(Components.interfaces.nsIURL);
|
|
} catch(e) { dump("problem creating nsIURL for: "+inURLString+"\n"); }
|
|
return URL;
|
|
}
|
|
|
|
function getCommonSpec()
|
|
{
|
|
var URL1 = getnsIURL(document.foo.baseEdit.value);
|
|
var URL2 = getnsIURL(document.foo.compareEdit.value);
|
|
var result = "";
|
|
try {
|
|
result = URL1.getCommonBaseSpec(URL2);
|
|
} catch(e) { dump("problem with getCommonSpec ("+e+")\n"); }
|
|
document.foo.resultEdit.value = result;
|
|
}
|
|
|
|
function getRelativeSpec()
|
|
{
|
|
var URL1 = getnsIURL(document.foo.baseEdit.value);
|
|
var URL2 = getnsIURL(document.foo.compareEdit.value);
|
|
var result = "";
|
|
try {
|
|
result = URL1.getRelativeSpec(URL2);
|
|
} catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
|
|
document.foo.resultEdit.value = result;
|
|
}
|
|
|
|
function doResolve()
|
|
{
|
|
var URL = getnsIURL(document.foo.baseEdit.value);
|
|
var result = "";
|
|
try {
|
|
result = URL.resolve(document.foo.resultEdit.value);
|
|
} catch(e) { dump("problem with getRelativeSpec ("+e+")\n"); }
|
|
document.foo.compareEdit.value = result;
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<h1>testing of URL manipulation:</h1>
|
|
<p>
|
|
<form name="foo">
|
|
<p>
|
|
<label for="baseEdit">base url (absolute)</label><br>
|
|
<input type="input" name="baseEdit" size="80" value="http://www.mozilla.org/">
|
|
|
|
<p>
|
|
<label for="compareEdit">comparison uri (absolute)</label><br>
|
|
<input type="input" name="compareEdit" size="80">
|
|
|
|
<p>
|
|
<label for="resultEdit">resolved url</label><br>
|
|
<input type="input" name="resultEdit" size="80">
|
|
|
|
<p>
|
|
<input type="button" onclick="getCommonSpec();" value="Get Common Spec">
|
|
<input type="button" onclick="getRelativeSpec();" value="Get Relative Spec">
|
|
<input type="button" onclick="doResolve();" value="Resolve">
|
|
<h5> note: results from "resolve" are placed in "comparison uri" edit field</h5>
|
|
</form>
|
|
<p>
|
|
<br>
|
|
|
|
<h3>notes for testing</h3>
|
|
different types of uris:<br>
|
|
<ul>
|
|
<li>about:</li>
|
|
<li>about:blank</li>
|
|
<li>mailbox://nsmail-2.mcom.com/xxx</li>
|
|
<li>mailto:brade@netscape.com)</li>
|
|
<li>junk</li>
|
|
<li>http://foo/</li>
|
|
<li>http://foo.com/</li>
|
|
<li>https://foo.com/</li>
|
|
<li>ftp://ftp.mozilla.org/</li>
|
|
<li>http://foo.com:8080/</li>
|
|
<li>http://brade@foo.com/</li>
|
|
<li>http://brade:password@foo.com/</li>
|
|
<li>http://brade:@foo.com:8080/</li>
|
|
<li>file:///</li>
|
|
<li>file:///Quest/Desktop%20Folder/test.html</li>
|
|
</ul>
|
|
other variations:<br>
|
|
<ul>
|
|
<li>sub-directories on above list</li>
|
|
<li>files on above list</li>
|
|
<li>sub-directories and files on above list<br>
|
|
</li>
|
|
<li>directories which don't end in a '/'</li>
|
|
<li>files with queries</li>
|
|
<li>files with no extension</li>
|
|
<li>files with references</li>
|
|
<li>files with params</li>
|
|
<li>other schemes (chrome, ldap, news, finger, etc.)<br>
|
|
</li>
|
|
</ul>
|
|
<br>
|
|
This should be true:<br>
|
|
resultString = baseURL.getRelativeSpec(URL);<br>
|
|
<==><br>
|
|
baseURL.resolve(resultString) == URL.spec;<br>
|
|
</body>
|
|
</html>
|