JavaScript API Class: Util
The Util class is available via the the "util" implicit object. It provides some miscelaneous functions that EditMe layout developers may need.
Properties
| Name | Type | Access |
Description |
| className | String | read | Returns "Util" to help identify this object as a Util class instance. |
| debugMessages |
String |
read |
Returns all the messages in the debug log wrapped in a <pre> tag. See Server Side JavaScript Debugging for usage details. |
| debugMode |
Boolean |
read/write |
Sets debug mode on or off. See Server Side JavaScript Debugging for usage details. |
Functions
| Name | Return Type |
Description |
| applyTimeZone (Date, String) |
Date | Returns a date representing the given date adjusted for the time zone specified by the String argument. Use user.timeZone to get the user's selected time zone. Note that date properties in the API such as page.date, comment.date and attachment.date already have the user's time zone applied. This method can be used to apply the time zone to other date values. |
| contains(String1, String2) contains(Array, Object) |
Boolean | If two strings are provided, returns true if String2 is found to be a substring within String1. If an Array is provided as the first argument, returns true if the second object is found as an item within the array. |
| convertHtmlEntities (String) | String | Converts HTML entities to XML entities. This is useful for parsing HTML from EditMe's editor into XML, as most HTML entities are not considered valid XML. For example, is replaced with  . |
| debug (String) | None |
Appends a message to the debug log. See Server Side JavaScript Debugging for usage details. |
| decodeCharacterEntities (String) |
String |
Converts numbered HTML/XML character entities such as   (space) to the corresponding character. This is useful for converting HTML/XML encoded content to text. |
| endsWith(String1, String2) | Boolean | Returns true if String1 ends with the value of String2. |
| expandCamelCase (String) | String | Adds spaces to a camel case string. For example, given "SomePageName", it will return "Some Page Name" |
| parseXML (String) |
DOM4J Document | Parses a string of valid XML and returns a DOM4J Document object. If the string to be parsed is not valid XML, this function returns null. A simple way to diagnose what about a piece of content is invalid, simply save it as a .xml file on your local hard drive and open it up in Firefox or Internet Explorer. This will give you a detailed error message. |
| formatDate (Date, String) |
String |
Formats the given date value using the String formatting command. See Date Formatting Codes. Example: formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'); |
| formatFileSize (Number) |
String |
Formats a number into a descriptive length. For example:
|
| htmlEncode (String) |
String |
Encodes a string for display in an HTML page. Specifically, it replaces:
|
| htmlDecode(String) | String | Performs the reverse of htmlEncode(String). |
| httpGet(String1, String2, [Number]) |
String |
Deprecated - see the newHttpClient() method Makes an HTTP GET connection to a web site and returns the result as a String. The String1 argument should be the host name, as in "www.editme.com" and String2 should be the URI, as in "/Home". The optional Number argument specifies a port number, which defaults to 80. If the host name specified matches the site's Default Domain setting, EditMe will authenticate the request as the current user. Example: var html = httpGet("www.editme.com", "/Home"); |
| httpsGet(String1, String2, [Number]) |
String |
Deprecated - see the newHttpClient() method Exactly like httpGet(..) above except that an SSL (https) connection is used and the port defaults to 443. |
| httpPost(String1, String2, Array, [Number]) |
String |
Deprecated - see the newHttpClient() method Makes an HTTP POST connection to a web site and returns the result as a String. The String1 argument should be the host name, as in "www.editme.com" and String2 should be the URI, as in "/Home". The Array argument should contain a set of name/value pairs. The optional Number argument specifies a port number, which defaults to 80. If the host name specified matches the site's Default Domain setting, EditMe will authenticate the request as the current user. Example: |
| httpsPost(String1, String2, Array, [Number]) |
String |
Deprecated - see the newHttpClient() method Exactly like httpPost(..) above except that an SSL (https) connection is used and the port defaults to 443. |
| md5(String1, String2) | String | Returns an MD5 hash of the the value in String2 using String1 as a key. |
| newHttpClient() | HttpClient | Returns a new instance of the HttpClient API class. See JavaScript API Class: HttpClient for details. |
| parseCSV (String) | Array of String[] |
Accepts a string of CSV data and returns an array of string arrays. Each element in the returned array is a row in the CSV file, represented as an array of Strings where each element is a field in the row. The CSV format accepted can be quoted or unquoted. |
| parseDate (String1, String2) | Date |
Parses the date in String1 using the format defined in String2. This function relies on the SimpleDateFormat class provided with Java. See that API documentation for formatting command details. Example: parseDate('12/15/2009', 'MM/dd/yyyy'); |
| startsWith(String1, String2) | Boolean | Returns true if String1 starts with String2. |
| toCSV (Array) | String | Accepts a two-dimensional array of Strings, as is returned by the parseCSV() method, and returns a String of CSV data. |
| trim(String) | String | Removes white space characters from the beginning and end of the String argument and returns the result. |
| urlDecode (String) |
String |
URL encodes a given string. For example, given "Hello%20World" it will return "Hello World". |
| urlEncode (String) |
String |
URL decodes a given string. For example, given "Hello World" it will return "Hello%20World". |
Example
// turns a date into MM/DD/YYYY format
function simpleDate(d) {
return util.formatDate(d, 'MM/dd/yyyy');
}
Return to JavaScript API
