From ba1d538b588dc57066213a94803584ea9016e1e7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 27 Feb 2013 22:25:58 +0100 Subject: Script testing and resulting fixes --- src/main/java/com/c2kernel/scripting/Script.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/c2kernel/scripting/Script.java b/src/main/java/com/c2kernel/scripting/Script.java index ab3c0e6..7e0c3f2 100644 --- a/src/main/java/com/c2kernel/scripting/Script.java +++ b/src/main/java/com/c2kernel/scripting/Script.java @@ -51,6 +51,14 @@ public class Script ScriptEngine engine; ScriptContext context; + /** For testing. Parses a given script xml, instead of loading it from Items. + * @param xml + * @throws ScriptParsingException + * @throws ParameterException + */ + public Script(String xml) throws ScriptParsingException, ParameterException { + parseScriptXML(xml); + } /** * Loads script xml and parses it for script source, parameters and output specifications. * First tries to load the script from resource path /scriptFiles/scriptName_scriptVersion.xml @@ -157,7 +165,7 @@ public class Script engine.setContext(context); } - public void loadScript(String scriptName, String scriptVersion) throws ScriptingEngineException + private void loadScript(String scriptName, String scriptVersion) throws ScriptingEngineException { try { @@ -420,7 +428,8 @@ public class Script throw new ScriptingEngineException("Execution aborted, the following declared parameters were not set: \n" + missingParams.toString()); for (Parameter outputParam : mOutputParams.values()) { - if (outputParam.getName() == null) continue; // If the name is null then it's the return type. don't pre-register it + System.out.println("Output param: "+outputParam.getName()); + if (outputParam.getName() == null || outputParam.getName().length()==0) continue; // If the name is null then it's the return type. don't pre-register it Logger.msg(8, "Script.setOutput() - Initialising output bean '" + outputParam.getName() + "'"); Object emptyObject; try { @@ -468,7 +477,7 @@ public class Script for (Parameter outputParam : mOutputParams.values()) { String outputName = outputParam.getName(); Object outputValue; - if (outputName == null) + if (outputName == null || outputName.length()==0) outputValue = returnValue; else outputValue = context.getBindings(ScriptContext.ENGINE_SCOPE).get(outputParam.getName()); -- cgit v1.2.3