org.eclipse.swt.browser.Browser.evaluate()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中org.eclipse.swt.browser.Browser.evaluate()方法的一些代码示例,展示了Browser.evaluate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Browser.evaluate()方法的具体详情如下:
包路径:org.eclipse.swt.browser.Browser
类名称:Browser
方法名:evaluate

Browser.evaluate介绍

[英]Returns the result, if any, of executing the specified script.

Evaluates a script containing javascript commands in the context of the current document. If document-defined functions or properties are accessed by the script then this method should not be invoked until the document has finished loading (ProgressListener.completed() gives notification of this).

If the script returns a value with a supported type then a java representation of the value is returned. The supported javascript -> java mappings are:

  • javascript null or undefined -> null
  • javascript number -> java.lang.Double
  • javascript string -> java.lang.String
  • javascript boolean -> java.lang.Boolean
  • javascript array whose elements are all of supported types -> java.lang.Object[]
    An SWTException is thrown if the return value has an unsupported type, or if evaluating the script causes a javascript error to be thrown.
    [中]返回执行指定脚本的结果(如果有)。
    在当前文档的上下文中计算包含javascript命令的脚本。如果脚本访问文档定义的函数或属性,则在文档完成加载之前不应调用此方法(ProgressListener.completed()发出此通知)。
    如果脚本返回一个支持类型的值,则返回该值的java表示形式。支持的javascript->java映射为:
    *javascript null或未定义->null
    *javascript编号->java.lang.Double
    *javascript字符串->java.lang.String
    *javascript布尔->java.lang.Boolean
    *元素均为受支持类型的javascript数组->java.lang.Object[]
    如果返回值的类型不受支持,或者计算脚本导致抛出javascript错误,则会抛出SWTException

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * Ask for user Agent of the available browser.
 *
 * @return a string that contains the user agent of the browser.
 */
protected String getUserAgent() {
 Browser browser;
 try {
  browser = new Browser(  new Shell(), SWT.NONE );
 } catch ( SWTError e ) {
  log.logError( "Could not open a browser", e );
  return  "";
 }
 String userAgent = browser.evaluate( "return window.navigator.userAgent;" ).toString();
 browser.close();
 return userAgent;
}

代码示例来源:origin: org.eclipse.rap/org.eclipse.rap.rwt

/**
 * Executes the given script in a non-blocking way. The <code>browserCallback</code> is notified
 * when the result from the operation is available.
 * <p>
 * Use this method instead of the <code>execute()</code> or <code>evaluate()</code> methods from
 * the respective <code>Browser</code> widget when running in <em>JEE_COMPATIBILITY</em> mode.
 * </p>
 *
 * <p>
 * This method will throw an IllegalStateException if called while another script is
 * still pending to be executed.
 * </p>
 * @param browser the browser to execute the script, must not be <code>null</code>.
 * @param script the script to execute, must not be <code>null</code>.
 * @param browserCallback the callback to be notified when the result from the script execution is
 * available, must not be <code>null</code>.
 *
 * @exception IllegalStateException when another script is already being executed.
 *
 * @see Browser
 * @see BrowserCallback
 * @see org.eclipse.rap.rwt.application.Application.OperationMode
 * @deprecated Use <code>Browser.evaluate( BrowserCallback )</code> instead
 */
@Deprecated
public static void evaluate( Browser browser, String script, BrowserCallback browserCallback ) {
 ParamCheck.notNull( browser, "browser" );
 browser.evaluate( script, browserCallback );
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.swt.win32.win32.x86

return evaluate (script, false);

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.linux.s390x

return evaluate (script, false);

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.aix.ppc

return evaluate (script, false);

代码示例来源:origin: org.eclipse.platform/org.eclipse.swt.gtk.linux.ppc

return evaluate (script, false);

代码示例来源:origin: org.xworker/xworker_swt

public void run(){
    Display display = new Display();
    Shell shell = new Shell(display);
    Browser browser = new Browser(shell, SWT.NONE);
    try{
      browser.setUrl(new File(World.getInstance().getPath() + "/webroot/js/xworker/InnerBrowserUtil.js").toURI().toString());
      Object value = browser.evaluate("var UA = navigator.userAgent.toLowerCase();return /webkit/i.test(UA);");
      if(value != null && "true".equals(value)){
        isWebKit = 1;
      }else{
        isWebKit = 0;
      }
    }catch(Exception e){
      
    }finally{						
      display.dispose();
    }
  }
}).start();

代码示例来源:origin: org.xworker/xworker_swt

public static void evaluateBrowserScript(Browser browser, String script, BrowserCallback callback, ActionContext actionContext) {
  if(SwtUtils.isRWT()) {
    Thing swt = World.getInstance().getThing("xworker.swt.SWT");
    swt.doAction("rwtBrowserEvaluate", actionContext, "browser", browser, "script", script, "callback", callback);
  }else {
    browser.evaluate(script);
  }
}

代码示例来源:origin: org.xworker/xworker_swt

}else{
  browser.evaluate("setHtml()");

代码示例来源:origin: stackoverflow.com

boolean result = (boolean) browser.evaluate("return window.find('" + baz + "');");
System.out.println(result);

代码示例来源:origin: stackoverflow.com

public void completed(ProgressEvent progressEvent)
  System.out.println(browser.evaluate("var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\\/))\\/?\\s*(\\d+)/i) || []; if (/trident/i.test(M[1])) { tem = /\\brv[ :]+(\\d+)/g.exec(ua) || []; return 'IE ' + (tem[1] || ''); } if (M[1] === 'Chrome') { tem = ua.match(/\\b(OPR|Edge)\\/(\\d+)/); if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera'); } M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; if ((tem = ua.match(/version\\/(\\d+)/i)) != null) M.splice(1, 1, tem[1]); return M.join(' ');"));

代码示例来源:origin: org.eclipse.mylyn.wikitext/ui

Object result = browser.evaluate(JAVASCRIPT_GETSCROLLTOP);
final int verticalScrollbarPos = result != null ? ((Number) result).intValue() : 0;
String xhtml = null;

代码示例来源:origin: org.xworker/xworker_swt

try{
  value = browser.evaluate("return CKEDITOR.instances.data.getData()");
}catch(Throwable e){

相关文章