Subversion Repositories pub

Compare Revisions

No changes between revisions

Ignore whitespace Rev 56 → Rev 57

/pluggablejs/tags/1.0build28/samples/RhinoRun.java
0,0 → 1,54
 
// This file is put in the Public Domain, originally published
// at <http://p.outlyer.net./javacode/>
// $Id$
 
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
 
/**
* This is a wrapper around the rhino script engine, it will load a file
* and try to eval() its contents.
*
* Usage: RhinoRun [inputfile.js] [inputfile2.js]
*/
public class RhinoRun {
public static void main(String...args) {
if (args.length == 0) {
System.err.printf("Usage: java [...] %s [file1.js [file2.js [...]]]\n",
RhinoRun.class.getName());
System.exit(1);
}
 
final ScriptEngine rhino = new ScriptEngineManager().getEngineByName("rhino");
 
for (final String path : args) {
try {
final File file = new File(path);
if (!file.isFile() || !file.canRead()) {
throw new FileNotFoundException("Failed to access " + path);
}
rhino.eval(new BufferedReader(new FileReader(file)));
}
catch (final FileNotFoundException e) {
System.err.println("Error: " + e.getMessage());
if (System.getProperty("debug", "0").equals("1")) {
e.printStackTrace(System.err);
}
}
catch (final ScriptException e) {
System.err.println("Error: " + e.getMessage());
if (System.getProperty("debug", "0").equals("1")) {
e.printStackTrace(System.err);
}
}
}
}
}
 
// vim:set ts=4 et ai: //
Property changes:
Added: svn:keywords
+Rev Id Date
\ No newline at end of property