205
/** Given an object exactly of the form described for the output of parseurl,
206
* returns a URL string built from those parameters.
207
* parseurl and buildurl are strict inverses of each other.
208
* Note that either query_string or args may be supplied. If both are
209
* supplied, query_string is preferred (because it keeps the argument order).
210
* If you take a url from parseurl, modify args, and pass to buildurl,
211
* you need to set query_string to null to use the new args.
212
* \param obj Object as returned by parseurl.
213
* \return String, a URL.
215
function buildurl(obj)
218
var query_string = null;
220
if (!("scheme" in obj) || obj.scheme != null)
221
url = obj.scheme.toString() + "://";
222
if (!("server_name" in obj) || obj.server_name != null)
223
url += obj.server_name.toString();
224
if (!("server_port" in obj) || obj.server_port != null)
225
url += ":" + obj.server_port.toString();
226
if (!("path" in obj) || obj.path != null)
228
var path = obj.path.toString();
229
if (path.length > 0 && path[0] != "/")
233
if (!("query_string" in obj) || obj.query_string != null)
234
query_string = obj.query_string.toString();
235
else if (!("args" in obj) || obj.args != null)
239
for (var arg_key in obj.args)
241
arg_val = obj.args[arg_key];
242
if (arg_val instanceof Array)
243
for (var i=0; i<arg_val.length; i++)
244
query_string += "&" + encodeURI(arg_key) + "=" +
245
encodeURI(arg_val[i]);
247
query_string += "&" + encodeURI(arg_key) + "=" +
251
if (query_string == "")
254
/* Drop the first "&" */
255
query_string = query_string.substr(1);
258
if (query_string != null)
259
url += "?" + query_string;
205
264
/** Given an argument map, as output in the args parameter of the return of
206
265
* parseurl, gets the first occurence of an argument in the URL string.
207
266
* If the argument was not found, returns null.