Coder Social home page Coder Social logo

basexjsr223's Introduction

BaseXJSR223

A JSR223 wrapper for BaseX XQuery 3.1 engine.

BaseX is our favorite platform for developing services and data oriented applications. Its comprehensive XQuery 3.1 engine turns out to be a real Swiss Army knife in several scenarios.

In order to exploit BaseX for scripting other complex software such as BPM engines, we've created basexjsr223 which is a JSR223 compliant wrapper of BaseX XQuery engine.

In order to use BaseXJSR223, you'll have to add to your classpath the BaseXJSR223.jar (download from releases) together with BaseX.jar which you can extract from the BaseX distributable available at BaseX Download.

At this point you could just write and run code like the following example class:

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import com.nubisware.jsr223.basex.BaseXScriptEngine;

public class StandaloneTest {

	public static void main(String[] args) {
		ScriptEngineManager manager = new ScriptEngineManager();
		ScriptEngine engine = (ScriptEngine) manager.getEngineByName("BaseX");
		try {
			//create bindings and set XQuery context to 1
			Bindings b = ((BaseXScriptEngine)engine).createBindings(1);
			b.put("offset", 1);
			System.out.println(engine.eval("declare variable $offset external; . + $offset", b));
		} catch (ScriptException e) {
			e.printStackTrace();
		}
	}

}

There are several names for whom the EngineManager will return BaseXJS223 engine instances ("BaseX", "basex","xquery", "Xquery", "XQuery", "xquery3","xquery3.1").

It is also possible to get the engine by file extensions ("xq", "xqm", "xquery", "xml") and MIME type ("application/xquery").

Besides passing the XQuery context at the time of instantiation of the Bindings, it is also possible to pass it through a special key:

bindings.put(BaseXScriptEngine.CONTEXT_KEY,context);

Please check the class AllTests.java for some useful examples on how to use the engine.

Note for developers: in order to build BaseXJSR223 you need gradle and executing gradle build from inside the repository's root folder will generate the library and execute the tests.

basexjsr223's People

Contributors

dcore94 avatar themaxx76 avatar

Stargazers

He Jiang avatar Andreas M. avatar  avatar  avatar  avatar

Watchers

 avatar Seeni avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.