Overview
Jessop is a polyglot templating language in the style of Java Server Pages (JSPs).
Like all templating languages, output can be any text stream ( e.g. English text, HTML/CSS or other text-based programming or markup languages), but the statements, conditions and expressions within the language can be written in any language that the Java scripting engine ( javax.script ) supports.
e.g. by enabling the 'javascript' target language, you can embed javascript code within your jessop script (which executes using the 'rhino' engine), or by enabling the 'python' target language, you can embed python code within your jessop script (which executes using the 'jython' engine).
The jessop syntax should be familiar to anyone who has written JSPs. A file may contain
- a declaration in the form
<%@ jessop language="javascript" engine="rhino" %>
- expressions to generate output in the form
<%= name %>
- scriptlets to execute arbitrary code in the form
<% if (name==null) { %>
No name
<% } %>
See the Javadoc overview for a more complete description of the jessop syntax.
Example input/output
Javascript
<%@ jessop language="javascript" engine="rhino" %> Hello, <%= name %> <% for (var i = 1; i < maxCount; i++) { %> <%= i %> <% } %>
Output
Hello, Count von Count 1 2 3
Java
<%@ jessop language="java" engine="beanshell" %> Hello, <%= name %> <% for (int i=1; i < maxCount; i++) { %> <%= i %> <% } %>
Output
Hello, Count von Count 1 2 3
Ruby
<%@ jessop language="ruby" engine="jruby" %> Hello, <%= $name %> <% (1..$maxCount).each do |i| %> <%= i %> <% end %>
Output
Hello, Count von Count 1 2 3
Python
<%@ jessop language="python2" engine="jython" %> Hello, <%= name %> <% for i in range(1, maxCount): %> <%= i %> <% pass; %>
Output
Hello, Count von Count 1 2 3
Lua
<%@ jessop language="lua" engine="luaj" %> Hello, <%= name %> <% for i = 1, maxCount - 1 do %> <%= i %> <% end %>
Output
Hello, Count von Count 1 2 3
Lisp
<%@ jessop language="lisp" engine="ABCL" %> Hello, <%= name %> <% (loop for i from 1 to maxCount do %> <%= i %> <% ) %>
Output
Hello, Count von Count 1 2 3
See the Javadoc overview for more example programs.
The unit tests accompanying this project include further examples.
Example Java code
The following Java code will read an input file and evaluate it using the 'jessop' ScriptEngine.
See the Javadoc overview for more example programs.
package com.example.contrived.jessop; import java.io.File; import java.io.FileNotFoundException; import javax.script.ScriptEngineManager; import javax.script.ScriptEngine; import javax.script.ScriptException; import java.util.Scanner; public class JessopExample { public void main(String args[]) throws FileNotFoundException, ScriptException { // read the input file String filename = args[1]; String input = new Scanner(new File(filename)).useDelimiter("\\Z").next(); // initialise the jessop ScriptEngine ScriptEngine engine = new ScriptEngineManager().getEngineByName("jessop"); if (engine==null) { throw new IllegalStateException("Missing engine 'jessop'"); } // set some variables which are used in the jessop script Bindings b = engine.createBindings(); b.put("name", "Count von Count"); b.put("maxCount", 4); // evaluate the script engine.eval(input); } }
Usage
To use this Maven project, include it in your project model
<project> ... <dependencies> ... <dependency> <groupId>com.randomnoun.common</groupId> <artifactId>jessop</artifactId> <version>1.0.15</version> </dependency> ... </dependencies> ... </project>
Download
If you're not using maven, you can download the binary and source JARs using these links:
To compile or run, add this JAR to your CLASSPATH. | |
To debug in an IDE, set this JAR as the Java Source attachment for jessop-1.0.15.jar | |
To build jessop from source, unpackage this archive and run mvn compile |
Target languages
Jessop has support for six target languages (using eight script engines).
You will need to add the appropriate maven dependency to target these languages and engines.
Language | Engine | Engine groupId | Engine artifactId | Artifact version |
---|---|---|---|---|
javascript | rhino / nashorn | (Bundled with JVM) | ||
javascript | graalvm | org.graalvm.js | js | 20.3.0 |
java | beanshell | org.beanshell | bsh | 2.0b5 |
python | jython | org.python | jython | 2.5.3 |
ruby | jruby | org.jruby | jruby-complete | 9.1.2.0 |
lua | luaj | org.luaj | luaj-jse | 3.0.1 |
lisp | abcl | org.abcl | abcl | 1.4.0 |
Additional languages and engines can be added by implementing the JessopScriptBuilder interface, registered using the standared Java ServiceLoader mechanism.
Syntax
See the Javadoc overview for a description of the jessop syntax.