1 38 package com.gargoylesoftware.htmlunit; 39 40 import com.gargoylesoftware.htmlunit.html.HtmlElement; 41 import com.gargoylesoftware.htmlunit.html.HtmlPage; 42 import org.apache.commons.logging.Log; 43 import org.apache.commons.logging.LogFactory; 44 45 53 public abstract class ScriptEngine { 54 private final WebClient webClient_; 55 private final Log scriptEngineLog_ = LogFactory.getLog(ScriptEngine.class); 56 57 61 protected ScriptEngine( final WebClient webClient ) { 62 Assert.notNull("webClient", webClient); 63 webClient_ = webClient; 64 } 65 66 67 71 public final WebClient getWebClient() { 72 return webClient_; 73 } 74 75 76 82 protected final void assertNotNull( final String description, final Object object ) { 83 Assert.notNull(description, object); 84 } 85 86 90 public abstract void initialize(final HtmlPage page); 91 92 100 public Object execute( 101 final HtmlPage htmlPage, final String sourceCode, final String sourceName ) { 102 103 return execute(htmlPage, sourceCode, sourceName, null); 104 } 105 106 107 116 public abstract Object execute( 117 final HtmlPage htmlPage, final String sourceCode, final String sourceName, final HtmlElement htmlElement ); 118 119 120 129 public abstract Object callFunction( 130 final HtmlPage htmlPage, 131 final Object javaScriptFunction, 132 final Object thisObject, 133 final Object [] args, 134 final HtmlElement htmlElementScope ); 135 136 137 143 public abstract String toString( 144 final HtmlPage htmlPage, final Object javaScriptObject ); 145 146 147 151 public Log getScriptEngineLog() { 152 return scriptEngineLog_; 153 } 154 155 167 public String preProcess( 168 final HtmlPage htmlPage, final String sourceCode, final String sourceName, final HtmlElement htmlElement ) { 169 170 String newSourceCode = sourceCode; 171 final ScriptPreProcessor preProcessor = getWebClient().getScriptPreProcessor(); 172 if ( preProcessor != null ) { 173 newSourceCode = preProcessor.preProcess(htmlPage, sourceCode, sourceName, htmlElement); 174 if ( newSourceCode == null ) { 175 newSourceCode = ""; 176 } 177 } 178 return newSourceCode; 179 } 180 181 186 public abstract boolean isScriptRunning(); 187 } 188 | Popular Tags |