Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the "jimport" function from "etherpad" work?

In etherpad's source I've seen code like:

jimport(java.util.Date, "JDate");

But it doesn't seem like some kind of javascript standard.

How is it done?

like image 596
ave4496 Avatar asked Mar 22 '26 11:03

ave4496


1 Answers

Looks like you're looking at the etherpad source. There they defined a helper function named jimport.

As mentioned, etherpad uses Rhino as its Javascript engine, which have Java available at his fingertips. So it is enough to make

file = java.io.File

in order to "import" it.

This function uses the helper function _jimportSinglePackage, to inject the Java package into the local Javascript scope.

This function receives the package name, and the global scope to which it'll inject the package to, and given a.b.c its essentially calling globalscope[c] = a.b.c, in order to import this Java package.

like image 146
Chi-Lan Avatar answered Mar 25 '26 00:03

Chi-Lan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!