JavaScript API

Search:

Welcome

Login to contribute. Register if you haven't yet.

Need Support?

Search this site to find an answer. If you still need help, post a Question. Private or account-related support inquiries can be made at the Private Support forum.

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 
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.
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, &nbsp; is replaced with &#160.
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 &#160; (space) to the corresponding character. This is useful for converting HTML/XML encoded content to text.
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. This function relies on the SimpleDateFormat class provided with Java. See that API documentation for formatting command details. Example: formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
formatFileSize (Number)
String

Formats a number into a descriptive length. For example:

  • 123 will return "123 bytes"
  • 321123 will return "321 KB"
  • 3123421 will return "3.12 MB"
htmlEncode (String)
String

Encodes a string for display in an HTML page. Specifically, it replaces:

  • & with &amp;
  • < with &lt;
  • > with &gt;
httpGet(String1, String2, [Number])
String

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
Exactly like httpGet(..) above except that an SSL (https) connection is used and the port defaults to 443.
httpPost(String1, String2, Array, [Number])
String
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:
var args = [['name1','value1'], ['name2','value2']];
var html = httpPost("www.editme.com", args, "/Home");

httpsPost(String1, String2, Array, [Number])
String
Exactly like httpPost(..) above except that an SSL (https) connection is used and the port defaults to 443.
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');
toCSV (Array) String  Accepts a two-dimensional array of Strings, as is returned by the parseCSV() method, and returns a String of CSV data.
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 Java Script API