michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsIURI.idl" michael@0: michael@0: /** michael@0: * The nsIURL interface provides convenience methods that further michael@0: * break down the path portion of nsIURI: michael@0: * michael@0: * http://host/directory/fileBaseName.fileExtension?query michael@0: * http://host/directory/fileBaseName.fileExtension#ref michael@0: * \ \ / michael@0: * \ ----------------------- michael@0: * \ | / michael@0: * \ fileName / michael@0: * ---------------------------- michael@0: * | michael@0: * filePath michael@0: */ michael@0: [scriptable, uuid(1419aa16-f134-4154-9886-00c7c5147a13)] michael@0: interface nsIURL : nsIURI michael@0: { michael@0: /************************************************************************* michael@0: * The URL path is broken down into the following principal components: michael@0: */ michael@0: michael@0: /** michael@0: * Returns a path including the directory and file portions of a michael@0: * URL. For example, the filePath of "http://host/foo/bar.html#baz" michael@0: * is "/foo/bar.html". michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String filePath; michael@0: michael@0: /** michael@0: * Returns the query portion (the part after the "?") of the URL. michael@0: * If there isn't one, an empty string is returned. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String query; michael@0: michael@0: michael@0: /************************************************************************* michael@0: * The URL filepath is broken down into the following sub-components: michael@0: */ michael@0: michael@0: /** michael@0: * Returns the directory portion of a URL. If the URL denotes a path to a michael@0: * directory and not a file, e.g. http://host/foo/bar/, then the Directory michael@0: * attribute accesses the complete /foo/bar/ portion, and the FileName is michael@0: * the empty string. If the trailing slash is omitted, then the Directory michael@0: * is /foo/ and the file is bar (i.e. this is a syntactic, not a semantic michael@0: * breakdown of the Path). And hence don't rely on this for something to michael@0: * be a definitely be a file. But you can get just the leading directory michael@0: * portion for sure. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String directory; michael@0: michael@0: /** michael@0: * Returns the file name portion of a URL. If the URL denotes a path to a michael@0: * directory and not a file, e.g. http://host/foo/bar/, then the Directory michael@0: * attribute accesses the complete /foo/bar/ portion, and the FileName is michael@0: * the empty string. Note that this is purely based on searching for the michael@0: * last trailing slash. And hence don't rely on this to be a definite file. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String fileName; michael@0: michael@0: michael@0: /************************************************************************* michael@0: * The URL filename is broken down even further: michael@0: */ michael@0: michael@0: /** michael@0: * Returns the file basename portion of a filename in a url. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String fileBaseName; michael@0: michael@0: /** michael@0: * Returns the file extension portion of a filename in a url. If a file michael@0: * extension does not exist, the empty string is returned. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String fileExtension; michael@0: michael@0: /** michael@0: * This method takes a uri and compares the two. The common uri portion michael@0: * is returned as a string. The minimum common uri portion is the michael@0: * protocol, and any of these if present: login, password, host and port michael@0: * If no commonality is found, "" is returned. If they are identical, the michael@0: * whole path with file/ref/etc. is returned. For file uris, it is michael@0: * expected that the common spec would be at least "file:///" since '/' is michael@0: * a shared common root. michael@0: * michael@0: * Examples: michael@0: * this.spec aURIToCompare.spec result michael@0: * 1) http://mozilla.org/ http://www.mozilla.org/ "" michael@0: * 2) http://foo.com/bar/ ftp://foo.com/bar/ "" michael@0: * 3) http://foo.com:8080/ http://foo.com/bar/ "" michael@0: * 4) ftp://user@foo.com/ ftp://user:pw@foo.com/ "" michael@0: * 5) ftp://foo.com/bar/ ftp://foo.com/bar ftp://foo.com/ michael@0: * 6) ftp://foo.com/bar/ ftp://foo.com/bar/b.html ftp://foo.com/bar/ michael@0: * 7) http://foo.com/a.htm#i http://foo.com/b.htm http://foo.com/ michael@0: * 8) ftp://foo.com/c.htm#i ftp://foo.com/c.htm ftp://foo.com/c.htm michael@0: * 9) file:///a/b/c.html file:///d/e/c.html file:/// michael@0: */ michael@0: AUTF8String getCommonBaseSpec(in nsIURI aURIToCompare); michael@0: michael@0: /** michael@0: * This method tries to create a string which specifies the location of the michael@0: * argument relative to |this|. If the argument and |this| are equal, the michael@0: * method returns "". If any of the URIs' scheme, host, userpass, or port michael@0: * don't match, the method returns the full spec of the argument. michael@0: * michael@0: * Examples: michael@0: * this.spec aURIToCompare.spec result michael@0: * 1) http://mozilla.org/ http://www.mozilla.org/ http://www.mozilla.org/ michael@0: * 2) http://mozilla.org/ http://www.mozilla.org http://www.mozilla.org/ michael@0: * 3) http://foo.com/bar/ http://foo.com:80/bar/ "" michael@0: * 4) http://foo.com/ http://foo.com/a.htm#b a.html#b michael@0: * 5) http://foo.com/a/b/ http://foo.com/c ../../c michael@0: */ michael@0: AUTF8String getRelativeSpec(in nsIURI aURIToCompare); michael@0: michael@0: };