Class ScriptHandler
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.core.ui.script.ScriptHandler
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
- Direct Known Subclasses:
AsyncScriptHandler
,CmsScriptHandler
,RepositoryScriptHandler
,ScriptVersionHandlerScriptHandler
public class ScriptHandler
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable
Handler to describe and execute server scripts
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
A processor for scripts results. -
Field Summary
Modifier and TypeFieldDescriptionprotected Context
The avalon contextprotected CurrentUserProvider
The current user providerprotected I18nUtils
The i18n utilsprotected RightManager
The right managerprotected ScriptBindingExtensionPoint
The script binding extension pointprotected static final String
Right for script executionstatic final String
Avalon role. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription_executeScript
(ScriptExecArguments arguments, Map<String, Object> scriptVariables, String workspaceName) Execute a script in the js admin console.protected ScriptExecArguments
buildExecArguments
(Map<String, Object> arguments) Builds theScriptExecArguments
object from the untyped JS object (seen as a Map in Java)void
contextualize
(Context context) executeScript
(String script) Execute a script in the js admin console.Execute a script in the js console.executeScript
(Map<String, Object> arguments) Execute a script in the js console.protected ScriptHandler.ResultProcessor
Returns theScriptHandler.ResultProcessor
used to process script result.Get the list of variables and functions descriptions currently registered for the Scripts.protected String
Gets the workspace nameprotected Object
processScriptResult
(Map<String, Object> results, Object scriptResult, ScriptExecArguments execArgs) Process the result of the scriptvoid
service
(ServiceManager serviceManager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
Avalon role. -
RIGHT_EXECUTE_SCRIPTS
Right for script execution- See Also:
-
_scriptBindingEP
The script binding extension point -
_rightManager
The right manager -
_currentUserProvider
The current user provider -
_i18nUtils
The i18n utils -
_context
The avalon context
-
-
Constructor Details
-
ScriptHandler
public ScriptHandler()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
buildExecArguments
Builds theScriptExecArguments
object from the untyped JS object (seen as a Map in Java)- Parameters:
arguments
- The untyped JS object- Returns:
- the
ScriptExecArguments
-
executeScript
Execute a script in the js admin console.- Parameters:
script
- The script as a String.- Returns:
- A map of information on the script execution.
- Throws:
ScriptException
- If an error occurs
-
executeScript
Execute a script in the js console.- Parameters:
arguments
- The map of arguments. Must contains at least the argument "script"- Returns:
- A map of information on the script execution.
- Throws:
ScriptException
- If an error occurs
-
executeScript
public Map<String,Object> executeScript(String script, Map<String, Object> scriptVariables, String workspaceName) throws ScriptExceptionExecute a script in the js console.- Parameters:
script
- The script as a String.scriptVariables
- map of variables that will be added to the script.workspaceName
- The workspace name- Returns:
- A map of information on the script execution.
- Throws:
ScriptException
- If an error occurs
-
_executeScript
protected Map<String,Object> _executeScript(ScriptExecArguments arguments, Map<String, Object> scriptVariables, String workspaceName) throws ScriptExceptionExecute a script in the js admin console.- Parameters:
arguments
- The arguments for script executionscriptVariables
- map of variables that will be added to the script.workspaceName
- The workspace name- Returns:
- A map of information on the script execution.
- Throws:
ScriptException
- If an error occurs
-
processScriptResult
protected Object processScriptResult(Map<String, Object> results, Object scriptResult, ScriptExecArguments execArgs) Process the result of the script- Parameters:
results
- The results map, available to fillscriptResult
- The result of the scriptexecArgs
- The script execution arguments- Returns:
- The processed result
-
getProcessor
Returns theScriptHandler.ResultProcessor
used to process script result.- Returns:
- the
ScriptHandler.ResultProcessor
.
-
getScriptBindingDescription
Get the list of variables and functions descriptions currently registered for the Scripts.- Returns:
- The list of variables and functions, as describes by the script bindings available.
-
getWorkspaceName
Gets the workspace name- Returns:
- the workspace name
-