/xScript

Xml script language, 100% Java project. It define basic logical xml tag, like <if>, <for>, <while>, <method> etc. I think xScript is for the guys who is not a programmer, but also has repeating work to do every day. You can ask someone, your co-worker, to develop some tags or function for you. It's easy to define your own xml tag or ExpL function.

Primary LanguageJavaGNU Lesser General Public License v3.0LGPL-3.0

xScript

xScript, xml script, it defines the basic logical xml tag, like <if>, <for>, <while>, <method> ect.

I think xScript can link one application with the other. For me, I often need to operate the Excel doc and Oracle, so I use it to read the data from Excel or Oracle or both of them, and finally output the result. Futhermore, it's easy to define your own xml tag or ExpL function.

Click the xScript.bat under xScript.all to start this program.


Example:

<?xml version="1.0"?>
<script> 
	<method name="main">  
		<call name="listArray" ref="{[1,2,3,5,7,11]}"/> 
	</method>  
	<method name="listArray" param="ref">
		<for ref="{ref}">
			<println value="{___ref___}"/>
		</for>
	</method>	
</script>

The output:

1
2
3
5
7
11


<script>

Every xScript doc should start with <script> tag.

Attribute

name -- the name of this script, this name will store to variable ___xScript___, you can use {___xScript___} to get the value of this attribute.
main-method -- xScript will find the method with this name to invoke. The default vaue is main, so if this tag do not have this attribute, the method with the name 'main' will be invoked.

Sub-elements

<set>, <method>, <include>

Variable

___xScript___ -- the name of script.
___home___ -- if you use xml file, the value is the path of the folder that the file place, otherwise, the value is use's directory.

Example

<?xml version="1.0"?>
<script name="example" main-method="main"> 
	<method name="main">  
		<println>Name: {___xScript___}</println>
		<println>Home: {___home___}</println>
	</method>  
</script>

xmlns attribute

You can use namespace attribute to specify your own xScript or ExpL extension dynamically.
xmlns:<namespace>="<xScript extension package>"
xmlns:f.<namespace>="<ExpL extension package>"
xmlns:func.<namespace>="<ExpL extension package>"
xmlns:function.<namespace>="<ExpL extension package>"

Example

<?xml version="1.0"?>
<script name="example" xmlns:yours="your.xscript.package" xmlns:f.yours="your.expl.package"> 
	<method name="main">  
		<yours:yourelement attribute="{#yours:yourfunction()}"/>
	</method>  
</script>

<set>

Initial a variable with specify value.

Attribute

var -- the name of variable.
value -- the value.
default -- the default value when attribute value is empty.

Sub-elements

<condition>

Modifier

<set> support two modifiers: public, final.

public -- means this variable is publics, it can be used anywhere. The <set> under <script> is publics automatically.
final -- means this variable can't be changed anymore.

Example

<set var="result" value="1">
	<condition cond="{result}==0" value="2"/>
	<condition cond="{result}==1" value="3"/>
	<condition cond="{result}==2" value="4"/>
</set>
<set var="public final my_var" value="1" />

<condition>

Sub-element of Set, the condition check for <set>.

Attribute

cond -- the condition.
value -- the value.


<method>

A method tag.

Attribute

name -- the name of method.
param -- the parameters.

Sub-elements

All except for <method>, <script>, <include>

Modifier

The attribute param suport 3 modifiers: final, required, default.

final -- means this parameter can't be changed anymore.
required -- means this parameter is required, when this method is called.
default -- means default value when this parameter is blank.

Example

<method name="method1" param="required var1, final required var2, final var3, default({'abc'}) var4">
	...
</method>

<call>

invoke the method.

Attribute

name -- the name of method.
var -- the variable store the value of method's return value.
other attribute, the parameter of method.

Example

<method name="method1" param="required var1, final required var2, final var3, default({'abc'}) var4">
	<return value="1" />
</method>
<method name="main">
	<call name="method1" var="returnValue" var1="1" var2="2" var4="a"/>
</method>

<return>

Return the value of method. This element will skip the elements after it.

Attribute

value -- the return value.


<if>

Condition element.

Attribute

cond -- the condition of <if>. If the result is true, use <then> else, use <else>.

Sub-elements

<then>, <else>

Example

<if cond="{a}==0">
	<then>
		<set var="b" value="1"/>
	</then>
	<else>
		<set var="b" value="2"/>
	</else>
</if>

<then>

Sub element of <if>.

Sub-elements

All except for <method>, <script>, <include>


<else>

Sub element of <if>.

Sub-elements

All except for <method>, <script>, <include>


<ifthen>

The simple style of <if>-<then>.

Attribute

cond -- the condition.

Sub-elements

All except for <method>, <script>, <include>

Example

<ifthen cond="{a}==0">
	<set var="a" value="1"/>
</ifthen>

<while>

Loops, just like while keyword in Java.

Attribute

cond -- the condition.
after -- if this attribute is true, it works like do...while.

Sub-elements

All except for <method>, <script>, <include>

Variable

___index___ -- the loops time.

Example

	<set var="i" value="0"/>
	<while cond="{i} &lt; 10">
		<set var="i" value="{{i} + 1}"/>
		<println>{___index___}</println>
	</while>

<for>

Loops.

Attribute

from, to -- use number to loop.
step -- each step.

ref, sub-ref -- use reference/array to loop.
skip -- skip previous ref. When you want to skip first reference, just let skip="1".

Sub-elements

All except for <method>, <script>, <include>

Variable

___index___ -- when use number to loop, the value is the current number; when use reference to loop, the value is the loop time.
___ref___ -- the default variable name of sub reference when sub-ref is blank.

Example

<!--use reference to loop-->
<set var="ref" value="{[1,2,3,5,7,11]}"/>
<for ref="{ref}">
	<println value="{___ref___}"/> <!--do not specify attribute sub-ref, so use ___ref___.-->
</for>

<!--use number to loop-->
<for from="0" to="10" step="2">
	<println value="{___index___}"/>
</for>
<for from="0" to="10">
	<println value="{___index___}"/>
</for>

<continue>

Just like keyword continue in Java, skip the current loop and start the next.


<break>

Just like keyword break in Java, jump out of the loops.


<accum>

Accumulator.

Attribute

var -- the name of variable.
step -- each step.

Example

<set var="a1" value="3"/>
<set var="a2" value="3"/>
<accum var="a1"/> <!--a1 == 4-->
<accum var="a2" step="2"/>  <!--a2 == 5-->
<accum var="public a3"/>  <!--if a3 do not define, a3 == 1, and a3 is a public variable-->

<clear>

Remove the variable.

Attribute

var -- the name of variable.


<include>

Include another xScript doc.

Attribute

file -- the path of file.
url -- the url.
load-methods -- load method in the doc.
methods -- list the methos need to load.
load-publics -- load variable under <script> in the doc.


<debug>

Show debug dialog, list all variables and allow you to test ExpL expression.

Attribute

cond -- the condition.


<print>, <println>

System standard output. <println> is with link break.

Attribute

value -- the value you want to output.
trim -- omit the leading and trailing whitespace.

Text

These two elements allow text, text is the context you want to output. Same as attribute value.

Example

<print value="{1+1}"/>
<println/>
<println>{1+1}</println>

<param>

Provide the parameter for parent element.

Attribute

name -- the name of this parameter.
value -- the value of this parameter.
default -- the default value of this parameter.
link -- link another parameter. When use link parameter, it means use another parameter's value.


<catch>

When EXCEPTION is return (process metod return EXCEPTION), the sub-elements of this element will be invoked. kenh.xscript.database.elements.Execute is the example of EXCEPTION.

Example

<!--the example use xScript.database-->
<d:execute var="result" ref="conn">
	<![CDATA[ INSERT INTO TABLE1 (str_col,num_col,bo_col,date_col) VALUES(NULL, NULL, NULL, NULL, NULL) ]]>
</d:execute>
<catch> 
	<d:rollback ref="conn"/> 
</catch> 

Variable

___exception___ - The exception.



The scope of variable

The variable define by <set> that under <script> is public variable.
The variable define by <set> use public modifier is public variable.
Public variable can visit everywhere in doc.

The variable define by <set> in the <method> is non-public variable. The variable will be remove when jump out of method.

When a method have parameter that the name same as public variable, in the method, parameter take effect.

<script>
	<set var="var1" value="1"/> <!--public variable, define under script-->
	<method name="main">
		<set var="public var2" value="2"/> <!--public variable, use public modifier-->
		<call name="method1" var1="{{var2}+1}"/>
	</method>
	<method name="method1" param="var1">
		<set var="var3" value="1"/>  <!--non-public variable-->
		<println value="{var1}"/> <!-- 3   display parameter var1 here-->
		<println value="{var2}"/> <!-- 2   display public variable var2 here-->
	</method>
</script>