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.HashMap;
019import java.util.Map;
020
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023
024import org.ametys.runtime.i18n.I18nizableText;
025
026import com.google.common.collect.ImmutableMap;
027
028/**
029 * Runtime default script binding, provides default variables to the script tool, and a configuration file for the functions. 
030 */
031public class RuntimeScriptBinding extends StaticConfigurableScriptBinding
032{
033    private ServiceManager _manager;
034
035    @Override
036    public void service(ServiceManager manager) throws ServiceException
037    {
038        super.service(manager);
039
040        _manager = manager;
041    }
042    
043    @Override
044    public Map<String, Object> getVariables()
045    {
046        Map<String, Object> variables = new HashMap<>();
047        variables.put("serviceManager", _manager);
048        variables.put("sourceResolver", _sourceResolver);
049        variables.put("avalonContext", _context);
050        return variables;
051    }
052    
053    @Override
054    public Map<String, I18nizableText> getVariablesDescriptions()
055    {
056        return ImmutableMap.of("serviceManager", new I18nizableText("plugin.core-ui", "PLUGINS_CORE_UI_SCRIPT_VAR_SERVICEMANAGER"),
057                               "sourceResolver", new I18nizableText("plugin.core-ui", "PLUGINS_CORE_UI_SCRIPT_VAR_RESOLVER"),
058                               "avalonContext", new I18nizableText("plugin.core-ui", "PLUGINS_CORE_UI_SCRIPT_VAR_AVALONCONTEXT"));
059    }
060
061}