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