Wrapping Java libraries

4 views
Skip to first unread message

pgio

unread,
Mar 25, 2011, 6:19:53 PM3/25/11
to Helma
I'd really love to know how to do this correctly for Helma. I'm trying
to use a jar but I'm instantiating it wrong, I guess. I get the Type
Error every time

TypeError: [JavaPackage java.com.mindprod.base64.Base64u.Base64u] is
not a function, it is object.

No matter where I terminate the name. I find the documentation rather
lacking on this subject.

The function is something like:


String.prototype.debase64u = function() {
var helper = Packages.java.com.mindprod.base64;
var chunk = new helper.Base64u();
var final = chunk.decode(this)
return String(new java.lang.String(final));
};

though I have tried many variations. Hopefully the answer is glaringly
obvious to someone. And yes, the jar is in /ext, and helma recognizes
it on startup.

Thanks,
Pete

pgio

unread,
Mar 25, 2011, 6:48:40 PM3/25/11
to Helma
So this works:

String.prototype.debase64u = function() {
var helper = new Packages.com.mindprod.base64.Base64u();
var padlength = this.length%4;
var padded = this.valueOf();
if (padlength>0){
for (var i = 0; i<(4-padlength); i++){
padded += "*"
}
}
var chunk = helper.decode(padded);
return String(new java.lang.String(chunk));
};
Reply all
Reply to author
Forward
0 new messages