1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
4 <title>URL manipulation
</title>
5 <meta http-equiv=
"content-type" content=
"text/html; charset=ISO-8859-1">
7 <script type=
"text/javascript">
9 function getIOService()
15 gIOService
= Components
.classes
["@mozilla.org/network/io-service;1"]
16 .getService(Components
.interfaces
.nsIIOService
);
17 } catch(e
) { dump("problem creating nsIURL for: "+inURLString
+"\n"); }
22 function getnsIURL(inURLString
)
25 var ioserv
= getIOService();
27 var URI
= ioserv
.newURI(inURLString
, "", null);
28 URL
= URI
.QueryInterface(Components
.interfaces
.nsIURL
);
29 } catch(e
) { dump("problem creating nsIURL for: "+inURLString
+"\n"); }
33 function getCommonSpec()
35 var URL1
= getnsIURL(document
.foo
.baseEdit
.value
);
36 var URL2
= getnsIURL(document
.foo
.compareEdit
.value
);
39 result
= URL1
.getCommonBaseSpec(URL2
);
40 } catch(e
) { dump("problem with getCommonSpec ("+e
+")\n"); }
41 document
.foo
.resultEdit
.value
= result
;
44 function getRelativeSpec()
46 var URL1
= getnsIURL(document
.foo
.baseEdit
.value
);
47 var URL2
= getnsIURL(document
.foo
.compareEdit
.value
);
50 result
= URL1
.getRelativeSpec(URL2
);
51 } catch(e
) { dump("problem with getRelativeSpec ("+e
+")\n"); }
52 document
.foo
.resultEdit
.value
= result
;
57 var URL
= getnsIURL(document
.foo
.baseEdit
.value
);
60 result
= URL
.resolve(document
.foo
.resultEdit
.value
);
61 } catch(e
) { dump("problem with getRelativeSpec ("+e
+")\n"); }
62 document
.foo
.compareEdit
.value
= result
;
67 <h1>testing of URL manipulation:
</h1>
71 <label for=
"baseEdit">base url (absolute)
</label><br>
72 <input type=
"input" name=
"baseEdit" size=
"80" value=
"http://www.mozilla.org/">
75 <label for=
"compareEdit">comparison uri (absolute)
</label><br>
76 <input type=
"input" name=
"compareEdit" size=
"80">
79 <label for=
"resultEdit">resolved url
</label><br>
80 <input type=
"input" name=
"resultEdit" size=
"80">
83 <input type=
"button" onclick=
"getCommonSpec();" value=
"Get Common Spec">
84 <input type=
"button" onclick=
"getRelativeSpec();" value=
"Get Relative Spec">
85 <input type=
"button" onclick=
"doResolve();" value=
"Resolve">
86 <h5> note: results from
"resolve" are placed in
"comparison uri" edit field
</h5>
91 <h3>notes for testing
</h3>
92 different types of uris:
<br>
96 <li>mailbox://nsmail-
2.mcom.com/xxx
</li>
97 <li>mailto:brade@netscape.com)
</li>
100 <li>http://foo.com/
</li>
101 <li>https://foo.com/
</li>
102 <li>ftp://ftp.mozilla.org/
</li>
103 <li>http://foo.com:
8080/
</li>
104 <li>http://brade@foo.com/
</li>
105 <li>http://brade:password@foo.com/
</li>
106 <li>http://brade:@foo.com:
8080/
</li>
108 <li>file:///Quest/Desktop%
20Folder/test.html
</li>
110 other variations:
<br>
112 <li>sub-directories on above list
</li>
113 <li>files on above list
</li>
114 <li>sub-directories and files on above list
<br>
116 <li>directories which don't end in a '/'
</li>
117 <li>files with queries
</li>
118 <li>files with no extension
</li>
119 <li>files with references
</li>
120 <li>files with params
</li>
121 <li>other schemes (chrome, ldap, news, finger, etc.)
<br>
125 This should be true:
<br>
126 resultString = baseURL.getRelativeSpec(URL);
<br>
128 baseURL.resolve(resultString) == URL.spec;
<br>