You can use SysSingleton.UrlEncode in OCL to convert a string into a form that can travel in a URL; it is intended for developers building URLs or URL-carried data in a Turnkey application.
Signature
UrlEncode(url:String; decode:Boolean):String
The method replaces characters that are not suitable for URL transport.
To make the method available, set the following tagged value on the method:
Eco.ExternalLateBound=true
Use the method from OCL
Call the method through SysSingleton.oclSingleton. Pass the string to prepare for URL transport as the first argument.
SysSingleton.oclSingleton.UrlEncode(compressedbase64,false)
In this example, compressedbase64 is a Base64 string. The second argument is the decode argument in the method signature.
Example: encode compressed data for a URL
The following OCL expression prepares XML data for URL transport. It removes line breaks, converts the text to Base64 bytes, compresses those bytes, converts the compressed result back to Base64, and then URL-encodes the resulting string.
let compressedbase64=SysSingleton.oclsingleton.Deflate(xml.Replace('\r\n', ' ').Replace('\n', ' ').StringToBase64.Base64ToBlob,false).BlobToBase64 in
(
SysSingleton.oclsingleton.UrlEncode(compressedbase64,false)
)
Use this pattern when the value you place in a URL is generated data rather than ordinary URL text. Keep the transformations in the correct order: create the Base64 string first, then apply UrlEncode before placing it in the URL.
Requirements and scope
- Add
Eco.ExternalLateBound=trueto expose this SysSingleton method for use from OCL. - Call the method through
SysSingleton.oclSingleton, as shown in the example. - The method is used in the SysCert example.
- If you compress data before encoding it, use SysSingleton.Deflate for the compression and decompression steps.
