001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.core.ui.script; 017 018import java.util.Map; 019import java.util.regex.Pattern; 020 021import org.ametys.runtime.i18n.I18nizableText; 022 023/** 024 * This interface describes a console data, variables and functions. 025 * Each implementation of this interface will enhance the console, by providing additional variables and functions that can be used in scripts. 026 */ 027public interface ScriptBinding 028{ 029 /** 030 * Return the pattern of the workspace corresponding to this script binding. 031 * @return The pattern to match 032 */ 033 public Pattern getWorkspacePattern(); 034 035 /** 036 * Returns the list of variables this ScriptBinding provides, mapped by variable name. 037 * @param execArgs The The arguments for script execution 038 * @return The list of variables, or null if no variable is provided. 039 */ 040 public Map<String, Object> getVariables(ScriptExecArguments execArgs); 041 042 043 /** 044 * Returns the JavaScript variables script to inject at the start of the script, in the form of a single String prepended to the script. 045 * @return The functions text, or null if no function is provided. 046 */ 047 public String getVariablesScripts(); 048 049 /** 050 * Returns the list of variables descriptions, mapped by variable name. 051 * This list does not have to match the getVariables return value, but the description is used to inform the user of the existence and usability of each variable. 052 * @return The list of variables descriptions, or null if no description is provided. 053 */ 054 public Map<String, ScriptBindingDocumentation> getVariablesDescriptions(); 055 056 /** 057 * Allows clean up of variables created during the getVariables call. 058 * @param variables The map of variables. 059 */ 060 public void cleanVariables(Map<String, Object> variables); 061 062 /** 063 * Returns the JavaScript functions to inject at the start of the script, in the form of a single String prepended to the script. 064 * @return The functions text, or null if no function is provided. 065 */ 066 public String getFunctions(); 067 068 /** 069 * Returns the list of functions descriptions, mapped by function name. 070 * This list does not have to match the functions returned by getFunctions, but the description is used to inform the user of the existence and usability of each function. 071 * @return The list of functions descriptions, or null if no description is provided. 072 */ 073 public Map<String, ScriptBindingDocumentation> getFunctionsDescriptions(); 074 075 /** 076 * Returns the list of tutorials 077 * @return The list of tutorials, or null if no tutorial is provided. 078 */ 079 public Map<I18nizableText, ScriptBindingDocumentation> getTutorials(); 080}