/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* jrunscript JavaScript built-in functions and objects.
*/
/**
* Creates an object that delegates all method calls on
* it to the 'invoke' method on the given delegate object.<br>
*
* Example:
* <pre>
* <code>
* var x = { invoke: function(name, args) { //code...}
* var y = new JSInvoker(x);
* y.func(3, 3); // calls x.invoke('func', args); where args is array of arguments
* </code>
* </pre>
* @param obj object to be wrapped by JSInvoker
* @constructor
*/
return new JSAdapter({
return function() {
}
}
});
}
/**
* This variable represents OS environment. Environment
* variables can be accessed as fields of this object. For
* example, env.PATH will return PATH value configured.
*/
},
},
__getIds__ : function() {
},
__delete__ : function(name) {
println("can't delete env item");
},
println("can't change env item");
},
toString: function() {
}
});
/**
* Creates a convenient script object to deal with java.util.Map instances.
* The result script object's field names are keys of the Map. For example,
* scriptObj.keyName can be used to access value associated with given key.<br>
* Example:
* <pre>
* <code>
* var x = java.lang.SystemProperties();
* var y = jmap(x);
* println(y['java.class.path']); // prints java.class.path System property
* delete y['java.class.path']; // remove java.class.path System property
* </code>
* </pre>
*
* @param map java.util.Map instance that will be wrapped
* @constructor
*/
return new JSAdapter({
} else {
return undefined;
}
},
},
__delete__ : function (name) {
},
},
__getIds__ : function() {
},
toString: function() {
}
});
}
/**
* Creates a convenient script object to deal with java.util.List instances.
* The result script object behaves like an array. For example,
* scriptObj[index] syntax can be used to access values in the List instance.
* 'length' field gives size of the List. <br>
*
* Example:
* <pre>
* <code>
* var x = new java.util.ArrayList(4);
* x.add('Java');
* x.add('JavaScript');
* x.add('SQL');
* x.add('XML');
*
* var y = jlist(x);
* println(y[2]); // prints third element of list
* println(y.length); // prints size of the list
*
* @param map java.util.List instance that will be wrapped
* @constructor
*/
return typeof(index) == 'number' &&
}
return new JSAdapter({
} else if (name == 'length') {
} else {
return undefined;
}
},
},
__delete__ : function(name) {
}
},
}
},
__getIds__: function() {
res[i] = i;
}
return res;
},
toString: function() {
}
});
}
/**
* This is java.lang.System properties wrapped by jmap.
* For eg. to access java.class.path property, you can use
* the syntax sysProps["java.class.path"]
*/
// stdout, stderr & stdin
// can't use 'in' because it is a JavaScript keyword :-(
// useful imports for often used io, net classes
/**
* Generic any object to input stream mapper
* @param str input file name, URL or InputStream
* @return InputStream object
* @private
*/
if (typeof(str) == "string") {
// '-' means standard input
if (str == '-') {
}
// try file first
var file = null;
try {
} catch (e) {
}
return new FileInputStream(file);
} else {
try {
// treat the string as URL
} catch (e) {
}
}
} else {
if (str instanceof InputStream) {
return str;
return str.openStream();
return new FileInputStream(str);
}
}
// everything failed, just give input stream
}
/**
* Generic any object to output stream mapper
*
* @param out output file name or stream
* @return OutputStream object
* @private
*/
if (typeof(out) == "string") {
if (out == '>') {
} else {
// treat it as file
}
} else {
if (out instanceof OutputStream) {
return out;
return new FileOutputStream(out);
}
}
// everything failed, just return System.out
}
/**
* stream close takes care not to close stdin, out & err.
* @private
*/
if (stream) {
try {
} catch (e) {
println(e);
}
}
}
}
/**
* Loads and evaluates JavaScript code from a stream or file or URL<br>
*
* Examples:
* <pre>
* <code>
* load('http://java.sun.com/foo.js'); // load from a URL
* </code>
* </pre>
*
* @param str input from which script is loaded and evaluated
*/
try {
} finally {
}
}
// file system utilities
/**
* Creates a Java byte[] of given length
* @param len size of the array to create
* @private
*/
}
/**
* Print present working directory
*/
function pwd() {
}
/**
* Changes present working directory to given directory
* @param target directory to change to. optional, defaults to user's HOME
*/
}
}
} else {
}
}
/**
* Converts path to java.io.File taking care of shell present working dir
*
* @param pathname file path to be converted
* @private
*/
}
if (!tmp.isAbsolute()) {
} else {
return tmp;
}
}
/**
* Copies a file or URL or stream to another file or stream
*
* @param from input file or URL or stream
* @param to output stream or file
*/
return;
}
var len;
}
/**
* Shows the content of a file or URL or any InputStream<br>
* Examples:
* <pre>
* <code>
* cat('http://java.net'); // show the contents from the URL http://java.net
* </code>
* </pre>
* @param obj input to show
* @param pattern optional. show only the lines matching the pattern
*/
return;
}
var inp = null;
}
var line;
if (pattern) {
var count = 1;
}
count++;
}
} else {
}
}
}
/**
* Returns directory part of a filename
*
* @param pathname input path name
* @return directory part of the given file name
*/
var dirName = ".";
// Normalize '/' to local file separator before work.
if ( i != -1 )
return dirName;
}
/**
* Creates a new dir of given name
*
* @param dir name of the new directory
*/
}
/**
* Creates the directory named by given pathname, including
* any necessary but nonexistent parent directories.
*
* @param dir input path name
*/
}
/**
* Removes a given file
*
* @param pathname name of the file
*/
return false;
}
// note that delete is a keyword in JavaScript!
}
/**
* Removes a given directory
*
* @param pathname name of the directory
*/
}
/**
* Synonym for 'rm'
*/
}
/**
* Moves a file to another
*
* @param from original name of the file
* @param to new name for the file
*/
"moved" : "can not move");
}
/**
* Synonym for 'mv'.
*/
}
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
/**
* Helper function called by ls
* @private
*/
function printFile(f) {
c.setTime(d);
+ " " + day );
if (day < 10) {
}
// to get fixed length 'length' field
var fieldlen = 8;
for(var j=0; j<fieldlen; j++)
// move the spaces to the front
if ( si != -1 ) {
}
if (f.isDirectory()) {
}
}
/**
* Lists the files in a directory
*
* @param dir directory from which to list the files. optional, default to pwd
* @param filter pattern to filter the files listed. optional, default is '.'.
*/
if (dir) {
} else {
}
if (dir.isDirectory()) {
for (var i in files) {
var f = files[i];
if (filter) {
continue;
}
}
printFile(f);
}
} else {
}
}
/**
* Synonym for 'ls'.
*/
}
/**
* Unix-like grep, but accepts JavaScript regex patterns
*
* @param pattern to search in files
* @param files one or more files
*/
}
}
/**
* Find in files. Calls arbitrary callback function
* for each matching file.<br>
*
* Examples:
* <pre>
* <code>
* find('.')
* find('.', '.*\.class', rm); // remove all .class files
* find('.', '.*\.java'); // print fullpath of each .java file
* find('.', '.*\.java', cat); // print all .java files
* </code>
* </pre>
*
* @param dir directory to search files
* @param pattern to search in the files
* @param callback function to call for matching files
*/
for (var f in files) {
if (file.isDirectory()) {
} else {
if (pattern) {
}
} else {
}
}
}
}
// process utilities
/**
* Exec's a child process, waits for completion & returns exit code
*
* @param cmd command to execute in child process
*/
var line = null;
}
}
/**
* Exit the shell program.
*
* @param exitCode integer code returned to OS shell.
* optional, defaults to 0
*/
if (code) {
} else {
}
}
/**
* synonym for exit
*/
}
// XML utilities
/**
* Converts input to DOM Document object
*
* @param inp file or reader. optional, without this param,
* this function returns a new DOM Document.
* @return returns a DOM Document object
*/
if (inp) {
if (typeof(inp) == "string") {
} else {
}
} else {
return builder.newDocument();
}
}
/**
* Converts arbitrary stream, file, URL to XMLSource
*
* @param inp input stream or file or URL
* @return XMLSource object
*/
return inp;
} else {
}
}
/**
* Converts arbitrary stream, file to XMLResult
*
* @param inp output stream or file
* @return XMLResult object
*/
return out;
} else {
}
}
/**
* Perform XSLT transform
*
* @param inp Input XML to transform (URL, File or InputStream)
* @param style XSL Stylesheet to be used (URL, File or InputStream). optional.
* @param out Output XML (File or OutputStream
*/
case 2:
break;
case 3:
break;
default:
println("XSL tranform requires 2 or 3 arguments");
return;
}
var tranformer;
if (style) {
} else {
}
if (source.getInputStream) {
}
if (result.getOutputStream) {
}
}
// miscellaneous utilities
/**
* Prints which command is selected from PATH
*
* @param cmd name of the command searched from PATH
*/
while (st.hasMoreTokens()) {
return;
}
}
}
/**
* Prints IP addresses of given domain name
*
* @param name domain name
*/
for (var i in addrs) {
}
}
/**
* Prints current date in current locale
*/
function date() {
println(new Date().toLocaleString());
}
/**
* Echoes the given string arguments
*/
function echo(x) {
}
}
/**
* This is C-like printf
*
* @param format string to format the rest of the print items
* @param args variadic argument list
*/
}
}
/**
* Reads one or more lines from stdin after printing prompt
*
* @param prompt optional, default is '>'
* @param multiline to tell whether to read single line or multiple lines
*/
if (!prompt) {
prompt = '>';
}
if (multiline) {
var line = '';
while (true) {
}
return line;
} else {
}
}