Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: How do I create a new script engine

...

The same logic applies to other extensions (html, txt, ...) handled by the DefaultGetServlet.

How do I create a new script engine?

As I write this, we don't have documentation on how to create more script engines, but that's not too hard to do if you take one of the simple existing engines as an example.

The JRuby engine for example, implemented in the scripting/ruby module, is built out of two simple classes, one that inherits from AbstractSlingScriptEngine, and one that inherits from AbstractScriptEngineFactory. The code is very simple, it's basically only a wrapper around the JRuby engine, that adapts it for Sling.

If creating a script engine, don't forget the META-INF/services/javax.script.ScriptEngineFactory file, which lets scripting subsystem know about the factory class, so that the engine is activated when the bundle that contains it is loaded.

Once the script engine is created, loading its bundle into Sling should be enough to activate scripts having the extension defined by the engine. If several scripts are found with the same name but different script extensions, the priority in selecting them is currently unspecified.

The javascript and freemarker engines source code also shows how to add automated tests to a script engine, including making a JCR repository available to the tests.

Working with bundles

Is there an easy way to update bundles in a running installation during development?

...