System Functions

System functions are an integral part of the many features of JudoScript language.

NameArgumentsDescriptionExamples
acceptHttp
serverSocket

Accepts a connection from the serverSocket and returns a HttpService object for a HTTP connection.

 
addMimeType
ext
value

Sets the mime type for file extension ext to value.

 
antcall
target
...
This function is only valid within embedded code inside Ant build scripts. It runs the named Ant targets of the enclosing Ant build script.  
assert
boolExpr
Takes a boolean expression and, if assertion is on (see setAssert()), evaluates the expression. If the result is false , throws an assertion exception.  
compare
left
right
Returns 1, 0 or -1 by comparing left to right as numerical or java.lang.Comparable values.  
connectMailServer
host
username
password
Connects to the mail server referenced by host. Only one mail server connection is allowed in a program. Once done with sending mails, should call disconnectMailServer().  
convertToVariables
map
isLocal
This function takes a map which is either Object or a java.util.Map, and converts all the data elements into variables in the current scope. If isLocal is specified and is true , local variables are created; otherwise, normal scoping rules decide where the variables are.  
cookie
name
value

Creates and returns a cookie object for name with value.

 
copyStream
copyStreams
input
output
closeStreams

Copies all the bytes from input stream to the output. Closes both streams if closeStreams is true . The input can be a file, a URL or an open stream (such as of a open HTTPConnection. The output can be a file name or any open output stream. It can be omitted, in which case the system standard output stream is used.

 
crc32
src
offset
length
prevCrc
Returns the CRC32 value of the source. The src can be an input stream, a java.io.File of a string as file name, in which case only one parameter is allowed. It can also be a byte array, and offset, length and prevCrc may apply.  
createCOMObject
createActiveXComponent
id

Returns a Microsoft COM IDispatch instance. The parameter can be a program ID such as "Word.Application", or a class ID in the form of "{FB7FDAE2-89B8-11CF-9BE8-00A0C90A632C}".

The returned object's methods can be called directly like any regular object methods (that is, without using the IDispatch interface method invoke()), and its properties can be set and got like any regular object data members.

This feature requires JCom support, which is only available on Wintel platforms. JCom 2.2.3 is included in JudoScript, and make sure that jcom.dll is in the path. (If you download a newer version of JCom, make sure the new jcom.dll is before JudoScript's in the PATH environment variable, and its jcom.jar is before judo.jar in the CLASSPATH.)

 
createDom
  Returns a new, empty DOMDoc object.  
createJar
jarFileName
manifest
Returns an open ZipArchive for the jarFileName. The manifest is optional; if present, is the content of the manifest file put in the jar file.  
createTar
tarFileName
Returns an open TarArchive for the tarFileName.  
createZip
zipFileName
Returns an open ZipArchive for the zipFileName.  
date
year
month
day
hour
minute
second
Creates a date value with the provided attributes. These attributes, if omitted, are defaulted to 0 or 1 except for year; if no parameters specified, creates a date for the current time.  
decrypt
password
input

The input is a byte array. This function uses a password-based encryptor class to decrypt the input byte array and returns the result as a byte array.

 
decryptFile
 

Decrypts the inputFile with the password using an encryptor class and writes the result into the outputFile.

 
disconnectMailServer
  Disconnects the one and only mail server connection. If the mail server connection was not open, no effect.  
encode
input
encoding
Takes an input, which can be a string or a byte array, and returns a string encoded with encoding. If encoding is omitted, use the default text encoding scheme. Base-64 encoding is support as encoding being "base64".  
encrypt
password
input

The input is a byte array. This function uses a password-based encryptor class to encrypt the input byte array and returns the result as a byte array.

 
encryptFile
password
inputFile
outputFile

Encrypts the inputFile with the password using an encryptor class and writes the result into the outputFile.

 
escapeHtml
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
escapeJava
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
escapeJavaScript
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
escapeSql
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
escapeXml
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
exit
exitValue
Exits the current session, optionally with exitValue (default is 0). Note this is not the same as calling java.lang.System.exit().  
fileChop
fileName
[baseName]
subFileSize

This utility function takes a (big) file fileName and generates a number of smaller files of the size subFileSize. The new files have baseName plus "." and incremented indices starting from 1. If basename is missing, the default base name is the same as fileName.

The subFileSize can be a number or a string such as "floppy" (for the size of a 1.44M floppy diskette), "zip100" or "zip250" for 100M/250M ZIP drive, or "CD" (for a 650M CD-ROM). It can also be a number followed by "M" or "m" (for megabytes) or "K" or "k" (for kilobytes). The number must be integer. If no subFileSize specified, default size is for floppy diskettes.

This function returns an integer array of all the sub-file sizes. Typically the last one is different than the others.

See fileUnchop() and fileChopCheck().

 
fileChopCheck
fileName
subFileSize

This utility function works with fileChop(). It returns an integer array for the sub-file sizes if the input file is to be chopped. The parameters are the same as in fileChop().

 
fileUnchop
baseName
outfileName

This utility function does the reverse of fileChop(): it goes through a series of files that starts with the baseName followed by "." and incremented indices, and assembles them into the output file. If outfileName is not empty, it is used for the output file name, otherwise defaulted to baseName.

See fileChop() and fileChopCheck().

 
getApacheContext
apacheContext
url
username
password
Returns a javax.naming.InitialContext for a WebSphere application server context. It is a shortcut for getInitialContext() with the first parameter being "org.apache.naming.java.javaURLContextFactory". This is typically used on Tomcat.  
getCharset
 

Returns the current character of the system. Default character set is used by SendMailStatement.

See setCharset().

 
getDefaultDateFormat
defaultDateFormat
  Returns the default date format as a string.  
getEnvVar
getenv
varName
Returns the environment variable value for varName of the current JVM process.  
getEnvVars
getenvs
  Returns a java.util.Properties that all the environment variable values of the current JVM process. The java.util.Properties's values can be updated, and the next call to getEnvVars() will return this modified one.  
getErr
  Returns the current system error output.  
getFileAsBytes
fileName
limit
encoding

Returns a byte array that is the content of the file fileName. limit and encoding are optional.

 
getFileAsBytesFromCP
fileName

Returns a byte array that is the content of the file fileName which resides somewhere on the classpath.

 
getFileAsString
fileName
limit
encoding

Returns a string that is the content of the file fileName. limit and encoding are optional.

 
getFileAsStringFromCP
fileName
limit
encoding

Returns a string that is the content of the file fileName which resides somewhere on the classpath. limit and encoding are optional.

 
getFunctions
namePattern
Returns a string array of the function names defined in the system that match namePattern. If namePattern is null , returns all the names.  
getGZipFileAsBytes
gzipName

Returns a byte array that is the content of the GZipped file gzipName.

 
getGZipFileAsString
gzipName
limit
encoding

Returns a string that is the content of the GZipped file gzipName. limit and encoding are optional.

 
getGuiHandler
guiHandler
timerHandler
 

In a JudoScript GUI program, there is only one Java ActionListener object; it receives and dispatches all the GUI events to user-defined event handlers, which may be defined in multiple GuiEventsStatement statements. This statement actually returns this Java ActionListener.

This function is most useful for javax.swing.Timer's constructor, which takes a java.awt.event.ActionListener as its second parameter.

 
getHttpResponseMsg
code

Returns a short message that corresponds to the HTTP response code.

 
getIn
  Returns the current system standard input.  
getInStream
  Returns the current system standard binary input stream.  
getInitialContext
initialContext
factory
url
username
password

Returns a javax.naming.InitialContext for the initial context factory class name and the other parameters.

Also see getWeblogicContext(), getWebsphereContext(), getOracle9iASContext(), getJBossContext() and getIonaContext().

 
getIonaContext
ionaContext
url
username
password
Returns a javax.naming.InitialContext for an IONA application server context. It is a shortcut for getInitialContext() with the first parameter being "com.ejbhome.nameing.spi.rmi.RMIInitCtxFactory".  
getJBossContext
jbossContext
url
username
password
Returns a javax.naming.InitialContext for a JBoss application server context. It is a shortcut for getInitialContext() with the first parameter being "org.jnp.interfaces.NamingContextFactory".  
getLog
  Returns the current system logger output.  
getMimeTypeMap
 

Returns a java.util.Hashtable that contains all the mime type mapping currently used by the HTTPConnection. The mapping maps file extensions to mime types.

 
getOracle9iASContext
oracle9iASContext
url
username
password
Returns a javax.naming.InitialContext for an Oracle 9iAS application server context. It is a shortcut for getInitialContext() with the first parameter being "com.evermind.server.rmi.RMIInitialContextFactory".  
getOut
  Returns the current system standard output.  
getOutStream
  Returns the current system standard binary output stream.  
getSunContext
sunContext
url
username
password
Returns a javax.naming.InitialContext for a Sun One application server context. It is a shortcut for getInitialContext() with the first parameter being "com.sun.jndi.cosnaming.CNCtxFactory".  
getThreads
namePattern
Returns a string array of the thread names defined in the system that match namePattern. If namePattern is null , returns all the names.  
getVariable
name
Returns the named variable.  
getWeblogicContext
weblogicContext
url
username
password
Returns a javax.naming.InitialContext for a WebLogic application server context. It is a shortcut for getInitialContext() with the first parameter being "weblogic.jndi.WLInitialContextFactory".  
getWebsphereContext
websphereContext
url
username
password
Returns a javax.naming.InitialContext for a WebSphere application server context. It is a shortcut for getInitialContext() with the first parameter being "com.ibm.websphere.naming.WsnInitialContextFactory".  
getWindowsRegistry
  Returns a Java object of com.ice.jni.registry.Registry, for manipulating Windows registry. The JNI Windows Registry library by Tim Endre must be installed.  
httpGet
url

Issues a HTTP GET request to the url. Returns a HTTPConnection object.

 
httpPost
url

Issues a HTTP POST request to the url. Returns a HTTPConnection object.

 
isHP
  Returns true if the system property for "os.name" contains "HP-UX".  
isLinux
  Returns true if the system property for "os.name" contains "Linux".  
isMac
  Returns true if the system property for "os.name" contains "Mac".  
isNetscape
  Returns true if the system property for "java.vendor" contains "Netscape".  
isNewer
file1
file2
Compares the two files based on their time stamps. Also handles the cases where one of the files does not exist. Returns true if file file1 is newer than file file2.  
isOS400
isAS400
  Returns true if the system property for "os.name" contains "/400".  
isSunOS
  Returns true if the system property for "os.name" contains "SunOS".  
isSunVendor
  Returns true if the system property for "java.vendor" contains "Sun".  
isUnix
  Returns true if the system property for "os.name" does not contain "/400", and java.io.File.pathSeparatorChar is ":" and java.io.File.separatorChar is "/".  
isWindows
  Returns true if the system property for "os.name" contains "Windows".  
javaVendor
  Returns the system property for "java.vendor".  
loadProperties
propsFile
Returns a java.util.Properties that holds the property values of the propsFile.  
lock
lockName

Locks are used to protect shared resources among multiple threads. They reside only in the root context, so that all threads have access to. A lock is simply represented by a name, lockName. If a lock is already acquired by one thread, another thread requesting the same lock will wait, until the unlock() is called by the holding thread.

 
loopIndex
level
This is only used in loops. Typically level is not specified, and this function returns the loop index; the index for the first iteration is 0. For embedded loops, -1 denotes the outer loop's index, -2 denotes the second outer loop's, and so on.  
max
value1
...
Returns the greatest numeric value among all the parameters.  
min
value1
...
Returns the smallest numeric value among all the parameters.  
neverEmpty
value
default_value
If the value is empty, that is, null or only containing whitespace characters, returns the default_value, which is required. Otherwise, returns the original value.  
neverNull
value
default_value
If the value is null , returns the default_value; if not default_value specified, return ''. Otherwise, returns the original value.  
notify
signalName

Sends out a signal of signalName for the threads waiting for it (see waitFor()). One of the waiting threads will be awakened.

 
notifyAll
signalName

Sends out a signal of signalName for the threads waiting for it (see waitFor()). All of the waiting threads will be awakened.

See notify().

 
obtainUsage
scriptName
Returns the usage block (a Hashtable) of the script scriptName, if it has one; otherwise, returns null . See UsageDeclaration.  
openFile
file_name
mode
Opens a binary file for file_name; mode can be 'r' for read (default), 'w' (for write) or 'a' (for append). Returns an IODevice.  
openGZippedFile
file_name
mode
Opens a GZipped binary file for file_name; mode can be 'r' for read (default), 'w' (for write) or 'a' (for append). Returns an IODevice.  
openGZippedTextFile
file_name
mode
encoding
Opens a GZipped text file for file_name; mode can be 'r' for read (default), 'w' (for write) or 'a' (for append); encoding is the text encoding, default is to use the JVM's current text encoding. Returns an IODevice.  
openRandomAccessFile
file_name
mode
encoding
Opens a random-access binary file for file_name; mode can be 'r' for read (default), 'w' (for write) or 'rw' (for read/write). Returns an IODevice.  
openTableDump
fileName
Opens the file as a table dump and returns a TableDump object.  
openTextFile
file_name
mode
encoding
Opens a text file for file_name; mode can be 'r' for read (default), 'w' (for write) or 'a' (for append); encoding is the text encoding, default is to use the JVM's current text encoding. Returns an IODevice.  
openZip
file_name
Opens a zip or jar file for file_name.  
rand
random
[lower]
upper

If no parameters, it returns a random between 0.0 and 1.0.

If lower is missing, it is defaulted to 0 or 0.0. If lower is present and is an integer, this function will return a uniformly distributed random number between lower and upper; if lower is a floating-point, the result is a float as well. If lower is not present, the return type is the same as upper.

 
readLine
  Returns a string by reading from the system input. It can return eof .  
resourceBundle
resourceName

Returns a java.util.ResourceBundle for resourceName.

 
saveProperties
properties
propsFile
head
Saves properties into propsFile. It cleans up the content first.  
secret
encryptedValue
cryptoAgent

This is a special-type value Secret that can be only used by certain system functions and statements. It is not accesible by regular print statements or string operations.

The cryptoAgent is a Java crypto class. If not present, the encryptedValue is used verbatim (no encryption).

 
setAssert
setAssertion
  Turns on or off the assertion. See assert().  
setCharset
charset

Sets the current character set to charset for the system. Default character set is used by MailStatement.

 
setDefaultDateFormat
format
Sets the default date format.  
setErr
textOutput
Sets the current system error output. The very original one is reserved and can be restored by calling this function without the parameter.  
setGuiListener
handlerName
comp1
...

This function is used in conjunction with GuiEventsStatement's generic handler feature. A generic handler is a named handler that is not bound to any specific GUI component.

The first parameter handlerName is that for the handler name. The following parameters are one or more GUI components to add the handler to.

 
setHttpProxy
host
port

If no host and port specified, put "false" into the system property "http.proxySet".

Otherwise, set the system property "http.proxySet" to "true" as well as those for "http.proxyHost" and "http.proxyPort". The port can be omitted, which will be defaulted to 80.

 
setIn
inputFile
Sets the input stream to the input file inputFile. The very original one is reserved and can be restored by calling this function without the parameter.  
setLog
textOutput
Sets the current system logger output. The very original one is reserved and can be restored by calling this function wihout the parameter.  
setOut
textOutput
Sets the current system standard output. The very original one is reserved and can be restored by calling this function without the parameter.  
setVariable
name
value
isLocal
Creates a variable with name. If isLocal is specified and is true , local variables are created; otherwise, normal scoping rules decide where the variables are.  
sleep
duration
Forces the current thread to sleep for duration milliseconds. If no duration specified, sleep forever.  
ssh
host
username
password
cipher
Starts a connection to host with the username and password. The cipher can be omitted or null . The host may include a port number separated by colon ":"; default port is 22. Returns a SSHConnection object.  
startServer
port
address
backlog

Starts and returns a java.net.ServerSocket for the given port, and optionally the bind address (a string or a java.net.InetAddress) and backlog.

 
thisFile
  Returns the current source file name.  
thisLine
  Returns the current line number in the script, relative to the current source file (see thisFile()).  
time
hour
minute
second
Creates a date value with the provided attribute. The year/month/day values are 0.  
timeToday
hour
minute
second
Creates a date value for today but with the provided hour, minute and second.  
unescapeHtml
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
unescapeJava
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
unescapeJavaScript
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
unescapeXml
str
The same as the name-sake method in org.apache.commons.lang.StringEscapeUtils.  
unit
count
nameSingular
namePlural
This is a convenience function returning a string that displays the number of count followed by the namd in correct English. If namePlural is omitted, when number is not 1, an 's' is append to nameSingular. If namePlural is present, then it is used if count is not 1.  
unlock
lockName

See lock().

 
waitFor
signalName

Signals are used to synchronize different threads. A signal is just a name signalName. See notify() and notifyAll().