    001package com.hammurapi.common;
    002
    003import javax.script.*;
    004import java.util.List;
    005import java.util.Arrays;
    006
    007public class TokenExpanderScriptEngineFactory implements javax.script.ScriptEngineFactory {
    008        final List<String> extensions = Arrays.asList("token", "txt");
    009
    010        final List<String> mimeTypes = Arrays.asList("application/x-token-expander");
    011
    012        final List<String> names = Arrays.asList("tokenexpander");
    013
    014        public String getEngineName() {
    015                return "Token Expander Engine";
    016        }
    017
    018        public String getEngineVersion() {
    019                return "1.0";
    020        }
    021
    022        public List<String> getExtensions() {
    023                return extensions;
    024        }
    025
    026        public List<String> getMimeTypes() {
    027                return mimeTypes;
    028        }
    029
    030        public List<String> getNames() {
    031                return names;
    032        }
    033
    034        public String getLanguageName() {
    035                return "TokenExpander";
    036        }
    037
    038        public String getLanguageVersion() {
    039                return "1.0";
    040        }
    041
    042        public Object getParameter(String param) {
    043                if (param.equals(ScriptEngine.ENGINE))
    044                        return getEngineName();
    045                if (param.equals(ScriptEngine.ENGINE_VERSION))
    046                        return getEngineVersion();
    047                if (param.equals(ScriptEngine.NAME))
    048                        return getEngineName();
    049                if (param.equals(ScriptEngine.LANGUAGE))
    050                        return getLanguageName();
    051                if (param.equals(ScriptEngine.LANGUAGE_VERSION))
    052                        return getLanguageVersion();
    053                if (param.equals("THREADING"))
    054                        return "MULTITHREADED";
    055
    056                return null;
    057        }
    058
    059        public String getMethodCallSyntax(String objectName, String methodName, String... args) {
    060                return null;
    061        }
    062
    063        public String getOutputStatement(String message) {
    064                return null;
    065        }
    066
    067        public String getProgram(String... statements) {
    068                StringBuilder sb = new StringBuilder();
    069                for (int i = 0; i < statements.length; i++) {
    070                        sb.append(statements[i]);
    071                }
    072                return sb.toString();
    073        }
    074
    075        public ScriptEngine getScriptEngine() {
    076                return new TokenExpanderScriptEngine();
    077        }
    078
    079        // End impl ScriptEngineFactory
    080}