Class JavaScriptApi

java.lang.Object
com.oorian.html.js.JavaScriptApi
Direct Known Subclasses:
ClipboardApi, FullscreenApi, GeolocationApi, MediaDevicesApi, NavigationApi, NetworkApi, NotificationApi, PermissionsApi, ScreenApi, SelectionApi, ShareApi, SpeechApi, StorageApi, TimerApi, VibrationApi, VisibilityApi, WakeLockApi, WindowApi

public class JavaScriptApi extends Object
Base class for JavaScript API wrappers providing access to browser functionality from server-side Java code.

This class provides the foundation for all JavaScript API classes in the Oorian framework. It includes the core executeJs methods for executing arbitrary JavaScript on the client, as well as utility methods for obtaining the current page context.

All methods are provided in two forms:

  • Convenience form - No page parameter; uses thread-local page lookup
  • Efficient form - Accepts page parameter; avoids thread-local lookup

Usage:


 // Convenience - uses thread-local page lookup
 JavaScriptApi.executeJs("console.log('Hello')");

 // Efficient - passes page reference directly
 JavaScriptApi.executeJs(this, "console.log('Hello')");
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • JavaScriptApi

      public JavaScriptApi()
  • Method Details

    • getPage

      protected static HtmlPage getPage()
      Returns the current page from the thread-local session context.
      Returns:
      The current HtmlPage instance.
    • executeJs

      public static void executeJs(String script)
      Executes a JavaScript statement on the client using the current page context.
      Parameters:
      script - The JavaScript code to execute.
    • executeJs

      public static void executeJs(HtmlPage page, String script)
      Executes a JavaScript statement on the client.
      Parameters:
      page - The page to execute the script on.
      script - The JavaScript code to execute.
    • executeJs

      public static void executeJs(String functionName, Object... parameters)
      Executes a JavaScript function on the client with the specified parameters using the current page context.
      Parameters:
      functionName - The JavaScript function name.
      parameters - The parameters to pass to the function.
    • executeJs

      public static void executeJs(HtmlPage page, String functionName, Object... parameters)
      Executes a JavaScript function on the client with the specified parameters.
      Parameters:
      page - The page to execute the script on.
      functionName - The JavaScript function name.
      parameters - The parameters to pass to the function.