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
Nested Classes Modifier and Type Class Description protected static class
ScriptHandler.ResultProcessor
A processor for scripts results.
-
Field Summary
Fields Modifier and Type Field Description private static String
__SCRIPT_INSERT_CLEANUP_MANAGER
private static String
__SCRIPT_INSERT_RUN_MAIN
protected Context
_context
The avalon contextprotected CurrentUserProvider
_currentUserProvider
The current user providerprotected I18nUtils
_i18nUtils
The i18n utilsprotected RightManager
_rightManager
The right managerprotected ScriptBindingExtensionPoint
_scriptBindingEP
The script binding extension pointprotected static String
RIGHT_EXECUTE_SCRIPTS
Right for script executionstatic String
ROLE
Avalon role.
-
Constructor Summary
Constructors Constructor Description ScriptHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_addToBinding(List<Map<String,Object>> descriptionsList, Map<? extends Object,ScriptBindingDocumentation> descriptions, String type)
protected Map<String,Object>
_executeScript(ScriptExecArguments arguments, Map<String,Object> scriptVariables, String workspaceName)
Execute a script in the js admin console.private void
_setScriptBindings(Map<String,Object> variables, List<String> scriptText, List<ScriptBinding> scriptBindings, ScriptExecArguments execArgs)
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)
Map<String,Object>
executeScript(String script)
Execute a script in the js admin console.Map<String,Object>
executeScript(String script, Map<String,Object> scriptVariables, String workspaceName)
Execute a script in the js console.Map<String,Object>
executeScript(Map<String,Object> arguments)
Execute a script in the js console.protected ScriptHandler.ResultProcessor
getProcessor()
Returns theScriptHandler.ResultProcessor
used to process script result.List<Map<String,Object>>
getScriptBindingDescription()
Get the list of variables and functions descriptions currently registered for the Scripts.protected String
getWorkspaceName()
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 Detail
-
RIGHT_EXECUTE_SCRIPTS
protected static final String RIGHT_EXECUTE_SCRIPTS
Right for script execution- See Also:
- Constant Field Values
-
__SCRIPT_INSERT_CLEANUP_MANAGER
private static final String __SCRIPT_INSERT_CLEANUP_MANAGER
- See Also:
- Constant Field Values
-
__SCRIPT_INSERT_RUN_MAIN
private static final String __SCRIPT_INSERT_RUN_MAIN
- See Also:
- Constant Field Values
-
_scriptBindingEP
protected ScriptBindingExtensionPoint _scriptBindingEP
The script binding extension point
-
_rightManager
protected RightManager _rightManager
The right manager
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider
-
_i18nUtils
protected I18nUtils _i18nUtils
The i18n utils
-
-
Constructor Detail
-
ScriptHandler
public ScriptHandler()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
buildExecArguments
protected ScriptExecArguments buildExecArguments(Map<String,Object> arguments)
Builds theScriptExecArguments
object from the untyped JS object (seen as a Map in Java)- Parameters:
arguments
- The untyped JS object- Returns:
- the
ScriptExecArguments
-
executeScript
public final Map<String,Object> executeScript(String script) throws ScriptException
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
public Map<String,Object> executeScript(Map<String,Object> arguments) throws ScriptException
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 ScriptException
Execute 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 ScriptException
Execute 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
-
_setScriptBindings
private void _setScriptBindings(Map<String,Object> variables, List<String> scriptText, List<ScriptBinding> scriptBindings, ScriptExecArguments execArgs)
-
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
protected ScriptHandler.ResultProcessor getProcessor()
Returns theScriptHandler.ResultProcessor
used to process script result.- Returns:
- the
ScriptHandler.ResultProcessor
.
-
_addToBinding
private void _addToBinding(List<Map<String,Object>> descriptionsList, Map<? extends Object,ScriptBindingDocumentation> descriptions, String type)
-
getScriptBindingDescription
public List<Map<String,Object>> 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
protected String getWorkspaceName()
Gets the workspace name- Returns:
- the workspace name
-
-