UrlHelper
some utility functions for making URLs
| Title |
some utility functions for making URLs |
| Author(s) |
LiXizhi |
| Date |
2008/2/22 |
| File |
script/kids/3DMapSystemApp/localserver/UrlHelper.lua |
Description
Sample Code
NPL.load("(gl)script/kids/3DMapSystemApp/localserver/UrlHelper.lua");
Map3DSystem.localserver.UrlHelper.WS_to_REST("www.paraengine.com/getPos.asmx", {uid=123, pos = {x=1, y=2}}, {"uid", "pos.x", "pos.y"});
Map3DSystem.localserver.UrlHelper.BuildURLQuery("profile.html", {uid=123, show=true});
Map3DSystem.localserver.UrlHelper.IsDefaultPort("http", 80)
Member Functions
UrlHelper.WS_to_REST
converting a web service request to a
REST-like url. (
REST stands for RESTFUL web)
- param wsUrl : web service url, e.g. "www.paraengine.com/getPos.asmx"
- param msg : the input msg table of the web service. e.g. {uid=123, pos = {x=1, y=2}}
- param fields : an array of text fields in msg. it may contain dot for depth child names. e.g. {"uid", "pos.x", "pos.y"}
- return __ : a unique url is returned, encoding all web service input to a REST url. in the above case, it is "www.paraengine.com/getPos.asmx?uid=123&pos.x=1&pos.y=2"
syntax
function UrlHelper.WS_to_REST(wsUrl, msg, fields)
parameters
| wsUrl |
web service url, e.g. "www.paraengine.com/getPos.asmx" |
| msg |
|
| fields |
an array of text fields in msg. it may contain dot for depth child names. e.g. {"uid", "pos.x", "pos.y"} |
UrlHelper.BuildURLQuery
build url query string. should sort in alphabetic order
- param baseUrl : base url such as "paraengine.com/index.aspx"
- param params : name, value pairs , such as {id=10, time=20}
- return __ : a unique url is returned such as "paraengine.com/index.aspx?id=10&time=20"
syntax
function UrlHelper.BuildURLQuery(baseUrl, params)
parameters
| baseUrl |
base url such as "paraengine.com/index.aspx" |
| params |
|
| return |
a unique url is returned such as "paraengine.com/index.aspx?id=10&time=20" |
UrlHelper.IsWebSerivce
return true if the url is for a web service.
syntax
function UrlHelper.IsWebSerivce(url)
parameters
UrlHelper.IsWebPage
return true if the url is for a web page request, such as RSS feed, HTML, xml, or http
REST call.
syntax
function UrlHelper.IsWebPage(url)
parameters
UrlHelper.IsFileUrl
return true if the url is for a file request, such as zip, jpg, png, etc
syntax
function UrlHelper.IsFileUrl(url)
parameters
UrlHelper.IsDefaultPort
- param scheme : string "http", "https", "file"
- param port : int. 80
- return true : if mapped.
syntax
function UrlHelper.IsDefaultPort(scheme, port)
parameters
| scheme |
string "http", "https", "file" |
| port |
|
| return |
if mapped. |
UrlHelper.IsStringValidPathComponent
string utility functions
Returns true if and only if the entire string (other than terminating null)
consists entirely of characters meeting the following criteria:
- visible ASCII
- None of the following characters: / \ : * ? " < > | ; ,
- Doesn't start with a dot.
- Doesn't end with a dot.
syntax
function UrlHelper.IsStringValidPathComponent(s)
parameters
UrlHelper.EnsureStringValidPathComponent
- return a : modified string, replacing characters that are not valid in a file path component with the '_' character. Also replaces leading and trailing dots with the '_' character See IsCharValidInPathComponent?
syntax
function UrlHelper.EnsureStringValidPathComponent(s)
parameters
|
return | modified string, replacing characters that are not valid in a file path
component with the '_' character. Also replaces leading and trailing dots with the '_' character
See
IsCharValidInPathComponent? |
UrlHelper.url_decode
UNTESTED: Decode an URL-encoded string
(Note that you should only decode a URL string after splitting it; this allows you to correctly process quoted "?" characters in the query string or base part, for instance.)
syntax
function UrlHelper.url_decode(str)
parameters
UrlHelper.url_encode
UNTESTED: URL-encode a string
syntax
function UrlHelper.url_encode(str)
parameters
UrlHelper.url_getparams
get request url parameter by its name. for example if page url is "www.paraengine.com/user?id=10&time=20", then
GetRequestParam? ("id") will be "10".
- param request :_url: url to from which to get parameters
- param paramName : parameter name.
- return __ : nil or string value.
syntax
function UrlHelper.url_getparams(request_url, paramName)
parameters
| request |
_url: url to from which to get parameters |
| url |
|
| paramName |
|
| return |
nil or string value. |
UrlHelper.ValidateEmailAddress
UNTESTED: Match Email addresses
syntax
function UrlHelper.ValidateEmailAddress(email)
parameters