-
Notifications
You must be signed in to change notification settings - Fork 6
afbase
- af.compile
- af.compileToClasses
- af.cp
- af.create2FACredentials
- af.crypt
- af.decrypt
- af.e
- af.encrypt
- af.enl
- af.eval
- af.externalAddClasspath
- af.externalClass
- af.externalClassLoader
- af.externalPlugin
- af.fromArray2Bytes
- af.fromBase64
- af.fromBytes2Array
- af.fromBytes2InputStream
- af.fromBytes2OutputStream
- af.fromBytes2String
- af.fromInputStream2Bytes
- af.fromInputStream2String
- af.fromString2Bytes
- af.fromString2InputStream
- af.fromString2OutputStream
- af.fromXML
- af.get2FAToken
- af.getClass
- af.getDistribution
- af.getOpenAFJar
- af.getScopeIds
- af.getVersion
- af.js2s
- af.load
- af.loadRequire
- af.mkdir
- af.mv
- af.newOutputStream
- af.p
- af.plugin
- af.pnl
- af.rename
- af.restartOpenAF
- af.rm
- af.runFromClass
- af.sh
- af.showDebugger
- af.sleep
- af.sync
- af.toBase64Bytes
- af.validate2FA
af.compile(aScriptString, aSourceName) : ObjectCompiles the aScriptString executing it and returning the corresponding result. Optionally you can provide aSourceName.
af.compileToClasses(aClassfile, aScriptString, aPath)Given aClassfile name, aScriptString and, optionally, a filesystem aPath it will generate Java bytecode as result of compiling the aScriptString into a filesystem aClassfile (on the provided aPath). Example:
af.compileToClasses("SomeClass", "print('hello world!');", "/some/path")
af.cp(aSourceFilePath, aTargetFilePath)Tries to copy aSourceFilePath to aTargetFilePath preserving file attributes.
af.create2FACredentials(anAccountName, anIssuer) : MapGiven anAccountName and anIssuer will create a the 2FA/TOTP (Time-Based One-Time Password) returning a map with the scratchCodes, the verificationCode, the key, the openaf encryptedKey, the QR code URL and the OTP URL.
af.crypt(aKey, aSalt) : StringTries to mimic crypt(3) password encryption using the org.apache.commons.codec.digest.Crypt.crypt function. Please check https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/digest/Crypt.html for more.
af.decrypt(aString, aKey) : StringDecrypts the provided aString with the provided aKey.
af.e(aString)Outputs to stderr aString ending with a newline.
af.encrypt(aString, aKey) : StringEncrypts the provided aString as password for most of the OpenAF password functionality. If aKey is provided it will encrypt using it.
af.enl(aString)Outputs to stderr aString without a newline on the end.
af.eval(aScript) : ObjectPerforms the equivalent version of the javascript eval function for the provided aScript. Returns the corresponding result of the evaluation.
af.externalAddClasspath(aURL)Tries to add aURL to the current classpath. Don't forget that directories must end with a '/', for example: file:/my/own/dir/
Note: This might not work for some JVMs.
af.externalClass(anArrayOfClasspathEntries, aClassName) : JavaClassReturns an external Java class with the aClassName, not included in the initial OpenAF's classpath, loaded from a list of jars/folders in anArrayOfClasspathEntries.
af.externalClassLoader(anArrayOfClasspathEntries) : ClassLoaderReturns a ClassLoader suitable to be use with af.getClass to dynamically load Java classes that weren't included on the initial OpenAF's classpath and are included in the jars/folders provided in anArrayOfClasspathEntries.
af.externalPlugin(anArrayOfClasspathEntries, aPluginClass)Loads a OpenAF's plugin identified by the aPluginClass that isn't available in the initial OpenAF's classpath, loaded from a list of jars/folders in anArrayOfClasspathEntries.
af.fromArray2Bytes(anArray) : anArrayOfBytesConverts a javascript array of integers into a Java anArrayOfBytes.
af.fromBase64(aBase) : anArrayOfBytesGiven aBase as a string or an array of bytes will convert it to anArrayOfBytes in Base 64.
af.fromBytes2Array(anArrayOfBytes) : ArrayConverts a Java anArrayOfBytes into a javascript array of integers with the value representation of each byte.
af.fromBytes2InputStream(anArrayOfBytes) : StreamConverts anArrayOfBytes into a ByteArrayInputStream.
af.fromBytes2OutputStream(anArrayOfBytes) : StreamConverts anArrayOfBytes into a ByteArrayOutputStream. After using this stream you can, for example, use .toString and toByteArray methods from the resulting stream.
af.fromBytes2String(anArrayOfBytes) : aStringConverts anArrayOfBytes into a string.
af.fromInputStream2Bytes(aStream) : anArrayOfBytesaf.fromInputStream2String(aStream) : StringTries to convert an input aStream into a String.
af.fromString2Bytes(aString) : anArrayOfBytesConverts aString into anArrayOfBytes.
af.fromString2InputStream(aString) : StreamConverts aString into a ByteArrayInputStream.
af.fromString2OutputStream(aString) : StreamConverts aString into a ByteArrayOutputStream. After using this stream you can, for example, use .toString and toByteArray methods from the resulting stream.
af.fromXML(aXMLObject) : aStringConverts aXMLObject (E4X) into a String. Warning: beware that E4X is an obsolete object.
af.get2FAToken(aKey) : StringGiven 2FA aKey it will return the current token. Note: it will use the current date/time of the system so it must be in sync with the authenticator
af.getClass(aName, aLoader) : JavaClassReturns the JavaClass object the Java class identified by aName. Optionally you can provide a Java classloader ( this can be the result of using af.externalClassLoader).
af.getDistribution() : StringReturns the current OpenAF's distribution channel.
af.getOpenAFJar() : StringRetrives the fullpath for the OpenAF jar.
af.getScopeIds() : ArrayReturns an array of the current scope IDs.
af.getVersion() : StringReturns the current OpenAF's build version.
af.js2s(aObject) : StringTries to convert an object into a beautified string representation.
af.load(aFilename)Loads an OpenAF script/file aFilename. The variable __loadedfrom will always be set to the aFilename value a after each execution. The aFilename can be composed not only by a filename but also with a zip/opack file where it resides (for example: "aZipFile.zip::aScriptInsideTheZip.js"). The variable __loadedfromzip would hold, in this case, the zip file from which the script was executed.
af.loadRequire(arrayOfPaths, isSandboxed)Will redefine the require function on the current scope to use the arrayOfPaths provided. Optionally you can the require function can provide a sandbox enviroment if isSandboxed = true.
af.mkdir(aNewDirectory) : booleanTries to create aNewDirectory. Returns true if successfull, false otherwise.
af.mv(aSourceFilePath, aTargetFilePath)Tries to move aSourceFilePath to aTargetFilePath preserving file attributes.
af.newOutputStream() : StreamCreates a new ByteArrayOutputStream. After using this stream you can, for example, use .toString and toByteArray methods from the resulting stream.
af.p(aString)Outputs to stdout aString ending with a newline.
af.plugin(aPluginClass)Loads a OpenAF's plugin class (aPluginClass).
af.pnl(aString)Outputs to stdout aString without a newline on the end.
af.rename(aSourceFilePath, aTargetFilePath)Tries to rename aSourceFilePath to aTargetFilePath.
af.restartOpenAF(aCommandLineArray)Terminates the current OpenAF execution and tries to start a new with the same command line, if aCommandLineArray is not provided. If aCommandLineArray is provided each array element will be use sequentially to build the command line to start a new OpenAF instance.
af.rm(aFilePath)Tries to delete a file or a directory on the provided aFilePath. In case it's a directory it will try to recursively delete all directory contents.
af.runFromClass(aCompiledJavascriptClass) : ObjectRuns aCompiledJavascriptClass returning it's output. Example:
af.compileToClasses("SomeClass", "print('hello world!');", "/some/path");
var aScriptClass = af.externalClass(["file://some/path/"], "SomeClass");
af.runFromClass(aScriptClass.newInstance());
af.sh(commandArguments, aStdIn, aTimeout, shouldInheritIO, aDirectory, returnMap) : String/MapTries to execute commandArguments (either a String or an array of strings) in the operating system. Optionally aStdIn can be provided, aTimeout can be defined for the execution and if shouldInheritIO is true the stdout, stderr and stdin will be inherit from OpenAF. If shouldInheritIO is not defined or false it will return the stdout of the command execution. It's possible also to provide a different working aDirectory. The variables __exitcode and __stderr can be checked for the command exit code and the stderr output correspondingly. In alternative if returnMap = true a map will be returned with stdout, stderr and exitcode.
af.showDebugger(shouldRedirect)Shows the default Rhino debugger. If shouldRedirect is true then stdin, stdout and stderr will be redirected to the debugger's console.
af.sleep(aTime)Suspends the current script execution (if using Threads only the thread executing this function) for a period of aTime in ms. For example aTime = 1000 would result in suspending the execution for 1 second.
af.sync(aFunction, aObject)When running in multithreaded scripts will ensure that aFunction is synchronized. Optionally aObject for synchronization can be provided.
af.toBase64Bytes(arrayOfBytes) : anArrayOfBytesGiven arrayOfBytes as a string or an array of bytes in Base 64 will convert it back to an array of bytes.
af.validate2FA(aKey, aToken) : booleanGiven aToken and a 2FA aKey returns true if it's valid. Note: it will use the current date/time of the system so it must be in sync with the authenticator app; scratchCodes are not handled.