Class CmsJsUtil

java.lang.Object
org.opencms.gwt.client.util.CmsJsUtil

public final class CmsJsUtil extends Object
A class containing generic Javascript utility methods.

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Calls a named global function (i.e.
    static void
    Calls a named global function (i.e.
    static void
    callWithString(com.google.gwt.core.client.JavaScriptObject func, String param)
    Calls a JS function with a string parameter.
    static void
    Closes the browser window.
    static com.google.gwt.user.client.Command
    convertCallbackToCommand(com.google.gwt.core.client.JavaScriptObject func)
    Creates a Command object which calls the given native JS function.
    static void
    fillStringMapFromJsObject(com.google.gwt.core.client.JavaScriptObject jso, Map<String,String> map)
    Iterates over attributes of a Javascript object and copies them to a string map.
    static void
    Opens the given URI in the current browser window, ensuring that a request to the server is triggered.
    static com.google.gwt.core.client.JavaScriptObject
    getAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr)
    Reads an attribute from a Javascript object.
    static String
    getAttributeString(com.google.gwt.core.client.JavaScriptObject jso, String attr)
    Reads a string-valued attribute from a Javascript object.
    static String
     
    static com.google.gwt.core.client.JavaScriptObject
    Gets the current window as a Javascript object.
    static com.google.gwt.core.client.JsArrayString
    Creates an empty Javascript string array.
    static com.google.gwt.core.client.JavaScriptObject
    Creates a JavaScript object from a JSON string.
    static void
    setAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr, com.google.gwt.core.client.JavaScriptObject newValue)
    Sets an attribute of the given Javascript object to a new value.
    static com.google.gwt.core.client.JavaScriptObject
     
    static com.google.gwt.user.client.rpc.AsyncCallback<String>
    wrapCallback(com.google.gwt.core.client.JavaScriptObject func)
    Wraps a native JavaScript callback taking a string argument into an AsyncCallback so that it can easily be called from GWT Java code.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • callNamedFunctionWithString

      public static void callNamedFunctionWithString(String name, String param)
      Calls a named global function (i.e. a function-valued attribute of window) with a string argument.

      Parameters:
      name - the function name
      param - the function parameter
    • callNamedFunctionWithString2

      public static void callNamedFunctionWithString2(String name, String param1, String param2)
      Calls a named global function (i.e. a function-valued attribute of window) with a string argument.

      Parameters:
      name - the function name
      param1 - a function parameter
      param2 - a function parameter
    • callWithString

      public static void callWithString(com.google.gwt.core.client.JavaScriptObject func, String param)
      Calls a JS function with a string parameter.

      Parameters:
      func - the Javascript function
      param - the string parameter
    • closeWindow

      public static void closeWindow()
      Closes the browser window.
    • convertCallbackToCommand

      public static com.google.gwt.user.client.Command convertCallbackToCommand(com.google.gwt.core.client.JavaScriptObject func)
      Creates a Command object which calls the given native JS function.
      Parameters:
      func - a Javascript function
      Returns:
      a Command object which calls the native function
    • fillStringMapFromJsObject

      public static void fillStringMapFromJsObject(com.google.gwt.core.client.JavaScriptObject jso, Map<String,String> map)
      Iterates over attributes of a Javascript object and copies them to a string map.

      Converts all values to strings.

      Parameters:
      jso - the Javascript object
      map - the map to fill
    • forceLoadUri

      public static void forceLoadUri(String uri)
      Opens the given URI in the current browser window, ensuring that a request to the server is triggered.
      Parameters:
      uri - the URI to open
    • getAttribute

      public static com.google.gwt.core.client.JavaScriptObject getAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr)
      Reads an attribute from a Javascript object.

      Parameters:
      jso - the Javascript object
      attr - the name of the attribute
      Returns:
      the value of the attribute
    • getAttributeString

      public static String getAttributeString(com.google.gwt.core.client.JavaScriptObject jso, String attr)
      Reads a string-valued attribute from a Javascript object.

      Parameters:
      jso - the Javascript object
      attr - the name of the attribute
      Returns:
      the value of the attribute
    • getLocalStorage

      public static String getLocalStorage(String key)
    • getWindow

      public static com.google.gwt.core.client.JavaScriptObject getWindow()
      Gets the current window as a Javascript object.

      Returns:
      the current window
    • newArray

      public static com.google.gwt.core.client.JsArrayString newArray()
      Creates an empty Javascript string array.
      Returns:
      the new array
    • parseJSON

      public static com.google.gwt.core.client.JavaScriptObject parseJSON(String json)
      Creates a JavaScript object from a JSON string.
      Parameters:
      json - the JSON string
      Returns:
      the JavaScript object parsed from the JSON string
    • setAttribute

      public static void setAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr, com.google.gwt.core.client.JavaScriptObject newValue)
      Sets an attribute of the given Javascript object to a new value.

      Parameters:
      jso - the object to modify
      attr - the attribute to set
      newValue - the new attribute value
    • toJavaScriptObject

      public static com.google.gwt.core.client.JavaScriptObject toJavaScriptObject(Object o)
    • wrapCallback

      public static com.google.gwt.user.client.rpc.AsyncCallback<String> wrapCallback(com.google.gwt.core.client.JavaScriptObject func)
      Wraps a native JavaScript callback taking a string argument into an AsyncCallback so that it can easily be called from GWT Java code.

      Parameters:
      func - the function to wrap
      Returns:
      the AsyncCallback wrapper