5.12 APIs that can be used with JavaScript Plugin Parts
The following table describes the APIs (JavaScript APIs) that can be used with JavaScript Plugin Parts.
Category |
Class name |
Description |
---|---|---|
Plugin manager |
This class provides objects that allow JavaScript to perform processing provided by Navigation Platform. |
|
REST caller |
This class invokes a URL from JavaScript. |
To use an API, you have to acquire the JavaScriptPluginManager object by using the reserved variable ucnpJavaScriptPluginManager from JavaScript. Furthermore, if REST is to be invoked, you have to acquire the RestClient object by using the getRestClient method of the reserved variable ucnpJavaScriptPluginManager.
-
Coding example
var client = ucnpJavaScriptPluginManager.getRestClient();
Because the methods (except the execute method) of the RestClient object return the RestClient object of the caller, they can be invoked with a method chain.
-
Coding example
var result = client .addHeader("Accept-Encoding", "deflate") .setAuthentication("user1", "pass1") .setMethod(client.METHOD_POST) .setPostContentType("text/json") .setPostContent("{ \"operation\": \"start\" }") .setReturnType(client.RETURNTYPE_JSON) .execute();
You can acquire the constant to be specified as the argument of the method of the RestClient object from the RestClient instance.
-
Coding example
var client = ucnpJavaScriptPluginManager.getRestClient(); var result = client .setMethod(client.METHOD_POST) .setReturnType(client.RETURNTYPE_STRING) .execute();
- Note:
-
You can select the Execute in the browser check box so that a script with the following API methods can run on a web browser (on the client-side). In such a case, the API methods return Map or List arrays in a different format from when they run on a server.
-
getCurrentParamsTypeMap
-
getReturnMap
A Map indicates an associative array that contains key-value records while a List indicates an array that contains just a list of values. Note that, depending on whether to select the Execute in the browser check box, you need to use the API methods to handle Map or List differently as described in the following examples:
- - Coding example 1: Get the type of the input parameter param0
-
-
When the Execute in the browser check box is cleared
var map = getCurrentParamsTypeMap(); var param0Type = map.get("param0");
-
When the Execute in the browser check box is selected
var map = getCurrentParamsTypeMap(); var param0Type = map["param0"];
-
- - Coding example 2: Raise and highlight an error when the input parameter param0 is empty
-
-
When the Execute in the browser check box is cleared
var retMap = ucnpJavaScriptPluginManager.getReturnMap(); if (praram0 === "") { var errorParts = new java.util.ArrayList(); errorParts.add("param0"); retMap.put("ucnp.error.params.list", errorParts); retMap.put("ucnp.error.message", "error!"); }
-
When the Execute in the browser check box is selected
var retMap = ucnpJavaScriptPluginManager.getReturnMap(); if (praram0 === "") { var errorParts = []; errorParts.push("param0"); retMap["ucnp.error.params.list"] = errorParts; retMap["ucnp.error.message"] = "Error!"; }
-
-
- Organization of this section