nsIURI 编辑
netwerk/base/public/nsIURI.idl
Scriptable This is an interface for an uniform resource identifier with internationalization support, offering attributes that allow setting and querying the basic components of a URI, and methods for performing basic operations on URIs. Inherits from: nsISupports
Last changed in Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3)See the following RFCs for details:
- RFC3490: Internationalizing Domain Names in Applications (IDNA)
- RFC3986: Uniform Resource Identifier (URI): Generic Syntax
- RFC3987: Internationalized Resource Identifiers
Subclasses of nsIURI
, such as nsIURL
, impose further structure on the URI.
To create an nsIURI
object, you should use nsIIOService.newURI()
, like this:
function makeURI(aURL, aOriginCharset, aBaseURI) {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return ioService.newURI(aURL, aOriginCharset, aBaseURI);
}
Components of a URI
prePath | path | |||||||
---|---|---|---|---|---|---|---|---|
scheme | userPass | host | port | ref | ||||
ftp | :// | username@password | @ | hostname | : | portnumber | /pathname?query=value | #ref |
Method overview
nsIURI clone(); |
nsIURI cloneIgnoringRef(); |
boolean equals(in nsIURI other); |
boolean equalsExceptRef(in nsIURI other); |
AUTF8String resolve(in AUTF8String relativePath); |
boolean schemeIs(in string scheme); |
Attributes
Attribute | Type | Description |
asciiHost | ACString | The URI Note: IPv6 addresses are not enclosed in square brackets. |
asciiSpec | ACString (US-ASCII) | The URI spec with an ASCII compatible encoding. The host portion follows the IDNA draft spec. Other parts are URL-escaped per the rules of RFC3986. The result is strictly ASCII. Read only. |
hasRef | boolean | Returns if there is a reference portion (the part after the "#") of the URI. |
host | AUTF8String | The host is the Internet domain name to which this URI refers. It could be an IPv4 (or IPv6) address literal. If supported, it could be a non-ASCII internationalized domain name. Exceptions thrown
|
hostPort | AUTF8String | The "host:port" part of the URI (or simply the host, if port is -1). Exceptions thrown
|
originCharset | ACString | The charset of the document from which this URI originated. An empty value implies UTF-8. If this value is something other than UTF-8 then the URI components (for examplespec , prePath , username , and so on) are all fully URL-escaped. Otherwise, the URI components may contain unescaped multibyte UTF-8 characters. Read only. |
password | AUTF8String | The optional password, assuming the Exceptions thrown
|
path | AUTF8String | The path, typically including at least a leading '/' (but may also be empty, depending on the protocol). Note: Some characters may be escaped. |
port | long | The URI's port. A port value of -1 corresponds to the protocol's default port (for example -1 implies port 80 for HTTP URIs). Exceptions thrown
|
prePath | AUTF8String | The This is related to the Web Origin Concept of RFC6454. This is useful for authentication, managing sessions, or for checking the |
ref | AUTF8String | Returns the reference portion (the part after the "#") of the URI. If there is not one, an empty string is returned. Note: Some characters may be escaped. |
scheme | ACString (US-ASCII) | The |
spec | AUTF8String | Returns a string representation of the URI. Setting the If the URI stores information from the |
specIgnoringRef | AUTF8String | Returns a string representation of the URI without the ref (part after the #) portion.Note: Some characters may be escaped. |
username | AUTF8String | The optional username, assuming the Exceptions thrown
|
userPass | AUTF8String | The "username:password" (or username only if the value doesn't contain a ':'). Exceptions thrown
|
Methods
clone()
Clones the URI, returning a new nsIURI
object.
nsIURI clone();
Parameters
None.
Return value
An nsIURI
object that represents the same URI as the current nsIURI
.
cloneIgnoringRef()
Clones the current URI, clearing the 'ref'
attribute in the clone.
nsIURI cloneIgnoringRef();
Parameters
None.
Return value
An nsIURI
object that represents the same URI as the current nsIURI
without the 'ref'
attribute.
equals()
Compares the current URI with another URI.
Note: This is more than a string comparison, as two different URI strings can represent the same location. For example, comparing "http://foo.com:80/" and "http://foo.com/" will returntrue
.boolean equals( in nsIURI other );
Parameters
other
- Another
nsIURI
to compare to.
Return value
true
if the two URIs represent the same location; otherwise false
.
equalsExceptRef()
Compares the current URI with another URI, ignoring the value of the .ref
member.
true
.boolean equalsExceptRef( in nsIURI other );
Parameters
other
- Another
nsIURI
to compare to.
Return value
true
if the two URIs represent the same location; otherwise false
.
resolve()
Resolves a relative URI string, using this URI as the base.
Note: Some implementations may have no concept of a relative URI.AUTF8String resolve( in AUTF8String relativePath );
Parameters
relativePath
- The relative path to resolve.
Return value
The resolved absolute URI string.
schemeIs()
Quickly reports whether the nsIURI
represents a URI with the specified scheme. This comparison is case-insensitive.
boolean schemeIs( in string scheme );
Parameters
scheme
- A string representing the scheme to compare to.
Return value
true
if the URI is for the specified scheme; otherwise false
.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论