execute script(a) with optional parameters b-j

Important note: Please note that Lobster cannot provide support for self-developed classes.



This function allows you to execute Java code as a script. In parameter a, you can either put in the name of a file which contains Java code or you can put in the java code directly. Parameters b-j are optional and can be used within the script code. Furthermore, you can use all variables, lists and maps of your profile. To get access to a list or a map you have to use the following methods:


  1. script.getMap("map_name") returns a map object of type java.util.Map.

  2. script.getList("list_name") returns a list object of type java.util.List.


With the execute script function you can also handle DOM objects (org.jdom.Document) which are created in the call webservice() function. To access a DOM object use this method:


  1. script.getDocument("document_name") returns an org.jdom.Document object.


The DOM object can also be deleted with method script.deleteDocument("document_name") or by using function delete DOM object().

Parameters


Parameter

Description

a

Script or filename.

b

(optional) Script parameter b.

c

(optional) Script parameter c.

d

(optional) Script parameter d.

e

(optional) Script parameter e.

f

(optional) Script parameter f.

g

(optional) Script parameter g.

h

(optional) Script parameter h.

i

(optional) Script parameter i.

j

(optional) Script parameter j.


Examples


Parameter a

Parameter b

Parameter c

Parameter d

..

Parameter j

Result

b+c

Demo

Script




DemoScript

return VAR_FILENAME;






demo.txt

./conf/MyScript.txt

30





yyyy-MM-dd

if(b.equals("demo")) return script.getMap(c).get("demo"); else return VAR_FILENAME;

test

map_demo




demo.txt

./conf/webservice/DOM_script.java

myDOM





Object as string.

MyScript.txt
int intValue = Integer.parseInt(b);
switch(intValue) {
case 10:
return "yyyyMMdd";
case 20:
return "dd.MM.yyyy";
case 30:
return "yyyy-MM-dd";
default:
return "yyyyMMdd";
}

DOM_script.java
//Imports
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
//Method to print JDOM element
private void printElement(List children, StringBuffer res, String tab){
for (int i = 0; i < children.size(); i++) {
Element child = (Element)children.get(i);
res.append(child.getName() +": "+ child.getText() + "\n");
printElement(child.getChildren(),res, tab+"\t");
}
}
//Get JDOM document for DOM name given in parameter b
Document dom = script.getDocument(b);
if(dom == null){
return "DOM Object does not exsist";
}
Element root = dom.getRootElement();
List children = root.getChildren();
StringBuffer res = new StringBuffer();
//Call method from above
printElement(children, res, "");
//Returns string as function result
return res.toString();

printXML_script.java
//Imports
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
//Get JDOM document for DOM name given in parameter b
Document dom = script.getDocument(b);
if(dom == null){
return "DOM Object does not exsist";
}
//Return JDOM document as XML string
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
return outputter.outputString(dom);