package com.sun.script.javascript;
import javax.script.*;
import java.util.*;
import sun.org.mozilla.javascript.internal.*;
import com.sun.script.util.*;
public class RhinoScriptEngineFactory extends ScriptEngineFactoryBase {
public RhinoScriptEngineFactory() {
}
public List<String> getExtensions() {
return extensions;
}
public List<String> getMimeTypes() {
return mimeTypes;
}
public List<String> getNames() {
return names;
}
public Object getParameter(String key) {
if (key.equals(ScriptEngine.NAME)) {
return "javascript";
} else if (key.equals(ScriptEngine.ENGINE)) {
return "Mozilla Rhino";
} else if (key.equals(ScriptEngine.ENGINE_VERSION)) {
return "1.7 release 3 PRERELEASE";
} else if (key.equals(ScriptEngine.LANGUAGE)) {
return "ECMAScript";
} else if (key.equals(ScriptEngine.LANGUAGE_VERSION)) {
return "1.8";
} else if (key.equals("THREADING")) {
return "MULTITHREADED";
} else {
throw new IllegalArgumentException("Invalid key");
}
}
public ScriptEngine getScriptEngine() {
RhinoScriptEngine ret = new RhinoScriptEngine();
ret.setEngineFactory(this);
return ret;
}
public String getMethodCallSyntax(String obj, String method, String... args) {
String ret = obj + "." + method + "(";
int len = args.length;
if (len == 0) {
ret += ")";
return ret;
}
for (int i = 0; i < len; i++) {
ret += args[i];
if (i != len - 1) {
ret += ",";
} else {
ret += ")";
}
}
return ret;
}
public String getOutputStatement(String toDisplay) {
StringBuffer buf = new StringBuffer();
int len = toDisplay.length();
buf.append("print(\"");
for (int i = 0; i < len; i++) {
char ch = toDisplay.charAt(i);
switch (ch) {
case '"':
buf.append("\\\"");
break;
case '\\':
buf.append("\\\\");
break;
default:
buf.append(ch);
break;
}
}
buf.append("\")");
return buf.toString();
}
public String getProgram(String... statements) {
int len = statements.length;
String ret = "";
for (int i = 0; i < len; i++) {
ret += statements[i] + ";";
}
return ret;
}
private static List<String> names;
private static List<String> mimeTypes;
private static List<String> extensions;
static {
names = new ArrayList<String>(6);
names.add("js");
names.add("rhino");
names.add("JavaScript");
names.add("javascript");
names.add("ECMAScript");
names.add("ecmascript");
names = Collections.unmodifiableList(names);
mimeTypes = new ArrayList<String>(4);
mimeTypes.add("application/javascript");
mimeTypes.add("application/ecmascript");
mimeTypes.add("text/javascript");
mimeTypes.add("text/ecmascript");
mimeTypes = Collections.unmodifiableList(mimeTypes);
extensions = new ArrayList<String>(1);
extensions.add("js");
extensions = Collections.unmodifiableList(extensions);
}
}