WMLScript Reference

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 8 - Libraries
Section 28 out of 34 total sections , Section 6 out of 9 sections in this chapter


URL Library

The URL library contains a set of functions for handling absolute URLs and relative URLs. The general URL syntax is:

<scheme>://<host>:<port>/<path>;<params>?<query>#<fragment>  

For more information, visit:

http://info.internet.isi.edu/in-notes/rfc/files/rfc2396.txt  

Included in this section are the following function calls:

Function call 

escapeString 

getBase 

getFragment 

getHost 

getParameters 

getPath 

getPort 

getQuery 

getReferer 

getScheme 

isValid 

loadString 

resolve 

unescapeString 



escapeString

url.escapeString(string)  

This function computes a new version of a string value in which special characters have been replaced by a hexadecimal escape sequence; a two-digit escape sequence of the form %xx must be used. For more information, visit:

http://info.internet.isi.edu/in-notes/rfc/files/rfc2396.txt  

The characters to be escaped are:

Control characters 

<US-ASCII coded characters 00-1F and 7F>  

Space 

<US-ASCII coded character 20 hexadecimal>  

Reserved 

;  /  ?  :  @  &  =  +  $  ,  

Unwise 

(  )  |  \  ^  [  ]  '  

Delims 

<  >  #  %  "  

The given string is escaped as such. No URL parsing is performed.


Parameters

string = String


Return Value

String or invalid.


Exceptions

If string contains characters that are not part of the US-ASCII character set, an invalid value is returned.


Examples

var a = URL.escapeString("http://w.h.com/dck?x=\u007f#crd");  
    // a = "http%3a%2f%2fw.h.com%2fdck%3fx%3d%7f%23crd"  


getBase

url.getBase()  

Returns an absolute URL (without the fragment) of the current WMLScript 1.1 file.


Return Value

String


Examples

var a = URL.getBase();
    // a = "http://www.host.com/test.scr"
 



getFragment

url.getFragment(url)  

Returns the fragment used in the given url. If no fragment is specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered while extracting the fragment, an invalid value is returned.


Examples

var a = URL.getFragment("http://w.h.com/cont#frag");  
    // a = "frag"  


getHost

url.getHost(url)  

Returns the host specified in the given url. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered while extracting the host part, an invalid value is returned.


Examples

var a = URL.getHost("http://w.h.com/path#frag");  
    // a = "w.h.com"  
var b = URL.getHost("path#frag");  
    // b = ""  


getParameters

url.getParameters(url)  

Returns the parameters used in the given url. If no parameters are specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered while extracting the parameters, an invalid value is returned.


Examples

a = URL.getParameters("http://w.h.com/script;3;27x=1&y=3");  
    // a = "3;2"  
b = URL.getParameters("../script;3;2?x=1&y=3");  
    // b = "3;2"  


getPath

url.getPath(url)  

Returns the path specified in the given url. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered while extracting the path, an invalid value is returned.


Examples

a = URL.getPath("http://w.h.com/home/sub/comp#frag");  
    // a = "3;2"  
b = URL.getParameters("../script;3;2?x=1&y=3");  
    // b = "3;2"  
   // b = "../home/sub/comp"  


getPort

url.getPort(url)  

Returns the port number specified in the given url. If no port is specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered while extracting the port number, an invalid value is returned.


Examples

var a = URL.getPort("http://w.h.com:80/path#frag");  
    // a = "80"  
var b = URL.getPort("http://w.h.com/path#frag");  
    // b = ""  


getQuery

url.getQuery(url)  

Returns the query part specified in the given url. If no query part is specified, an empty string is returned. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered while extracting the query part, an invalid value is returned.


Examples

a = URL.getParameters("http://w.h.com/home;3;2?x=1&y=3");
    // a = "x=1&y=3"
 

var base       = URL.getBase();
    // base    = "http://www.host.com/current.scr"
 



getReferer

url.getReferer()  

Returns the smallest relative URL (relative to the base URL of the current file) to the resource that called the current file. Local function calls do not change the referer. If the current file does not have a referer, an empty string ("") is returned.


Return Value

String


Examples

var referer    = URL.getReferer();  
    // referer = "app.wml"  


getScheme

url.getScheme(url)  

Returns the scheme used in the given url. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered while extracting the scheme, an invalid value is returned.


Examples

var a = URL.getScheme("http://w.h.com/path#frag");  
    // a = "http"  
var b = URL.getScheme("w.h.com/path#frag");  
    // b = ""  


isValid

url.isValid(url)  

Returns true if the given url has the right URL syntax, otherwise returns false. Both absolute and relative URLs are supported. Relative URLs are not resolved into absolute URLs.


Parameters

url = String


Return Value

Boolean or invalid


Examples

var a = URL.isValid("http://w.hst.com/script#func()");  
    // a = true  
var b = URL.isValid("../common#test()");  
    // b = true  
var c = URL.isValid("experimental?://www.host.com/cont");  
    // c = false  


loadString

url.loadString(url, contentType)  

Returns the content denoted by the given absolute url and the content type.

The given content type is erroneous if it does not comply with the following rules:

The behavior of this function is the following:


Parameters

url = String

contentType = String


Return Value

String, integer, or invalid.


Exceptions

Returns an integer error code that depends on the used URL scheme in case the load fails. If HTTP or WSP schemes are used, HTTP error codes are returned.

If an erroneous content type is given, an invalid value is returned.


Examples

var myUrl = "http://www.host.com/vcards/myaddr.vcf";  
myCard = URL.loadString(myUrl, "text/x-vcard");  


resolve

url.resolve(baseUrl, embeddedUrl)  

Returns an absolute URL from the given baseUrl and the embeddedUrl. For more information, visit:

http://info.internet.isi.edu/in-notes/rfc/files/rfc2396.txt  

If the embeddedUrl is already an absolute URL, the function returns it without modification.


Parameters

baseUrl = String

embeddedUrl = String


Return Value

String or invalid.


Exceptions

If an invalid URL syntax is encountered as part of the resolution an invalid value is returned.


Examples

var a = URL.resolve("http://foo.com/","foo.vcf");  
    // a = "http://foo.com/foo.vcf"  


unescapeString

url.unescapeString(string)  

The unescape function computes a new version of a string value in which each escape sequence of the sort that might be introduced by the URL.escapeString() function is replaced with the character that it represents. The given string is unescaped as such. No URL parsing is performed.


Parameters

string = String


Return Value

String or invalid.


Exceptions

If string contains characters that are not part of the US-ASCII character set, an invalid value is returned.


Examples

var a = "http%3a%2f%2fw.h.com%2fdck%3fx%3d12%23crd";  
var b = URL.unescapeString(a);  
    // b = "http://w.h.com/dck?x=12#crd"  

[Cover] [Previous Section] [Next Section] [Index]


Part Number DKWS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.