1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Gagan Saksena <gagan@netscape.com> (original author)
24 * Darin Fisher <darin@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
43 * The nsIURL interface provides convenience methods that further
44 * break down the path portion of nsIURI:
46 * http://host/directory/fileBaseName.fileExtension?query
47 * http://host/directory/fileBaseName.fileExtension#ref
48 * http://host/directory/fileBaseName.fileExtension;param
50 * \ -----------------------
53 * ----------------------------
59 [scriptable
, uuid(d6116970
-8034-11d3
-9399-00104ba0fd40
)]
60 interface nsIURL
: nsIURI
62 /*************************************************************************
63 * The URL path is broken down into the following principal components:
67 * Returns a path including the directory and file portions of a
68 * URL. For example, the filePath of "http://host/foo/bar.html#baz"
71 * Some characters may be escaped.
73 attribute AUTF8String filePath
;
76 * Returns the parameters specified after the ; in the URL.
78 * Some characters may be escaped.
80 attribute AUTF8String param
;
83 * Returns the query portion (the part after the "?") of the URL.
84 * If there isn't one, an empty string is returned.
86 * Some characters may be escaped.
88 attribute AUTF8String query
;
91 * Returns the reference portion (the part after the "#") of the URL.
92 * If there isn't one, an empty string is returned.
94 * Some characters may be escaped.
96 attribute AUTF8String
ref;
99 /*************************************************************************
100 * The URL filepath is broken down into the following sub-components:
104 * Returns the directory portion of a URL. If the URL denotes a path to a
105 * directory and not a file, e.g. http://host/foo/bar/, then the Directory
106 * attribute accesses the complete /foo/bar/ portion, and the FileName is
107 * the empty string. If the trailing slash is omitted, then the Directory
108 * is /foo/ and the file is bar (i.e. this is a syntactic, not a semantic
109 * breakdown of the Path). And hence don't rely on this for something to
110 * be a definitely be a file. But you can get just the leading directory
113 * Some characters may be escaped.
115 attribute AUTF8String directory
;
118 * Returns the file name portion of a URL. If the URL denotes a path to a
119 * directory and not a file, e.g. http://host/foo/bar/, then the Directory
120 * attribute accesses the complete /foo/bar/ portion, and the FileName is
121 * the empty string. Note that this is purely based on searching for the
122 * last trailing slash. And hence don't rely on this to be a definite file.
124 * Some characters may be escaped.
126 attribute AUTF8String fileName
;
129 /*************************************************************************
130 * The URL filename is broken down even further:
134 * Returns the file basename portion of a filename in a url.
136 * Some characters may be escaped.
138 attribute AUTF8String fileBaseName
;
141 * Returns the file extension portion of a filename in a url. If a file
142 * extension does not exist, the empty string is returned.
144 * Some characters may be escaped.
146 attribute AUTF8String fileExtension
;
149 * This method takes a uri and compares the two. The common uri portion
150 * is returned as a string. The minimum common uri portion is the
151 * protocol, and any of these if present: login, password, host and port
152 * If no commonality is found, "" is returned. If they are identical, the
153 * whole path with file/ref/etc. is returned. For file uris, it is
154 * expected that the common spec would be at least "file:///" since '/' is
155 * a shared common root.
158 * this.spec aURIToCompare.spec result
159 * 1) http://mozilla.org/ http://www.mozilla.org/ ""
160 * 2) http://foo.com/bar/ ftp://foo.com/bar/ ""
161 * 3) http://foo.com:8080/ http://foo.com/bar/ ""
162 * 4) ftp://user@foo.com/ ftp://user:pw@foo.com/ ""
163 * 5) ftp://foo.com/bar/ ftp://foo.com/bar ftp://foo.com/
164 * 6) ftp://foo.com/bar/ ftp://foo.com/bar/b.html ftp://foo.com/bar/
165 * 7) http://foo.com/a.htm#i http://foo.com/b.htm http://foo.com/
166 * 8) ftp://foo.com/c.htm#i ftp://foo.com/c.htm ftp://foo.com/c.htm
167 * 9) file:///a/b/c.html file:///d/e/c.html file:///
169 AUTF8String getCommonBaseSpec
(in nsIURI aURIToCompare
);
172 * This method takes a uri and returns a substring of this if it can be
173 * made relative to the uri passed in. If no commonality is found, the
174 * entire uri spec is returned. If they are identical, "" is returned.
175 * Filename, query, etc are always returned except when uris are identical.
177 AUTF8String getRelativeSpec
(in nsIURI aURIToCompare
);