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 javax.script.ScriptException; 022 023import org.ametys.runtime.i18n.I18nizableText; 024 025/** 026 * This interface describes a console data, variables and functions. 027 * Each implementation of this interface will enhance the console, by providing additional variables and functions that can be used in scripts. 028 */ 029public interface ScriptBinding 030{ 031 /** 032 * Return the pattern of the workspace corresponding to this script binding. 033 * @return The pattern to match 034 */ 035 public Pattern getWorkspacePattern(); 036 037 /** 038 * Returns the list of variables this ScriptBinding provides, mapped by variable name. 039 * @return The list of variables, or null if no variable is provided. 040 */ 041 public Map<String, Object> getVariables(); 042 043 /** 044 * Returns the list of variables descriptions, mapped by variable name. 045 * 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. 046 * @return The list of variables descriptions, or null if no description is provided. 047 */ 048 public Map<String, I18nizableText> getVariablesDescriptions(); 049 050 /** 051 * Allows clean up of variables created during the getVariables call. 052 * @param variables The map of variables. 053 */ 054 public void cleanVariables(Map<String, Object> variables); 055 056 /** 057 * Returns the JavaScript functions to inject at the start of the script, in the form of a single String prepended to the script. 058 * @return The functions text, or null if no function is provided. 059 */ 060 public String getFunctions(); 061 062 /** 063 * Returns the list of functions descriptions, mapped by function name. 064 * 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. 065 * @return The list of functions descriptions, or null if no description is provided. 066 */ 067 public Map<String, I18nizableText> getFunctionsDescriptions(); 068 069 /** 070 * Process the script result if there are any specificities for this console data. 071 * @param result The result 072 * @return The result processed, or null if this console data does not have any processing to do. 073 * @throws ScriptException If a processing error occurs. 074 */ 075 public Object processScriptResult(Object result) throws ScriptException; 076}