/** * run the given script * @param language - the language of the script * @param script - the script to run */ public String runScript( String language, String script ) { if (!supportsScriptLanguage( language )) return ""; try { script = script.trim(); if (script.startsWith( "<!--" )) { script = withoutFirstLine( script ); if (script.endsWith( "-->" )) script = script.substring( 0, script.lastIndexOf( "-->" )); } Context context = Context.enter(); context.initStandardObjects( null ); context.evaluateString( this, script, "httpunit", 0, null ); return getDocumentWriteBuffer(); } catch (Exception e) { handleScriptException( e, "Script '" + script + "'" ); return ""; } finally { discardDocumentWriteBuffer(); Context.exit(); } }
/** * run the given script * @param language - the language of the script * @param script - the script to run */ public String runScript( String language, String script ) { if (!supportsScriptLanguage( language )) return ""; try { script = script.trim(); if (script.startsWith( "<!--" )) { script = withoutFirstLine( script ); if (script.endsWith( "-->" )) script = script.substring( 0, script.lastIndexOf( "-->" )); } Context context = Context.enter(); context.initStandardObjects( null ); context.evaluateString( this, script, "httpunit", 0, null ); return getDocumentWriteBuffer(); } catch (Exception e) { handleScriptException( e, "Script '" + script + "'" ); return ""; } finally { discardDocumentWriteBuffer(); Context.exit(); } }
/** * load * @param response */ public void load( WebResponse response ) { Function onLoadEvent=null; try { Context context = Context.enter(); context.initStandardObjects( null ); HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument(); if (!(htmlDocument instanceof HTMLDocumentImpl)) return; HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody(); if (body == null) return; onLoadEvent = body.getOnloadEvent(); if (onLoadEvent == null) return; onLoadEvent.call( context, body, body, new Object[0] ); } catch (JavaScriptException e) { ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString()); // HttpUnitUtils.handleException(e); } catch (EcmaError ee) { //throw ee; ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString()); } finally { Context.exit(); } }
/** * run the given script * @param language - the language of the script * @param script - the script to run */ public String runScript( String language, String script ) { if (!supportsScriptLanguage( language )) return ""; try { script = script.trim(); if (script.startsWith( "<!--" )) { script = withoutFirstLine( script ); if (script.endsWith( "-->" )) script = script.substring( 0, script.lastIndexOf( "-->" )); } Context context = Context.enter(); context.initStandardObjects( null ); context.evaluateString( this, script, "httpunit", 0, null ); return getDocumentWriteBuffer(); } catch (Exception e) { handleScriptException( e, "Script '" + script + "'" ); return ""; } finally { discardDocumentWriteBuffer(); Context.exit(); } }
/** * load * @param response */ public void load( WebResponse response ) { Function onLoadEvent=null; try { Context context = Context.enter(); context.initStandardObjects( null ); HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument(); if (!(htmlDocument instanceof HTMLDocumentImpl)) return; HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody(); if (body == null) return; onLoadEvent = body.getOnloadEvent(); if (onLoadEvent == null) return; onLoadEvent.call( context, body, body, new Object[0] ); } catch (JavaScriptException e) { ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString()); // HttpUnitUtils.handleException(e); } catch (EcmaError ee) { //throw ee; ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString()); } finally { Context.exit(); } }
/** * load * @param response */ public void load( WebResponse response ) { Function onLoadEvent=null; try { Context context = Context.enter(); context.initStandardObjects( null ); HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument(); if (!(htmlDocument instanceof HTMLDocumentImpl)) return; HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody(); if (body == null) return; onLoadEvent = body.getOnloadEvent(); if (onLoadEvent == null) return; onLoadEvent.call( context, body, body, new Object[0] ); } catch (JavaScriptException e) { ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString()); // HttpUnitUtils.handleException(e); } catch (EcmaError ee) { //throw ee; ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString()); } finally { Context.exit(); } }
/** * Evaluates the specified string as JavaScript. Will return null if the script has no return value. * @param expression - the expression to evaluate */ public Object evaluateExpression( String expression ) { try { Context context = Context.enter(); context.initStandardObjects( null ); Object result = context.evaluateString( this, expression, "httpunit", 0, null ); return (result == null || result instanceof Undefined) ? null : result; } catch (Exception e) { handleScriptException( e, "URL '" + expression + "'" ); return null; } finally { Context.exit(); } }
/** * Evaluates the specified string as JavaScript. Will return null if the script has no return value. * @param expression - the expression to evaluate */ public Object evaluateExpression( String expression ) { try { Context context = Context.enter(); context.initStandardObjects( null ); Object result = context.evaluateString( this, expression, "httpunit", 0, null ); return (result == null || result instanceof Undefined) ? null : result; } catch (Exception e) { handleScriptException( e, "URL '" + expression + "'" ); return null; } finally { Context.exit(); } }
/** * Evaluates the specified string as JavaScript. Will return null if the script has no return value. * @param expression - the expression to evaluate */ public Object evaluateExpression( String expression ) { try { Context context = Context.enter(); context.initStandardObjects( null ); Object result = context.evaluateString( this, expression, "httpunit", 0, null ); return (result == null || result instanceof Undefined) ? null : result; } catch (Exception e) { handleScriptException( e, "URL '" + expression + "'" ); return null; } finally { Context.exit(); } }
/** * handle the event that has the given script attached * by compiling the eventScript as a function and executing it * @param eventScript - the script to use */ public boolean doEventScript( String eventScript ) { if (eventScript.length() == 0) { return true; } else { try { Context context = Context.enter(); context.initStandardObjects( null ); context.setOptimizationLevel( -1 ); // wrap the eventScript into a function Function f = context.compileFunction( this, "function x() { " + eventScript + "}", "httpunit", 0, null ); // call the function with no arguments Object result = f.call( context, this, this, NO_ARGS ); // return the result of the function or false if it is not boolean return (!(result instanceof Boolean)) || ((Boolean) result).booleanValue(); } catch (Exception e) { handleScriptException( e, "Event '" + eventScript + "'" ); return false; } finally { Context.exit(); } } // if }
/** * handle the event that has the given script attached * by compiling the eventScript as a function and executing it * @param eventScript - the script to use */ public boolean doEventScript( String eventScript ) { if (eventScript.length() == 0) { return true; } else { try { Context context = Context.enter(); context.initStandardObjects( null ); context.setOptimizationLevel( -1 ); // wrap the eventScript into a function Function f = context.compileFunction( this, "function x() { " + eventScript + "}", "httpunit", 0, null ); // call the function with no arguments Object result = f.call( context, this, this, NO_ARGS ); // return the result of the function or false if it is not boolean return (!(result instanceof Boolean)) || ((Boolean) result).booleanValue(); } catch (Exception e) { handleScriptException( e, "Event '" + eventScript + "'" ); return false; } finally { Context.exit(); } } // if }
/** * handle the event that has the given script attached * by compiling the eventScript as a function and executing it * @param eventScript - the script to use */ public boolean doEventScript( String eventScript ) { if (eventScript.length() == 0) { return true; } else { try { Context context = Context.enter(); context.initStandardObjects( null ); context.setOptimizationLevel( -1 ); // wrap the eventScript into a function Function f = context.compileFunction( this, "function x() { " + eventScript + "}", "httpunit", 0, null ); // call the function with no arguments Object result = f.call( context, this, this, NO_ARGS ); // return the result of the function or false if it is not boolean return (!(result instanceof Boolean)) || ((Boolean) result).booleanValue(); } catch (Exception e) { handleScriptException( e, "Event '" + eventScript + "'" ); return false; } finally { Context.exit(); } } // if }