Class CmsJsUtil


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

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void callNamedFunctionWithString​(java.lang.String name, java.lang.String param)
      Calls a named global function (i.e.
      static void callNamedFunctionWithString2​(java.lang.String name, java.lang.String param1, java.lang.String param2)
      Calls a named global function (i.e.
      static void callWithString​(com.google.gwt.core.client.JavaScriptObject func, java.lang.String param)
      Calls a JS function with a string parameter.
      static void closeWindow()
      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, java.util.Map<java.lang.String,​java.lang.String> map)
      Iterates over attributes of a Javascript object and copies them to a string map.
      static void forceLoadUri​(java.lang.String uri)
      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, java.lang.String attr)
      Reads an attribute from a Javascript object.
      static java.lang.String getAttributeString​(com.google.gwt.core.client.JavaScriptObject jso, java.lang.String attr)
      Reads a string-valued attribute from a Javascript object.
      static java.lang.String getLocalStorage​(java.lang.String key)  
      static com.google.gwt.core.client.JavaScriptObject getWindow()
      Gets the current window as a Javascript object.
      static com.google.gwt.core.client.JsArrayString newArray()
      Creates an empty Javascript string array.
      static com.google.gwt.core.client.JavaScriptObject parseJSON​(java.lang.String json)
      Creates a JavaScript object from a JSON string.
      static void setAttribute​(com.google.gwt.core.client.JavaScriptObject jso, java.lang.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 toJavaScriptObject​(java.lang.Object o)  
      static com.google.gwt.user.client.rpc.AsyncCallback<java.lang.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 Detail

      • callNamedFunctionWithString

        public static void callNamedFunctionWithString​(java.lang.String name,
                                                       java.lang.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​(java.lang.String name,
                                                        java.lang.String param1,
                                                        java.lang.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,
                                          java.lang.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,
                                                     java.util.Map<java.lang.String,​java.lang.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​(java.lang.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,
                                                                               java.lang.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 java.lang.String getAttributeString​(com.google.gwt.core.client.JavaScriptObject jso,
                                                          java.lang.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 java.lang.String getLocalStorage​(java.lang.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​(java.lang.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,
                                        java.lang.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​(java.lang.Object o)
      • wrapCallback

        public static com.google.gwt.user.client.rpc.AsyncCallback<java.lang.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