package com.hammurapi.common;

import javax.script.*;
import java.util.List;
import java.util.Arrays;

/**
 * HTML script engine factory used TokenExpander engine to expands tokens in HTML.
 * @author Pavel
 *
 */
public class HtmlScriptEngineFactory implements javax.script.ScriptEngineFactory {
	final List<String> extensions = Arrays.asList("html", "htm");

	final List<String> mimeTypes = Arrays.asList("text/html");

	final List<String> names = Arrays.asList("HTML");

	public String getEngineName() {
		return "HTML with token expansion";
	}

	public String getEngineVersion() {
		return "1.0";
	}

	public List<String> getExtensions() {
		return extensions;
	}

	public List<String> getMimeTypes() {
		return mimeTypes;
	}

	public List<String> getNames() {
		return names;
	}

	public String getLanguageName() {
		return "HTML";
	}

	public String getLanguageVersion() {
		return "4.1";
	}

	public Object getParameter(String param) {
		if (param.equals(ScriptEngine.ENGINE))
			return getEngineName();
		if (param.equals(ScriptEngine.ENGINE_VERSION))
			return getEngineVersion();
		if (param.equals(ScriptEngine.NAME))
			return getEngineName();
		if (param.equals(ScriptEngine.LANGUAGE))
			return getLanguageName();
		if (param.equals(ScriptEngine.LANGUAGE_VERSION))
			return getLanguageVersion();
		if (param.equals("THREADING"))
			return "MULTITHREADED";

		return null;
	}

	public String getMethodCallSyntax(String objectName, String methodName,	String... args) {
		return null;
	}

	public String getOutputStatement(String message) {
		return null;
	}

	public String getProgram(String... statements) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < statements.length; i++) {
			sb.append(statements[i]);
		}
		return sb.toString();
	}

	public ScriptEngine getScriptEngine() {
		return new TokenExpanderScriptEngine();
	}
}
