Encoding Content for Use with EditLive! for Java

Introduction

When working with content that is to be placed in EditLive! for Java it must be ensured that the relevant content is URL encoded before it is used with EditLive! for Java.  Content is required to be URL encoded so that it can be used with the JavaScript used to instantiate EditLive! for Java.

It should be noted that when instantiating EditLive! for Java with the ASP, ASP .NET or J2EE SDKs the content placed in the Style, Document and Body properties is automatically URL encoded using the appropriate URL encoding method.  It is recommended that when URL encoding content that this operation be performed on the server side through the use of the appropriate server side scripting function.  It is possible to use the JavaScript escape function however this is not recommended as this function does not correctly URL encode all content and may break.

URL Encoding Functions

Most scripting languages provide a function to URL encode strings.  The following section defines URL encoding functions which can be used with several common server side scripting languages. 

ASP

The URL encoding function which can be using in ASP is Server.URLEncode.  This can be used in the following manner:

Server.URLEncode("this string will be url encoded")

ASP .NET (C#)

The URL encoding function which can be used in ASP .NET is HttpUtility.UrlEncode.  This class is part of the System.Web packageThe function can be used in the following manner, with the correct "using" statement:

using System.Web;
...
HttpUtility.UrlEncode("this string will be url encoded");

JSP (Java)

The URL encoding method which can be used in JSP and Java classes is the URLEncoder.encode() method.  The URLEncoder class can be found in the java.net package.  The function can be used in the following manner and the relevant import statements must be included:

import java.net.URLEncoder;
...
URLEncoder.encode("this string will be url encoded");

PHP

When using the PHP URL encoding functions it is important to use the rawurlencode function as opposed to the urlencode function.  The function can be used in the following manner:

rawurlencode('this string will be url encoded');

Note:  It is important to note that the urlencode function provides different functionality to the rawurlencode function.  The urlencode function encodes spaces as "+" symbols which may cause errors with EditLive! for Java.

ColdFusion

When implementing an EditLive! for Java integration with ColdFusion the URL encoding function which should be used is URLEncodedFormat.  This function can be used in the following way:

urlencodedformat("this string will be url encoded");

Perl

Perl does not include a URL Encode function as part of the standard libraries and therefore developers must write their own.  This can be achieved through the use of regular expressions.  The following code gives an example on how this may be achieved:

#!/usr/bin/perl
$encodeString = "this string will be url encoded";
$encodeString = ~s/([^A-Za-z0-9_\-.]/uc sprintf("%%%02x",ord($1))/eg;

Summary

Content which is to be added to EditLive! for Java should be URL encoded.  The methods listed above can be used to URL encode content with several popular scripting languages.  The JavaScript escape function can also be used, however, this is not recommended as the encoding provided by this function does not comply with URL encoding.