OpenWGA 7.11 - TMLScript reference


Object:

URLBuilder

Description

The URLBuilder is a tool object to modify or build URLs.

It contains methods to modify any part of the URL and rebuilds the modified URL again with method build(). All data provided by methods that return parts of the URL is given back decoded. On building the URLs all parts will be encoded properly according to the set encoding.

The methods modifying/builder the URL all return the URLBuilder object again so that method calls can be chained (see examples).

Just like in URL generation in WebTML via <tml:url> the URLBuilder also supports two types of parameters on the URL: Regular URL parameters settable via setParameter() and Var Parameters that are encrypted and added as WebTML variable to the page behind the URL, settable via setVarParameter(). Both are organized completely separately with an own set of methods for each one.

Retrieval WGA.urlBuilder()
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Properties and methods
Name Purpose
absoluteUrlGiven Returns if the URLBuilder object was constructed with an absolute URL as parameter
appendPath(pathElement) Adds a path element to the path part of the URL
build([absolute]) Rebuilds the URL
buildLikeGiven() Builds the URL in the form it was given on creation, either absolute or relative
clearParameters() Removes all URL parameters
clearVarParameters() Removes all var parameters
clone() Creates an identical copy of this URLBuilder object
encoding Contains the encoding by which the URL will be encoded when built
fragment Contains the fragment part of an URL
getParameter(name) Returns the value of an URL parameter
getParameterNames() Returns the names of all URL parameters
getVarParameter(name) Returns the value of a var parameter
getVarParameterNames() Returns the names of all var parameters
hasParameter(name) Returns if an URL parameter of a given name exists
hasVarParameter(name) Returns if an var parameter of a given name exists
host Contains the host part of an URL
path Contains the path part of the URL
port Contains the port of an URL
protocol Contains the protocol part of an URL
removeParameter(name) Removes an URL parameter
removeVarParameter(name) Removes a var parameter
sessionBoundParams Controls if the var parameters on this URL should only be valid on the current user session
setEncoding(encoding) Sets the encoding by which the URL is encoded when built
setFragment(fragment) Sets the fragment part of the URL
setHost(host) Sets the host part of the URL
setParameter(name[, value])
setParameter(map)
Sets an URL parameter
setPath(path) Sets the path part of the URL
setPort(port) Sets the port of the URL
setProtocol(protocol) Sets the protocol part of the URL
setVarParameter(name, value)
setVarParameter(map)
Sets a var parameter
Examples

An example, creating an URLBuilder from a content URL of the current content, adding an URL Parameter an rebuilding it:

var builder = WGA.urlBuilder(contentURL());

builder.setParameter("mode", "1");

return builder.build();

Using method chaining this can also be expressed in a single elegant line:

WGA.urlBuilder(contentURL()).setParameter("mode", "1").build()