Refine search
Scriptable jsR = Context.toObject( sItem.getText(), jsscope ); jsscope.put( folder.getItem( i ).getText(), jsscope, jsR ); jsscope.put( "_TransformationName_", jsscope, this.stepname ); jsscope.put( "_step_", jsscope, jsvalue ); jsscope.put( "SKIP_TRANSFORMATION", jsscope, Integer.valueOf( SKIP_TRANSFORMATION ) ); jsscope.put( "ABORT_TRANSFORMATION", jsscope, Integer.valueOf( ABORT_TRANSFORMATION ) ); jsscope.put( "ERROR_TRANSFORMATION", jsscope, Integer.valueOf( ERROR_TRANSFORMATION ) ); jsscope.put( "CONTINUE_TRANSFORMATION", jsscope, Integer.valueOf( CONTINUE_TRANSFORMATION ) ); } catch ( Exception ex ) { testException = jsscope.put( "rowMeta", jsscope, jsRowMeta ); for ( int i = 0; i < rowMeta.size(); i++ ) { ValueMetaInterface valueMeta = rowMeta.getValueMeta( i ); jsscope.put( valueMeta.getName(), jsscope, jsarg ); jsscope.put( valueMeta.getName(), jsscope, jsarg ); jsscope.put( "Value", jsscope, jsval ); jsscope.put( "row", jsscope, jsV2Row ); jsscope.put( "row", jsscope, jsRow ); int type = ValueMetaInterface.TYPE_STRING;
public TemplateCollectionModel values() throws TemplateModelException { Object[] ids = scriptable.getIds(); Object[] values = new Object[ids.length]; for (int i = 0; i < values.length; i++) { Object id = ids[i]; if (id instanceof Number) { values[i] = ScriptableObject.getProperty(scriptable, ((Number) id).intValue()); } else { values[i] = ScriptableObject.getProperty(scriptable, String.valueOf(id)); } } return (TemplateCollectionModel) wrapper.wrap(values); }
scope = cx.initStandardObjects( null ); Long nr = new Long( result.getEntryNr() ); scope.put( "errors", scope, errors ); scope.put( "lines_input", scope, lines_input ); scope.put( "lines_output", scope, lines_output ); scope.put( "lines_updated", scope, lines_updated ); scope.put( "lines_rejected", scope, lines_rejected ); scope.put( "lines_read", scope, lines_read ); scope.put( "lines_written", scope, lines_written ); scope.put( "files_retrieved", scope, files_retrieved ); scope.put( "exit_status", scope, exit_status ); scope.put( "nr", scope, nr ); scope.put( "is_windows", scope, Boolean.valueOf( Const.isWindows() ) ); scope.put( "_entry_", scope, this ); scope.put( "rows", scope, array ); scope.put( "parent_job", scope, parentJob ); scope.put( "previous_result", scope, prev_result ); Object res = cx.evaluateString( scope, this.script, "<cmd>", 1, null ); boolean retval = Context.toBoolean( res );
public static Object evaluate(Map<String, Object> globals, String script) throws IOException { init(); try { Context jsContext = ContextFactory.getGlobal().enterContext(); jsContext.setClassShutter(new SecurityClassShutter()); jsContext.setWrapFactory(new PrimitiveWrapFactory()); Scriptable instanceScope = jsContext.newObject(jsScope); instanceScope.setPrototype(jsScope); instanceScope.setParentScope(null); if (globals != null) { for (Map.Entry<String, Object> entry : globals.entrySet()) { Object wrappedObject = Context.javaToJS(entry.getValue(), instanceScope); ScriptableObject.putProperty(instanceScope, entry.getKey(), wrappedObject); } } Object o = jsContext.evaluateString(instanceScope, script, "evaluate", 1, null); return o; } finally { Context.exit(); } }
private Scriptable getScope(Scriptable rootScope) { Scriptable scope; Context ctx = Context.enter(); try { scope = ctx.newObject(rootScope); scope.setPrototype(rootScope); scope.setParentScope(null); } catch (Exception e) { throw new RuntimeException("Exception", e); } finally { Context.exit(); } return scope; }
public static Object setName(Scriptable bound, Object value, Context cx, Scriptable scope, String id) { if (bound != null) { // TODO: we used to special-case XMLObject here, but putProperty // seems to work for E4X and it's better to optimize the common case ScriptableObject.putProperty(bound, id, value); } else { // "newname = 7;", where 'newname' has not yet // been defined, creates a new property in the // top scope unless strict mode is specified. if (cx.hasFeature(Context.FEATURE_STRICT_MODE) || cx.hasFeature(Context.FEATURE_STRICT_VARS)) { Context.reportWarning( ScriptRuntime.getMessage1("msg.assn.create.strict", id)); } // Find the top scope by walking up the scope chain. bound = ScriptableObject.getTopLevelScope(scope); if (cx.useDynamicScope) { bound = checkDynamicScope(cx.topCallScope, bound); } bound.put(id, bound, value); } return value; }
public static String getVariable( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { String sRC = ""; String sArg1 = ""; String sArg2 = ""; if ( ArgList.length == 2 ) { try { Object scmo = actualObject.get( "_step_", actualObject ); Object scmO = Context.jsToJava( scmo, StepInterface.class ); if ( scmO instanceof StepInterface ) { StepInterface scm = (StepInterface) Context.jsToJava( scmO, StepInterface.class ); sArg1 = Context.toString( ArgList[0] ); sArg2 = Context.toString( ArgList[1] ); return scm.getVariable( sArg1, sArg2 ); } else { // running via the Test button in a dialog sArg2 = Context.toString( ArgList[1] ); return sArg2; } } catch ( Exception e ) { sRC = ""; } } else { throw Context.reportRuntimeError( "The function call getVariable requires 2 arguments." ); } return sRC; }
public Object getObject() { Scriptable newPackages; Context.enter(); try { final String JAVA_PACKAGE = "JavaPackage"; ClassLoader cl = Thread.currentThread().getContextClassLoader(); // FIXME - NativeJavaPackage is an internal class which we should not use newPackages = new NativeJavaPackage( "", cl ); newPackages.setParentScope( getScope() ); newPackages.setPrototype( ScriptableObject.getClassPrototype( getScope(), JAVA_PACKAGE ) ); //objectModel.put( "Packages", newPackages ); //objectModel.put( "java", ScriptableObject.getProperty( getScope(), "java" ) ); } finally { Context.exit(); } return newPackages; }
public static Object setDefaultNamespace(Object namespace, Context cx) { Scriptable scope = cx.currentActivationCall; if (scope == null) { scope = getTopCallScope(cx); } XMLLib xmlLib = currentXMLLib(cx); Object ns = xmlLib.toDefaultXmlNamespace(cx, namespace); // XXX : this should be in separated namesapce from Scriptable.get/put if (!scope.has(DEFAULT_NS_TAG, scope)) { // XXX: this is racy of cause ScriptableObject.defineProperty(scope, DEFAULT_NS_TAG, ns, ScriptableObject.PERMANENT | ScriptableObject.DONTENUM); } else { scope.put(DEFAULT_NS_TAG, scope, ns); } return Undefined.instance; }
public static void LoadScriptFromTab( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { try { for ( int i = 0; i < ArgList.length; i++ ) { // don't worry about "undefined" arguments String strToLoad = Context.toString( ArgList[i] ); String strScript = actualObject.get( strToLoad, actualObject ).toString(); actualContext.evaluateString( actualObject, strScript, "_" + strToLoad + "_", 0, null ); } } catch ( Exception e ) { // System.out.println(e.toString()); } }
public String[] getPropertyNames(Object obj) { Context.enter(); try { Object[] ids; if (obj instanceof ScriptableObject) { ids = ((ScriptableObject)obj).getAllIds(); } else { ids = ((Scriptable)obj).getIds(); } String[] result = new String[ids.length]; for (int i = 0; i < result.length; i++) { result[i] = (String)ids[i]; } return result; } finally { Context.exit(); } }
private Scriptable executeModuleScript(Context cx, String id, Scriptable exports, ModuleScript moduleScript, boolean isMain) { final ScriptableObject moduleObject = (ScriptableObject)cx.newObject( nativeScope); URI uri = moduleScript.getUri(); URI base = moduleScript.getBase(); defineReadOnlyProperty(moduleObject, "id", id); if(!sandboxed) { defineReadOnlyProperty(moduleObject, "uri", uri.toString()); } final Scriptable executionScope = new ModuleScope(nativeScope, uri, base); // Set this so it can access the global JS environment objects. // This means we're currently using the "MGN" approach (ModuleScript // with Global Natives) as specified here: // <http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension> executionScope.put("exports", executionScope, exports); executionScope.put("module", executionScope, moduleObject); moduleObject.put("exports", moduleObject, exports); install(executionScope); if(isMain) { defineReadOnlyProperty(this, "main", moduleObject); } executeOptionalScript(preExec, cx, executionScope); moduleScript.getScript().exec(cx, executionScope); executeOptionalScript(postExec, cx, executionScope); return ScriptRuntime.toObject(cx, nativeScope, ScriptableObject.getProperty(moduleObject, "exports")); }
@Override protected boolean isValid(Row row) throws Exception { Map<String, Object> values = new ScriptAccessColumnMap(_columns, row, _evaluatedColumns); Scriptable scope = _context.newObject(_standardObjectsScope); scope.setPrototype(_standardObjectsScope); scope.setParentScope(null); Object wrappedValues = Context.javaToJS(values, scope); ScriptableObject.putProperty(scope, "values", wrappedValues); Object result = _script.exec(_context, scope); if (result instanceof Boolean) { return (Boolean) result; } throw new IllegalStateException( "Javascript expression did not return a boolean"); }
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if ( args.length != 3 && args.length != 2 ) { throw new IllegalArgumentException(); } String code = (String) Context.toString(args[0]); Scriptable vmContext = (Scriptable) args[1]; String scriptName = (String) (args.length > 2 ? args[2] : "_RunInConext_NoName" ); ScriptableObject.putProperty(vmContext, "window", vmContext); vmContext.setParentScope(scope ); return cx.evaluateString(vmContext, code, scriptName, 0, null); } }
public static RowMetaInterface getInputRowMeta( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 0 ) { try { Object scmO = actualObject.get( "_step_", actualObject ); try { ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class ); return scm.getInputRowMeta(); } catch ( Exception e ) { ScriptValuesModDummy scm = (ScriptValuesModDummy) Context.jsToJava( scmO, ScriptValuesModDummy.class ); return scm.getInputRowMeta(); } } catch ( Exception e ) { throw Context.reportRuntimeError( "Unable to get the input row metadata because of an error: " + Const.CR + e.toString() ); } } else { throw Context.reportRuntimeError( "The function call getInputRowMeta doesn't require arguments." ); } }
private Object[] compileScript(Context cx, String scriptStr, Scriptable scriptScope, File f) { int opt = cx.getOptimizationLevel(); cx.setOptimizationLevel(-1); Script script = cx.compileString(scriptStr, f.getName(), 1, null); script.exec(cx, scriptScope); Object[] ids = scriptScope.getIds(); cx.setOptimizationLevel(opt); script = cx.compileString(scriptStr, f.getName(), 1, null); script.exec(cx, scriptScope); return ids; }
private Reducer(String reduceTxt, Context cx) { Scriptable scope = new ImporterTopLevel(cx); cx.evaluateString(scope, REDUCE_JS, "reduce.js", 1, null); Scriptable builtins = (Scriptable) scope.get("BUILTIN_REDUCERS", scope); if (builtins.has(reduceTxt, builtins)) { reduceFunc = (Function)builtins.get(reduceTxt, builtins); } else { reduceFunc = cx.compileFunction(scope, reduceTxt, "reduce", 1, null); } }
public static Object getTransformationName( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { try { Object objTranName = Context.toString( actualObject.get( "_TransformationName_", actualObject ) ); return objTranName; } catch ( Exception e ) { throw Context.reportRuntimeError( e.toString() ); } }
public static Object[] createRowCopy( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) { if ( ArgList.length == 1 ) { try { int newSize = (int) Math.round( Context.toNumber( ArgList[0] ) ); Object scmO = actualObject.get( "row", actualObject ); Object[] row = (Object[]) Context.jsToJava( scmO, ( new Object[] {} ).getClass() ); return RowDataUtil.createResizedCopy( row, newSize ); } catch ( Exception e ) { throw Context.reportRuntimeError( "Unable to create a row copy: " + Const.CR + e.toString() ); } } else { throw Context .reportRuntimeError( "The function call createRowCopy requires a single arguments : the new size of the row" ); } }