CWebApi

This is the documentation of the helper class CWebApi of the RemoteSkin Web API. This class can be used to send messages to the browser with which the DOM tree of the website can be changed.

Usage

You have a target that should send commands to the browser. Create a private field in the target class:

private final CWebApi mWebApi;
    

Initialize the field (e.g. in the constructor). In any case, you need the target address of the web socket connection.

mWebApi = new CWebApi(this,
                      mWebSocketConnectionAddress);
    

Registration of website notifications

In order for notifications from the website to find their way to the targets, element IDs must be linked to target addresses.

registerWidgets

Registers an array of element IDs with the target address of the sender. These can then receive the events from these HTML elements as a message.

public void registerWidgets(final String @NotNull [] aIds) throws CException;
    

deregisterWidgetOwner

Deregisters a target. All registered element IDs that were registered with its address are removed.

public void deregisterWidgetOwner() throws CException;
    

Manipulation of the website

Call a method of the API. This will then send a message to the browser via the WebSocket target connected to the browser.

mWebApi.addClassToElement("#id_my_element",
                          "class1");
    

Methoden

addClassToElement

Adds a single class to an HTML element or several HTML elements. The selector for identifying the HTML element can be e.g. #id_my_element for an ID or .my_class for a class.

The message sent to the WebSocketConnection is CRecordWebAddClassesToElement.

public void addClassToElement(@NotNull final String aSelector,
                              @NotNull final String aClass) throws CException;
    

removeClassFromElement

Removes a single class from an HTML element or from several HTML elements. The selector for identifying the HTML element can be e.g. #id_my_element for an ID or .my_class for a class.

The message sent to the WebSocketConnection is CRecordWebRemoveClassesFromElement.

public void removeClassFromElement(@NotNull final String aSelector,
                                   @NotNull final String aClass) throws CException;
    

addClassesToElement

Adds several classes to an HTML element or several HTML elements. The selector for identifying the HTML element can be e.g. #id_my_element for an ID or .my_class for a class.

The message sent to the WebSocketConnection is CRecordWebAddClassesToElement.

public void addClassesToElement(@NotNull final String aSelector,
                                @NotNull final Collection<String> aClasses) throws CException;
    

removeClassesFromElement

Removes classes from an HTML element.

The message sent to the WebSocketConnection is CRecordWebRemoveClassesFromElement.

public void removeClassesFromElement(@NotNull final String aSelector,
                                     @NotNull final Collection<String> aClasses) throws CException;
    

addClickListener1

Adds a click listener to an HTML element. At the same time, IDs of other HTML elements are listed, from which you want to get the current value at the moment of the click. The event sent by the browser is CRecordWebNotifyClick1.

The message sent to the WebSocketConnection is CRecordWebListenOnClick1.

public void addClickListener1(@NotNull final String aId,
                              @NotNull final String[] aIds) throws CException;
    

addClickListener2

Adds click listeners to a number of HTML elements. The message that is generated by the browser when a click is made is called CRecordWebNotifyClick2.

The message sent to the WebSocketConnection is CRecordWebListenOnClick2.

public void addClickListener2(@NotNull final String[] aIds) throws CException;
    

addCss

The method inserts the content of a CSS file into the web page. An ID is assigned to the CSS element so that it can be easily removed again at any time.

The message sent to the WebSocketConnection is CRecordWebAddStyleSheet.

public void addCss(@NotNull final String aStyleSheetId,
                   @NotNull final String aCss) throws CException
    

removeCss

Removes the style sheet with the given ID.

The message sent to the WebSocketConnection is CRecordWebRemoveStyleSheet.

public void removeCss(@NotNull final String aId) throws CException;
    

addScript

The method adds a JavaScript to the website. This can be an external JavaScript file (aSource) or the code itself (aContent). The script element is given an ID so that it can be removed again.

The message sent to the WebSocketConnection is CRecordWebAddScript.

public void addScript(@NotNull final String aId,
                      @Nullable final String aContent,
                      @Nullable final String aSource);
    

removeScript

The method removes a script with the ID aId from the web page.

The message sent to the WebSocketConnection is CRecordWebRemoveScript.

public void removeScript(@NotNull final String aId) throws CException;
    

addTableRowListener

The method adds a click listener for a table row.

The message sent to the WebSocketConnection is CRecordWebAddTableRowListener.

public void addTableRowListener(@NotNull final String aId) throws CException;
    

alert

A message is displayed in a simple alert box.

The message sent to the WebSocketConnection is CRecordWebAlert.

public void alert(@NotNull final String aMessage) throws CException;
    

loadImage

An image file is downloaded asynchronously from a FileStore of any node to the node of the web server. When the image is downloaded, the source attribute of the image element is updated with the path to the image file.

Files in the FileStores are identified by a relative path.

The message sent to the WebSocketConnection is CRecordWebLoadImage.

public void loadImage(@NotNull final String aRelativePath,
                      @NotNull final String aElementId) throws CException;
    

openNewTab

A web page is opened in a new tab. If sameUrl=true, the current URL is used, otherwise the specified URL is used. The optional properties are any URL parameters.

The message sent to the WebSocketConnection is CRecordWebOpenNewTab.

public void openNewTab(final boolean aSameUrl,
                       @Nullable final String aUrl,
                       @Nullable final CStringProperties aProperties) throws CException;
    

removeElement

Removes the element with the ID aId from the web page.

The message sent to the WebSocketConnection is CRecordWebRemoveElement.

public void removeElement(@NotNull final String aId) throws CException;
    

setInnerHtml

Inserts HTML markup within an element.

The message sent to the WebSocketConnection is CRecordWebSetInnerHtml.

public void setInnerHtml(@NotNull final String aId,
                         @NotNull final String aHtml) throws CException;
    

setStylesForElements

Adds styles to one or more elements. The elements are identified via the selector.

The message sent to the WebSocketConnection is CRecordWebSetStylesForElements.

public void setStylesForElements(@NotNull final String aSelector,
                                 @NotNull final CStringProperties aStyles) throws CException;
    

setValue

Sets a value for an input element in a form.

The message sent to the WebSocketConnection is CRecordWebSetValue.

public void setValue(@NotNull final String aId,
                     @NotNull final String aValue) throws CException;
    

showModal

Shows a modal dialog that must be added to the website beforehand.

The message sent to the WebSocketConnection is CRecordWebShowModal.

public void showModal(@NotNull final String aId) throws CException;