throw new ScriptFrameworkErrorException(
nsc.getMessage(), null,
metaData.getLanguageName(), metaData.getLanguage(),
ScriptFrameworkErrorType.UNKNOWN );
}
Context ctxt = null;
try
{
String editorURL = sourceUrl.toString();
Object result = null;
String source = null;
ScriptEditorForJavaScript editor =
ScriptEditorForJavaScript.getEditor(
metaData.getSourceURL() );
if (editor != null)
{
editorURL = editor.getURL();
result = editor.execute();
if ( result != null &&
result.getClass().getName().equals( "org.mozilla.javascript.Undefined" ) )
{
// Always return a string
// TODO revisit
return Context.toString( result );
}
}
if (editor != null && editor.isModified() == true)
{
LogUtils.DEBUG("GOT A MODIFIED SOURCE");
source = editor.getText();
}
else
{
metaData.loadSource();
source = metaData.getSource();
}
if ( source == null || source.length() == 0 ) {
throw new ScriptFrameworkErrorException(
"Failed to read source data for script", null,
metaData.getLanguageName(), metaData.getLanguage(),
ScriptFrameworkErrorType.UNKNOWN );
}
/* Set the context ClassLoader on the current thread to
be our custom ClassLoader. This is the suggested method
for setting up a ClassLoader to be used by the Rhino
interpreter
*/
if (cl != null) {
Thread.currentThread().setContextClassLoader(cl);
}
// Initialize a Rhino Context object
ctxt = Context.enter();
/* The ImporterTopLevel ensures that importClass and
importPackage statements work in Javascript scripts
Make the XScriptContext available as a global variable
to the script
*/
ImporterTopLevel scope = new ImporterTopLevel(ctxt);
Scriptable jsCtxt = Context.toObject(
ScriptContext.createContext(
m_xModel, m_xInvocContext, m_xContext,
m_xMultiComponentFactory), scope);
scope.put("XSCRIPTCONTEXT", scope, jsCtxt);
Scriptable jsArgs = Context.toObject(params, scope);
scope.put("ARGUMENTS", scope, jsArgs);
result = ctxt.evaluateString(scope,
source, "<stdin>", 1, null);
result = ctxt.toString(result);
return result;
}
catch (JavaScriptException jse) {
LogUtils.DEBUG( "Caught JavaScriptException exception for JavaScript type = " + jse.getClass() );
String message = jse.getMessage();