Uri Extends Object
This class contains setters and getters for the parts of the URI. The getXyz/setXyz methods return the decoded part -- sogoog.Uri.parse('/foo%20bar').getPath() will return the decoded path, /foo bar. The constructor accepts an optional unparsed, raw URI string. The parser is relaxed, so special characters that aren't escaped but don't cause ambiguities will not cause parse failures. All setters return this and so may be chained, a la goog.Uri.parse('/foo').setFragment('part').toString().

Inheritance

Constructor

goog.Uri(opt_uriopt_ignoreCase)

Parameters

opt_uri :
*
Optional string URI to parse (use goog.Uri.create() to create a URI from parts), or if a goog.Uri is passed, a clone is created.
opt_ignoreCase :
(boolean | undefined)
If true, #getParameterValue will ignore the case of the parameter name.

Instance Methods

Public Protected Private
Defined in goog.Uri
clone()
Clones the URI instance.
Returns:   New instance of the URI objcet.
code »
enforceReadOnly()
Checks if this Uri has been marked as read only, and if so, throws an error. This should be called whenever any modifying function is called.
code »
getDecodedQuery()
No description.
Returns:   The decoded URI query, not including the ?.
code »
getDomain()
No description.
Returns:   The decoded domain.
code »
getEncodedQuery()
No description.
Returns:   The encoded URI query, not including the ?.
code »
getFragment()
No description.
Returns:   The URI fragment, not including the #.
code »
getIgnoreCase()
No description.
Returns:   Whether to ignore case.
code »
getParameterValue(paramName)
*
Returns the first value for a given cgi parameter or undefined if the given parameter name does not appear in the query string.
Arguments:
paramName :
Unescaped parameter name.
Returns: 
*
  The first value for a given cgi parameter or undefined if the given parameter name does not appear in the query string.
code »
getParameterValues(name)
(Array | null)
Returns the values for a given cgi parameter as a list of decoded query parameter values.
Arguments:
name :
The parameter to get values for.
Returns: 
(Array | null)
  The values for a given cgi parameter as a list of decoded query parameter values.
code »
getPath()
No description.
Returns:   The decoded path.
code »
getPort()
(null | number)
No description.
Returns: 
(null | number)
  The port number.
code »
getQuery()
No description.
Returns:   The encoded URI query, not including the ?. Warning: This method, unlike other getter methods, returns encoded value, instead of decoded one.
code »
getQueryData()
Returns the query data.
Returns:   QueryData object.
code »
getScheme()
No description.
Returns:   The encoded scheme/protocol for the URI.
code »
getUserInfo()
No description.
Returns:   The decoded user info.
code »
hasDomain()
No description.
Returns:   Whether the domain has been set.
code »
hasFragment()
No description.
Returns:   Whether the URI has a fragment set.
code »
hasPath()
No description.
Returns:   Whether the path has been set.
code »
hasPort()
No description.
Returns:   Whether the port has been set.
code »
hasQuery()
No description.
Returns:   Whether the query string has been set.
code »
hasSameDomainAs(uri2)
Returns true if this has the same domain as that of uri2.
Arguments:
uri2 :
(goog.Uri | null)
The URI object to compare to.
Returns:   true if same domain; false otherwise.
code »
hasScheme()
No description.
Returns:   Whether the scheme has been set.
code »
hasUserInfo()
No description.
Returns:   Whether the user info has been set.
code »
isReadOnly()
No description.
Returns:   Whether the URI is read only.
code »
makeUnique()
Adds a random parameter to the Uri.
Returns:   Reference to this Uri object.
code »
removeParameter(key)
Removes the named query parameter.
Arguments:
key :
The parameter to remove.
Returns:   Reference to this URI object.
code »
resolve(relativeUri)
Resolves a relative url string to a this base uri. There are several kinds of relative urls:
1. foo - replaces the last part of the path, the whole query and fragment
2. /foo - replaces the the path, the query and fragment
3. //foo - replaces everything from the domain on. foo is a domain name
4. ?foo - replace the query and fragment
5. #foo - replace the fragment only Additionally, if relative url has a non-empty path, all ".." and "." segments will be resolved, as described in RFC 3986.
Arguments:
relativeUri :
(goog.Uri | null)
The relative url to resolve.
Returns:   The resolved URI.
code »
setDomain(newDomainopt_decode)
Sets the domain.
Arguments:
newDomain :
New domain value.
opt_decode :
(boolean | undefined)
Optional param for whether to decode new value.
Returns:   Reference to this URI object.
code »
setFragment(newFragmentopt_decode)
Sets the URI fragment.
Arguments:
newFragment :
New fragment value.
opt_decode :
(boolean | undefined)
Optional param for whether to decode new value.
Returns:   Reference to this URI object.
code »
setIgnoreCase(ignoreCase)
Sets whether to ignore case. NOTE: If there are already key/value pairs in the QueryData, and ignoreCase_ is set to false, the keys will all be lower-cased.
Arguments:
ignoreCase :
whether this goog.Uri should ignore case.
Returns:   Reference to this Uri object.
code »
setParameterValue(keyvalue)
Sets the value of the named query parameters, clearing previous values for that key.
Arguments:
key :
The parameter to set.
value :
*
The new value.
Returns:   Reference to this URI object.
code »
setParameterValues(keyvalues)
Sets the values of the named query parameters, clearing previous values for that key. Not new values will currently be moved to the end of the query string. So, goog.Uri.parse('foo?a=b&c=d&e=f').setParameterValues('c', ['new']) yields foo?a=b&e=f&c=new.
Arguments:
key :
The parameter to set.
values :
*
The new values. If values is a single string then it will be treated as the sole value.
Returns:   Reference to this URI object.
code »
setPath(newPathopt_decode)
Sets the path.
Arguments:
newPath :
New path value.
opt_decode :
(boolean | undefined)
Optional param for whether to decode new value.
Returns:   Reference to this URI object.
code »
setPort(newPort)
Sets the port number.
Arguments:
newPort :
*
Port number. Will be explicitly casted to a number.
Returns:   Reference to this URI object.
code »
setQuery(newQueryopt_decode)
Sets the URI query.
Arguments:
newQuery :
New query value.
opt_decode :
(boolean | undefined)
Optional param for whether to decode new value.
Returns:   Reference to this URI object.
code »
setQueryData(queryDataopt_decode)
Sets the query data.
Arguments:
queryData :
(goog.Uri.QueryData | null | string | undefined)
QueryData object.
opt_decode :
(boolean | undefined)
Optional param for whether to decode new value. Applies only if queryData is a string.
Returns:   Reference to this URI object.
code »
setReadOnly(isReadOnly)
Sets whether Uri is read only. If this goog.Uri is read-only, enforceReadOnly_ will be called at the start of any function that may modify this Uri.
Arguments:
isReadOnly :
whether this goog.Uri should be read only.
Returns:   Reference to this Uri object.
code »
setScheme(newSchemeopt_decode)
Sets the scheme/protocol.
Arguments:
newScheme :
New scheme value.
opt_decode :
(boolean | undefined)
Optional param for whether to decode new value.
Returns:   Reference to this URI object.
code »
setUserInfo(newUserInfoopt_decode)
Sets the userInfo.
Arguments:
newUserInfo :
New userInfo value.
opt_decode :
(boolean | undefined)
Optional param for whether to decode new value.
Returns:   Reference to this URI object.
code »
toString()
No description.
Returns:   The string form of the url.
code »

Instance Properties

Defined in goog.Uri
domain_ :
Domain part, e.g. "www.google.com".
Code »
fragment_ :
The fragment without the #.
Code »
ignoreCase_ :
Whether or not to ignore case when comparing query params.
Code »
isReadOnly_ :
Whether or not this Uri should be treated as Read Only.
Code »
path_ :
Path, e.g. "/tests/img.png".
Code »
port_ :
(null | number)
Port, e.g. 8080.
Code »
queryData_ :
Object representing query data.
Code »
scheme_ :
Scheme such as "http".
Code »
userInfo_ :
User credentials in the form "username:password".
Code »

Static Methods

goog.Uri.create(opt_schemeopt_userInfoopt_domainopt_portopt_pathopt_queryopt_fragmentopt_ignoreCase)
Creates a new goog.Uri object from unencoded parts.
Arguments:
opt_scheme :
(null | string | undefined)
Scheme/protocol or full URI to parse.
opt_userInfo :
(null | string | undefined)
username:password.
opt_domain :
(null | string | undefined)
opt_port :
(null | number | undefined)
9830.
opt_path :
(null | string | undefined)
/some/path/to/a/file.html.
opt_query :
(goog.Uri.QueryData | null | string | undefined)
a=1&b=2.
opt_fragment :
(null | string | undefined)
The fragment without the #.
opt_ignoreCase :
(boolean | undefined)
Whether to ignore parameter name case in #getParameterValue.
Returns:   The new URI object.
code »
goog.Uri.decodeOrEmpty_(val)
Decodes a value or returns the empty string if it isn't defined or empty.
Arguments:
val :
(string | undefined)
Value to decode.
Returns:   Decoded value.
code »
goog.Uri.encodeChar_(ch)
Converts a character in [\01-\177] to its unicode character equivalent.
Arguments:
ch :
One character string.
Returns:   Encoded string.
code »
goog.Uri.encodeSpecialChars_(unescapedPartextra)
(null | string)
If unescapedPart is non null, then escapes any characters in it that aren't valid characters in a url and also escapes any special characters that appear in extra.
Arguments:
unescapedPart :
*
The string to encode.
extra :
(RegExp | null)
A character set of characters in [\01-\177].
Returns: 
(null | string)
  null iff unescapedPart == null.
code »
goog.Uri.encodeString_(unescapedPart)
(null | string)
URI encode a string, or return null if it's not a string.
Arguments:
unescapedPart :
*
Unescaped string.
Returns: 
(null | string)
  Escaped string.
code »
goog.Uri.haveSameDomain(uri1Stringuri2String)
Checks whether two URIs have the same domain.
Arguments:
uri1String :
First URI string.
uri2String :
Second URI string.
Returns:   true if the two URIs have the same domain; false otherwise.
code »
goog.Uri.parse(uriopt_ignoreCase)
Creates a uri from the string form. Basically an alias of new goog.Uri(). If a Uri object is passed to parse then it will return a clone of the object.
Arguments:
uri :
*
Raw URI string or instance of Uri object.
opt_ignoreCase :
(boolean | undefined)
Whether to ignore the case of parameter names in #getParameterValue.
Returns:   The new URI object.
code »
goog.Uri.removeDotSegments(path)
Removes dot segments in given path component, as described in RFC 3986, section 5.2.4.
Arguments:
path :
A non-empty path component.
Returns:   Path component with removed dot segments.
code »
goog.Uri.resolve(baserel)
Resolves a relative Uri against a base Uri, accepting both strings and Uri objects.
Arguments:
base :
*
Base Uri.
rel :
*
Relative Uri.
Returns:   Resolved uri.
code »

Static Properties

goog.Uri.RANDOM_PARAM :
Parameter name added to stop caching.
Code »
goog.Uri.encodeSpecialRegExp_ :
(RegExp | null)
Regular expression used for determining if a string needs to be encoded.
Code »
goog.Uri.reDisallowedInAbsolutePath_ :
(RegExp | null)
Regular expression for characters that are disallowed in an absolute path.
Code »
goog.Uri.reDisallowedInFragment_ :
(RegExp | null)
Regular expression for characters that are disallowed in the fragment.
Code »
goog.Uri.reDisallowedInQuery_ :
(RegExp | null)
Regular expression for characters that are disallowed in the query.
Code »
goog.Uri.reDisallowedInRelativePath_ :
(RegExp | null)
Regular expression for characters that are disallowed in a relative path.
Code »
goog.Uri.reDisallowedInSchemeOrUserInfo_ :
(RegExp | null)
Regular expression for characters that are disallowed in the scheme or userInfo part of the URI.
Code »

Package Uri

Package Reference