Encoding Functions

In this section:

Encoding functions enable you to decode and convert strings. This section lists and describes the various encoding functions that you can use in iWay Service Manager.


Top of page

x
_url(): Convert String to MIME Format

The _url() function converts the URL string to the application/x-www-form-urlencoded MIME format. For more information about HTML form encoding, consult the HTML specification. The _url() function uses the following format:

_url(URLString [,encoding])

URLString

string

The string to convert.

encoding

string

IANA encoding for the string.

When encoding the string, the following rules apply:

For example, using UTF-8 as the encoding scheme the string The string ü@foo-bar would get converted to The+string+%C3%BC%40foo-bar because in UTF-8 the character ü is encoded as two bytes C3 (hex) and BC (hex), and the character @ is encoded as one byte 40 (hex).

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities. For this reason, UTF-8 is the default encoding regardless of the encoding under which the listener is running.

If the function determines that the passed string is a valid URL, it encodes only the portion following the '?'. This is called the <query> in the URL specification. Otherwise, it encodes the complete string.

For example, the URL http://localhost:1456?value=1 test=2 will encode to http://localhost:1456?value=1+test=2.



x
_urlencode(): Convert String to MIME Encoding

The _urlencode() function converts the full passed in string to the application/x-www-form-urlencoded MIME format. For more information about HTML form encoding, consult the HTML specification. The string is not checked for URL format. The _urlencode() function uses the following format:

_urlencode(String [,encoding])

String

string

The string to convert.

encoding

string

IANA encoding for the string.

When encoding the string, the following rules apply:

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilities. For this reason, UTF-8 is the default encoding regardless of the encoding under which the listener is running.

Unlike the _url() function, no effort is made to validate the input string. Instead, it encodes the complete string. For example, http://localhost:1456?value=1 test=2 will encode to http%3A%2F%2Flocalhost%3A1456%3Fvalue%3D1+test%3D2.



x
_urldecode():Decode a String in MIME Format

The _urldecode() function decodes a string from the application/x-www-form-urlencoded MIME format into standard format for use as a parameter, inclusion in an XML value, and so on. It uses the following format:

_urldecode(URL String [,encoding])

URLString

string

The string to convert.

encoding

string

IANA encoding for the string.

The conversion process is the reverse of that used by the _urlencode() function. It is assumed that all characters in the encoded string are one of the following: "a" through "z", "A" through "Z", "0" through "9", and "-", "_", ".", and "*". The character "%" is allowed but is interpreted as the start of a special escaped sequence.

If the encoding is not specified, UTF-8 is assumed, in accord with the recommendations as described by the _urlencode() function.



x
_base64():Encode Into Base64

The _base64() function uses the following format:

_base64(value)

value

string

The value to encode.

encoding

string

The encoding to be used in creating the base64.

The input may be represented in a non-server encoding. To set the encoding for the conversion, the encoding parameter must be used.

For example, if you want to transfer the current message (document payload) to a third-party in base64 form, configure the function as follows:

_base64(_flatof(),_docinfo('encoding'))


x
_frombase64():Decode From Base64

The _frombase64() function uses the following format:

_frombase64(value)

value

string

The string to convert.

encoding

string

The encoding to be used in creating the base64.

The passed value is converted from base64 representation to standard notation.



x
_encode64():Conditionally Encode Into Base64

The _encode64() function uses the following format:

_encode64(value)

value

string

The string to convert.

encoding

string

The encoding to be used in creating the base64.

If the value requires base64 encoding it is converted to base 64, else it is returned with no conversion. Examples of values that need base64 conversion include those with values lower than 0x20.

If conversion is required, the converted value is enclosed in base64() functional notation.



x
_decode64(): Conditionally Decode From Base64

The _decode64() function uses the following format:

_decode64(value)

value

string

The string to convert.

encoding

string

The encoding to be used in creating the base64.

If the input value is enclosed in base64() functional notation. it is converted. Otherwise, it is not changed.

Example 1:

_decode64('base64(YWJj)')

In this example, the string is decoded as 'abc'.

Example 2:

_decode64('abcd')

In this example, the string is not decoded since it is not enclosed in the base64 tag.



x
_fmtdec(): Insert an Integer Into a Pattern Mask

The _fmtdec() function is useful when a value must be in a specific format. It uses the following format:

_fmtdec(pattern,intval)

pattern

string

Define the string to be created.

intval

integer

Value to be inserted.

The value is inserted into the pattern mask to form a complete result. The mask consists of alphabetic and numeric characters and special symbols as defined for Java formatting. When the value is inserted, the appropriate pattern characters are replaced with the value. For example _fmtdec('ab##.#x',17.3) yields ab17.3x.



x
_fmtint(): Insert an Integer Into a Pattern Mask

The _fmtint() function is useful when a value for a control number is read from the trading partner manager or another source. It uses the following format:

_fmtint(pattern,intval)

pattern

string

Define the string to be created.

intval

integer

Value to be inserted.

The integer is inserted into the pattern mask to form a complete result. The mask consists of alphabetic and numeric characters and special symbols. It also should contain one sequence of # characters. When the integer is inserted, the # characters are replaced with the integer. For example _fmtint('ab###x',17) yields ab017x.



x
_urlparse() Extract Portions of a URL/URI
_urlparse(URL String, component [,query_kw [,default]])

URLString

string

The string to parse.

component

string

The name of the desired component.

query_kw

string

A keyword to be located in the query portion of the URL.

default

string

Value returned if the query keyword is not found.

The Uniform resource Locator/Identified is parsed in order to extract useful pieces. The components are as described in RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax (http://www.ietf.org/rfc/rfc2396.txt).

The component parameter, which is required, can be one of these RFC-identified words:

When parsing for the query component, two additional parameters are supported. The first is a keyword to be located, and the second is a default. The keyword is a URL keyword contained in the query. If the keyword is not found, the default is returned. If the default is not present, an empty string is returned. For example:

_urlparse('http://www.url.com/look?q=iway','query','q','hello')

yields iway.

In addition, we have two more keywords for simplicity of use:

Note that file and filename are not synonyms. File returns the URL path plus any query string.

To extract specific portions of the returned information, the _token() function can be used.


iWay Software