Defines an external java function (compiled) which can be used as a xsql-script tag as any other function already implemented in the library.

1 system.function.defineExternal

<system.function.defineExternal
    dir='dir'
    name='name'
/>

Remarks

The java class has the following struct:

Copy
// webStudio script
import deister.webstudio.core.xsql.script.XSQLScriptRunner;
import deister.webstudio.core.xsql.script.XSQLScriptFunction;
import deister.webstudio.core.xsql.script.XSQLScriptException;

// dom
import org.w3c.dom.Element;

/**
* Complie with:
*
* javac sample.java -cp ..\..\common\lib\webStudioCore.jar
*
* Register and use from xsql-script
*/
public final class sample extends XSQLScriptFunction
{
	protected final static String[] ATTRIBUTES	= new String[] { [List of attributes separated by comma] };
	protected final boolean  isTerminal()		{ return true;	}
	protected final String[] getAttributes()	{ return ATTRIBUTES;	}

	protected final Object process(XSQLScriptRunner program, Element el, int deep)
		throws XSQLScriptException
	{
		// Body of the function
		//
		// ...

		return [Object];
	}
}

An example of function which given an argument returns its content passed to uppercases:

Copy
// webStudio script
import deister.webstudio.core.xsql.script.XSQLScriptRunner;
import deister.webstudio.core.xsql.script.XSQLScriptFunction;
import deister.webstudio.core.xsql.script.XSQLScriptException;

// dom
import org.w3c.dom.Element;

/**
* 
*
* Complie with:
*
* javac sample.java -cp ..\..\common\lib\webStudioCore.jar
*
* Register and usine from script
*/
public final class sample extends XSQLScriptFunction
{
	protected final static String[] ATTRIBUTES	= new String[] { "name" };
	protected final boolean  isTerminal()		{ return false;	}
	protected final String[] getAttributes()	{ return ATTRIBUTES;	}

	protected final Object process(XSQLScriptRunner program, Element el, int deep)
		throws XSQLScriptException
	{
		Object data    = program.__get1EvaluatedArguments(el, deep);
		if (data == null)
			return null;
		String text = program.__object2String(el, data);
		return text.toUpperCase();
	}
}

To compile the class, you should dispose of the package webStudioCore.jar located in $JAS_HOME/common/lib

Copy
javac sample.java -cp /home/jas/common/lib/webStudioCore.jar

Once the class is compiled can be used from xsql-script as shows the following example.

Example

Use of a compiled java class to be used from xsql-script.

Copy
<xsql-script name='getAttributes_example'>
    <body>

		<!-- load a java class and register it as my.sample -->
		<system.function.loadExternalFunction dir='conf\functions' name='sample' />
		<!-- this class simply retuns the upper case -->
		<println>
			<sample>
				this text is uppercase
			</sample>
		</println>
    </body>
</xsql-script>