?? uri.as
字號:
_scheme = _scheme.toLowerCase();
baseURI = baseURI.substr(index + 1);
if (baseURI.substr(0, 2) == "//")
{
// This is a hierarchical URI
_nonHierarchical = "";
// Trim off the "//"
baseURI = baseURI.substr(2, baseURI.length - 2);
}
else
{
// This is a non-hierarchical URI like "mailto:bob@mail.com"
_nonHierarchical = baseURI;
if ((_valid = validateURI()) == false)
initialize(); // Bad URI. Clear it.
// No more parsing to do for this case
return isValid();
}
}
else
{
// No scheme. We will consider this a relative URI
_scheme = "";
_relative = true;
_nonHierarchical = "";
}
// Ok, what we have left is everything after the <scheme>://
// Now that we have stripped off any query and fragment parts, we
// need to split the authority from the path
if (isRelative())
{
// Don't bother looking for the authority. It's a relative URI
_authority = "";
_port = "";
_path = baseURI;
}
else
{
// Check for malformed UNC style file://///server/type/path/
// By the time we get here, we have already trimmed the "file://"
// so baseURI will be ///server/type/path. If baseURI only
// has one slash, we leave it alone because that is valid (that
// is the case of "file:///path/to/file.txt" where there is no
// server - implicit "localhost").
if (baseURI.substr(0, 2) == "//")
{
// Trim all leading slashes
while(baseURI.charAt(0) == "/")
baseURI = baseURI.substr(1, baseURI.length - 1);
}
index = baseURI.search('/');
if (index == -1)
{
// No path. We must have passed something like "http://something.com"
_authority = baseURI;
_path = "";
}
else
{
_authority = baseURI.substr(0, index);
_path = baseURI.substr(index, baseURI.length - index);
}
// Check to see if the URI has any username or password information.
// For example: ftp://username:password@server.com
index = _authority.search('@');
if (index != -1)
{
// We have a username and possibly a password
_username = _authority.substr(0, index);
// Remove the username/password from the authority
_authority = _authority.substr(index + 1); // Skip the '@'
// Now check to see if the username also has a password
index = _username.search(':');
if (index != -1)
{
_password = _username.substring(index + 1, _username.length);
_username = _username.substr(0, index);
}
else
_password = "";
}
else
{
_username = "";
_password = "";
}
// Lastly, check to see if the authorty has a port number.
// This is parsed after the username/password to avoid conflicting
// with the ':' in the 'username:password' if one exists.
index = _authority.search(':');
if (index != -1)
{
_port = _authority.substring(index + 1, _authority.length); // skip the ':'
_authority = _authority.substr(0, index);
}
else
{
_port = "";
}
// Lastly, normalize the authority. Domain names
// are case insensitive.
_authority = _authority.toLowerCase();
}
if ((_valid = validateURI()) == false)
initialize(); // Bad URI. Clear it
return isValid();
}
/********************************************************************
* Copy function.
*/
public function copyURI(uri:URI) : void
{
this._scheme = uri._scheme;
this._authority = uri._authority;
this._username = uri._username;
this._password = uri._password;
this._port = uri._port;
this._path = uri._path;
this._query = uri._query;
this._fragment = uri._fragment;
this._nonHierarchical = uri._nonHierarchical;
this._valid = uri._valid;
this._relative = uri._relative;
}
/**
* @private
* Checks if the given string only contains a-z or A-Z.
*/
protected function verifyAlpha(str:String) : Boolean
{
var pattern:RegExp = /[^a-z]/;
var index:int;
str = str.toLowerCase();
index = str.search(pattern);
if (index == -1)
return true;
else
return false;
}
/**
* Is this a valid URI?
*
* @return true if this object represents a valid URI, false
* otherwise.
*/
public function isValid() : Boolean
{
return this._valid;
}
/**
* Is this URI an absolute URI? An absolute URI is a complete, fully
* qualified reference to a resource. e.g. http://site.com/index.htm
* Non-hierarchical URI's are always absolute.
*/
public function isAbsolute() : Boolean
{
return !this._relative;
}
/**
* Is this URI a relative URI? Relative URI's do not have a scheme
* and only contain a relative path with optional anchor and query
* parts. e.g. "../reports/index.htm". Non-hierarchical URI's
* will never be relative.
*/
public function isRelative() : Boolean
{
return this._relative;
}
/**
* Does this URI point to a resource that is a directory/folder?
* The URI specification dictates that any path that ends in a slash
* is a directory. This is needed to be able to perform correct path
* logic when combining relative URI's with absolute URI's to
* obtain the correct absolute URI to a resource.
*
* @see URI.chdir
*
* @return true if this URI represents a directory resource, false
* if this URI represents a file resource.
*/
public function isDirectory() : Boolean
{
if (_path.length == 0)
return false;
return (_path.charAt(path.length - 1) == '/');
}
/**
* Is this URI a hierarchical URI? URI's can be
*/
public function isHierarchical() : Boolean
{
return hierState;
}
/**
* The scheme of the URI.
*/
public function get scheme() : String
{
return URI.unescapeChars(_scheme);
}
public function set scheme(schemeStr:String) : void
{
// Normalize the scheme
var normalized:String = schemeStr.toLowerCase();
_scheme = URI.fastEscapeChars(normalized, URI.URIschemeExcludedBitmap);
}
/**
* The authority (host) of the URI. Only valid for
* hierarchical URI's. If the URI is relative, this will
* be an empty string. When setting this value, the string
* given is assumed to be unescaped. When retrieving this
* value, the resulting string is unescaped.
*/
public function get authority() : String
{
return URI.unescapeChars(_authority);
}
public function set authority(authorityStr:String) : void
{
// Normalize the authority
authorityStr = authorityStr.toLowerCase();
_authority = URI.fastEscapeChars(authorityStr,
URI.URIauthorityExcludedBitmap);
// Only hierarchical URI's can have an authority, make
// sure this URI is of the proper format.
this.hierState = true;
}
/**
* The username of the URI. Only valid for hierarchical
* URI's. If the URI is relative, this will be an empty
* string.
*
* <p>The URI specification allows for authentication
* credentials to be embedded in the URI as such:</p>
*
* <p>http://user:passwd@host/path/to/file.htm</p>
*
* <p>When setting this value, the string
* given is assumed to be unescaped. When retrieving this
* value, the resulting string is unescaped.</p>
*/
public function get username() : String
{
return URI.unescapeChars(_username);
}
public function set username(usernameStr:String) : void
{
_username = URI.fastEscapeChars(usernameStr, URI.URIuserpassExcludedBitmap);
// Only hierarchical URI's can have a username.
this.hierState = true;
}
/**
* The password of the URI. Similar to username.
* @see URI.username
*/
public function get password() : String
{
return URI.unescapeChars(_password);
}
public function set password(passwordStr:String) : void
{
_password = URI.fastEscapeChars(passwordStr,
URI.URIuserpassExcludedBitmap);
// Only hierarchical URI's can have a password.
this.hierState = true;
}
/**
* The host port number. Only valid for hierarchical URI's. If
* the URI is relative, this will be an empty string. URI's can
* contain the port number of the remote host:
*
* <p>http://site.com:8080/index.htm</p>
*/
public function get port() : String
{
return URI.unescapeChars(_port);
}
public function set port(portStr:String) : void
{
_port = URI.escapeChars(portStr);
// Only hierarchical URI's can have a port.
this.hierState = true;
}
/**
* The path portion of the URI. Only valid for hierarchical
* URI's. When setting this value, the string
* given is assumed to be unescaped. When retrieving this
* value, the resulting string is unescaped.
*
* <p>The path portion can be in one of two formats. 1) an absolute
* path, or 2) a relative path. An absolute path starts with a
* slash ('/'), a relative path does not.</p>
*
* <p>An absolute path may look like:</p>
* <listing>/full/path/to/my/file.htm</listing>
*
* <p>A relative path may look like:</p>
* <listing>
* path/to/my/file.htm
* ../images/logo.gif
* ../../reports/index.htm
* </listing>
*
* <p>Paths can be absolute or relative. Note that this not the same as
* an absolute or relative URI. An absolute URI can only have absolute
* paths. For example:</p>
*
* <listing>http:/site.com/path/to/file.htm</listing>
*
* <p>This absolute URI has an absolute path of "/path/to/file.htm".</p>
*
* <p>Relative URI's can have either absolute paths or relative paths.
* All of the following relative URI's are valid:</p>
*
* <listing>
* /absolute/path/to/file.htm
* path/to/file.htm
* ../path/to/file.htm
* </listing>
*/
public function get path() : String
{
return URI.unescapeChars(_path);
}
public function set path(pathStr:String) : void
{
this._path = URI.fastEscapeChars(pathStr, URI.URIpathExcludedBitmap);
if (this._scheme == UNKNOWN_SCHEME)
{
// We set the path. This is a valid URI now.
this._scheme = "";
}
// Only hierarchical URI's can have a path.
hierState = true;
}
/**
* The query (CGI) portion of the URI. This part is valid for
* both hierarchical and non-hierarchical URI's.
*
* <p>This accessor should only be used if a custom query syntax
* is used. This URI class supports the common "param=value"
* style query syntax via the get/setQueryValue() and
* get/setQueryByMap() functions. Those functions should be used
* instead if the common syntax is being used.
*
* <p>The URI RFC does not specify any particular
* syntax for the query part of a URI. It is intended to allow
* any format that can be agreed upon by the two communicating hosts.
* However, most systems have standardized on the typical CGI
* format:</p>
*
* <listing>http://site.com/script.php?param1=value1¶m2=value2</listing>
*
* <p>This class has specific support for this query syntax</p>
*
* <p>This common query format is an array of name/value
* pairs with its own syntax that is different from the overall URI
* syntax. The query has its own escaping logic. For a query part
* to be properly escaped and unescaped, it must be split into its
* component parts. This accessor escapes/unescapes the entire query
* part without regard for it's component parts. This has the
* possibliity of leaving the query string in an ambiguious state in
* regards to its syntax. If the contents of the query part are
* important, it is recommended that get/setQueryValue() or
* get/setQueryByMap() are used instead.</p>
*
* If a different query syntax is being used, a subclass of URI
* can be created to handle that specific syntax.
*
* @see URI.getQueryValue, URI.getQueryByMap
*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -