Utility Class Methods
In this section, the Utility class methods are presented in alphabetical order.
Syntax
dateStringToUserPref(DateString)
Description
Use this method to transform a date string from the "yyyy-MM-dd" format to the user-preferred date format.
Parameters
Field or Control |
Definition |
---|---|
DateString |
Specifies the date string to be transformed. |
Returns
A string containing the date in the user-preferred date format.
Syntax
datetimeToString(Datetime)
Description
Use this method to transform a DateTime value to a string in “yyyy-MM-dd HH:mm:ss” format.
Parameters
Field or Control |
Definition |
---|---|
Datetime |
Specifies the DateTime value to be transformed. |
Returns
A string in “yyyy-MM-dd HH:mm:ss” format or an empty string if the DateTime value is empty.
Syntax
dateToString(Date)
Description
Use this method to transform a date value to a string in “yyyy-MM-dd” format.
Parameters
Field or Control |
Definition |
---|---|
Date |
Specifies the date value to be transformed. |
Returns
A string in “yyyy-MM-dd” format or an empty string if the date value is empty.
Syntax
decodeXML(String)
Description
Use this method to decode the following encoded XML characters in the source string:
Encoded Character |
Decoded Character |
---|---|
< |
< (less than) |
> |
> (greater than) |
& |
& (ampersand) |
' |
' (apostrophe) |
" |
" (quotation mark) |
Parameters
Field or Control |
Definition |
---|---|
String |
Specifies the source XML string with encoded characters to be decoded. |
Returns
A string containing the source XML string with encoded characters decoded.
Example
For &i = 1 To &elementList.Len
&valueList = CreateArrayRept("", &pChildTags.Len);
For &j = 1 To &pChildTags.Len
&thisValue = %This.getNodeValue(&elementList [&i], &pChildTags [&j]);
&valueList [&j] = %This.decodeXML(&thisValue);
End-For;
&return_value.Push(&valueList);
End-For;
Syntax
encodeXML(String)
Description
Use this method to encode the following special characters in the source string as encoded XML characters:
Character |
Encoded Character |
---|---|
< (less than) |
< |
> (greater than) |
> |
& (ampersand) |
& |
' (apostrophe) |
' |
" (quotation mark) |
" |
Parameters
Field or Control |
Definition |
---|---|
String |
Specifies the source string with special characters to be encoded. |
Returns
A string containing the source string with the special characters encoded.
Example
If (&pValues [&i] <> Null) And
(&pChildTags <> Null) Then
/* get the children */
For &j = 1 To &pValues [&i].Len
If &j > &pChildTags.Len Then
Break;
End-If;
&thisElement = &thisElement | %This.setNodeValue(%This.encodeXML(&pValues [&i][&j]), &pChildTags [&j]);
End-For;
End-If;
Syntax
evaluateSysVar(SysVar)
Description
Use this method to evaluate and return the value of a system variable.
Parameters
Field or Control |
Definition |
---|---|
SysVar |
Specifies the system variable to be evaluated as a string. |
Returns
A string representation of the evaluated system variable, or the system variable name if it cannot be evaluated.
Syntax
genNameSpaceID(NameSpace_ID)
Description
Use this method to replace special characters in the original ID string with “_”, so that it only contains “A–Z”, “0–9” and “_”.
Parameters
Field or Control |
Definition |
---|---|
NameSpace_ID |
Specifies the name space ID to be converted as a string. |
Returns
A string containing the generated name space ID using only “A–Z”, “0–9” and “_”.
Syntax
getExceptionText(&Exception)
Description
Use this method to return the exception error message.
Parameters
Field or Control |
Definition |
---|---|
&Exception |
Specifies the exception as an Exception object. |
Returns
The exception error message as a string.
Syntax
getFeedDoc(feed_ID, Format, &Attributes)
Description
Use this method to create a FeedDoc object of the given feed format.
Parameters
Field or Control |
Definition |
---|---|
feed_ID |
Specifies the ID of the feed definition as a string. |
Format |
Specifies the feed format as a string. The values are: |
Value |
Description |
---|---|
&utility.FEEDFORMAT_ATOM10 |
An Atom 1.0 format feed. |
Field or Control |
Definition |
---|---|
&Attributes |
Specifies the feed-level properties as an Attribute collection. |
Returns
A FeedDoc object of the given feed format with properties filled in from the Attribute collection.
Example
import PTFP_FEED:FeedFactory;
import PTFP_FEED:XML_FEED:FeedDoc;
import PTFP_FEED:XML_FEED:FeedEntry;
Local PTFP_FEED:FeedFactory &thisFeedFactory = create PTFP_FEED:FeedFactory();
Local PTFP_FEED:XML_FEED:FeedDoc &this_FeedDoc = &thisFeedFactory.Utility.getFeedDoc("feed_ID", &thisFeedFactory.Utility.FEEDFORMAT_ATOM10, Null);
Local PTFP_FEED:XML_FEED:FeedEntry &this_Entry = &this_FeedDoc.addEntry("entry_ID");
Syntax
getFeedMimeType(Format)
Description
Use this method to return the MIME type of the given feed format.
Parameters
Field or Control |
Definition |
---|---|
Format |
Specifies the feed format as a string. The values are: |
Value |
Description |
---|---|
&utility.FEEDFORMAT_ATOM10 |
An Atom 1.0 format feed. |
Returns
A string containing the MIME type as follows:
Feed Format Constant |
MIME Type Constant |
MIME Type |
---|---|---|
&utility.FEEDFORMAT_ATOM10 |
MIMETYPE_ATOM |
application/atom+xml |
undefined |
MIMETYPE_XML |
application/xml |
Syntax
getFieldTranslates(FieldName)
Description
Use this method to return the valid translate values of a field.
Parameters
Field or Control |
Definition |
---|---|
FieldName |
Specifies the field name for which to retrieve translate values, as a string. |
Returns
An array of array of string.
Syntax
getNodeValue(String, Tag)
Description
Use this method to extract the value from the first element enclosed by the given tag in the source string.
Parameters
Field or Control |
Definition |
---|---|
String |
Specifies the string to check. |
Tag |
Specifies the tag to search for as a string. |
Returns
A string containing the value from the first element enclosed by the specified tag.
Example
import PTFP_FEED:UTILITY:Utility;
Local PTFP_FEED:UTILITY:Utility &utility = create PTFP_FEED:UTILITY:Utility();
&str = "<div><p>value1</p><p>value2</p></div>";
&str1 = &utility.getNodeValue(&str, "p");
/* &str1="value1" */
Syntax
getUserDateFormat()
Description
Use this method to construct and return the date format string based on the user's personalization settings.
Parameters
None.
Returns
A string containing the format mask representing the user's preferred date format—for example: MM-dd-yyyy.
Syntax
getUserDatetimeFormat()
Description
Use this method to construct and return the date/time format string based on the user's personalization settings.
Parameters
None.
Returns
A string containing the format mask representing the user's preferred date/time format—for example: MM-dd-yyyy hh:mm a.
Syntax
getUserInfo(user_ID)
Description
Use this method to return the user name and email address of the given user ID.
Parameters
Field or Control |
Definition |
---|---|
user_ID |
Specifies the user ID for which to retrieve the user information, as a string. |
Returns
An array of string containing two elements:
User name (or the user ID if this is empty).
Email address (or an empty string if this is empty).
Syntax
httpStringToDatetime(string)
Description
Use this method to convert an HTTP date/time string in the "dow, dd mmm yyyy hh:mm:ss GMT" format to a DateTime value.
Parameters
Field or Control |
Definition |
---|---|
string |
Specifies the HTTP date/time string in the "dow, dd mmm yyyy hh:mm:ss GMT" format. |
Returns
A DateTime value.
Syntax
join(&Array, Tag)
Description
Use this method to concatenate the string array together enclosing each string element in the specified tag.
Parameters
Field or Control |
Definition |
---|---|
&Array |
Specifies the array of string to be concatenated together. |
Tag |
Specifies the tag to enclose each string element. |
Returns
A string containing the concatenation of each of the string elements enclosed by the specified tag.
Example
import PTFP_FEED:UTILITY:Utility;
Local PTFP_FEED:UTILITY:Utility &utility = create PTFP_FEED:UTILITY:Utility();
&str = &utility.join(CreateArray("value1", "value2"), "p");
/* &str="<p>value1</p><p>value2</p>" */
Syntax
join2D(&Array, Tag, ChildTags)
Description
Use this method to concatenate the array of array of string together enclosing each element in the specified tag. Each child element is XML encoded and enclosed in the child tag.
Parameters
Field or Control |
Definition |
---|---|
&Array |
Specifies the array of array of string to be concatenated together. |
Tag |
Specifies the tag to enclose each string element, as a string. |
ChildTags |
Specifies the tags to enclose each child element, as an array of string. |
Returns
A string containing the concatenation of each of the string elements enclosed by the specified tag. Each child element is XML encoded and enclosed in the child tag.
Example
import PTFP_FEED:UTILITY:Utility;
Local PTFP_FEED:UTILITY:Utility &utility = create PTFP_FEED:UTILITY:Utility();
&str = &utility.join2D(CreateArray(CreateArray("value1", "value2")), "div", CreateArray("b", "i"));
/* &str="<div><b>value1</b><i>value2</i></div>" */
Syntax
setMessageHeadersAndMimeType(&Message, &feeddoc, &FeedRequest)
Description
Use this method to return the specified Message object with the MIME type set, and populated with the specified FeedDoc. If the feed is an incremental feed, then incremental feed information is set as connector properties for the message.
Parameters
Field or Control |
Definition |
---|---|
&Message |
Specifies the Message object to be returned. |
&feeddoc |
Specifies the feed document to be returned specified as an XmlDoc object. |
&FeedRequest |
Specifies the feed as a FeedRequest object. |
Returns
A Message object.
Syntax
setNodeValue(Value, Tag)
Description
Use this method to form an element using the given value and tag name.
Parameters
Field or Control |
Definition |
---|---|
Value |
Specifies the string value to enclose in the tags. |
Tag |
Specifies the tag to enclose the value within, as a string. |
Returns
A string element containing the value enclosed within the given tag.
Example
import PTFP_FEED:UTILITY:Utility;
Local PTFP_FEED:UTILITY:Utility &utility = create PTFP_FEED:UTILITY:Utility();
&str1 = &utility.setNodeValue("value", "p");
/* &str="<p>value</p>" */
Syntax
showException(Exception)
Description
Use this method to raise an error when the component variable &PTFP_THROWPAGELETEXCEPTIONS is false, otherwise throw the exception.
Parameters
Field or Control |
Definition |
---|---|
Exception |
Specifies the exception as an Exception. |
Returns
None.
Syntax
showInvalidValueException(Name, Value)
Description
Use this method to show an invalid value exception using the showException method.
Parameters
Field or Control |
Definition |
---|---|
Name |
Specifies the name of the property as a string. |
Value |
Specifies the value that is invalid as a string. |
Returns
None
Syntax
split()
Description
Use this method to extract the elements from the string that are enclosed in the specified tag.
Parameters
Field or Control |
Definition |
---|---|
String |
Specifies the string to check. |
Tag |
Specifies the tag to search for as a string. |
Returns
An array of string containing the string elements enclosed by the specified tag.
Example
import PTFP_FEED:UTILITY:Utility;
Local PTFP_FEED:UTILITY:Utility &utility = create PTFP_FEED:UTILITY:Utility();
&str = "<p>value1</p><p>value2</p>";
&arr = &utility.split(&str, "p");
/* &arr[1]="value1", &arr[2]="value2" */
Syntax
split2D()
Description
Use this method to extract the elements from the string that are enclosed in the specified tag. Child elements enclosed by the child tags are also extracted. All elements are XML decoded.
Parameters
Field or Control |
Definition |
---|---|
String |
Specifies the string to check. |
Tag |
Specifies the tag that encloses each string element, as a string. This tag can be an empty string. |
ChildTags |
Specifies the tags that enclose each child element, as an array of string. |
Returns
An array of array of string containing the extracted string elements enclosed by the specified tags. Child elements are enclosed by the child tags. All elements are XML decoded.
Example
import PTFP_FEED:UTILITY:Utility;
Local PTFP_FEED:UTILITY:Utility &utility = create PTFP_FEED:UTILITY:Utility();
&str = "<div><b>value1</b><i>value2</i></div>";
&arr = &utility.split2D(&str, "div", CreateArray("b", "i"));
/* &arr[1][1]="value1", &arr[1][2]="value2" */
Syntax
stringToDate(DateString)
Description
Use this method to convert a date string in the "yyyy-MM-dd" format to a date.
Parameters
Field or Control |
Definition |
---|---|
DateString |
Specifies the string to be converted to a date. |
Returns
A date.
Syntax
stringToDatetime(DatetimeString)
Description
Use this method to convert a date string in the "yyyy-MM-dd HH:mm:ss" format to a DateTime value.
Parameters
Field or Control |
Definition |
---|---|
DatetimeString |
Specifies the string to be converted to a DateTime value. |
Returns
A DateTime value.
Syntax
validateSysVar(SysVar)
Description
Use this method to return the valid, correctly capitalized name of a system variable.
Parameters
Field or Control |
Definition |
---|---|
SysVar |
Specifies the system variable name to be validated as a string. |
Returns
A string containing the validated and correctly capitalized system variable name, INVALID SYSVAR if the system variable does not exist.
Example
In the following example, %AuthenticationToken is returned as the validated system variable name.
import PTFP_FEED:UTILITY:Utility;
Local PTFP_FEED:UTILITY:Utility &utility = create PTFP_FEED:UTILITY:Utility();
&str = &utility.validateSysVar("%AUTHENTICATIONtoken");
/* &str="%AUTHENTICATIONTOKEN" */
Syntax
viewStringAsAttachment(String, FileName, ViewAttachment)
Description
Use this method to transform the given string into an attachment file that is sent to the browser.
Parameters
Field or Control |
Definition |
---|---|
String |
Specifies the specifies the contents of the attachment file as a string. |
FileName |
Specifies the attachment file name as a string. |
ViewAttachment |
Specifies the as a Boolean value whether the attachment is to be viewed directly or detached for download. |
Returns
None.