HowTo: URLEncode a field in Pentaho Data Integration (Kettle)

I've been working with PDI (aka. Kettle) for some time and came across the need to URLEncode a link.


Here's how I did:


java
var url = new org.apache.commons.httpclient.URI(link).toString();
if(new org.apache.commons.httpclient.URI(link).getScheme() == null) {
url = 'http://'+url;
}

Just put this code in a JavaScript-Step - it will convert the link-field to an url-field which has been URL-Encoded. If you're missing the schema in your link it will be set to "http". It uses some Java-Code for that.

This article was updated on 21 Januar 2011