java.lang.Objectorg.mozilla.javascript.ScriptableObject
org.wso2.mashup.hostobjects.file.JavaScriptFileObject
public class JavaScriptFileObject
| Field Summary |
|---|
| Fields inherited from class org.mozilla.javascript.ScriptableObject |
|---|
CONST, DONTENUM, EMPTY, PERMANENT, READONLY,
UNINITIALIZED_CONST |
| Fields inherited from interface org.mozilla.javascript.Scriptable |
|---|
NOT_FOUND |
| Constructor Summary | |
|---|---|
JavaScriptFileObject() |
|
| Method Summary | |
|---|---|
java.lang.String |
getClassName() |
java.io.File |
getFile()To access the file from java classes |
static org.mozilla.javascript.Scriptable |
jsConstructor(org.mozilla.javascript.Context cx,
java.lang.Object[] args,
org.mozilla.javascript.Function ctorObj,
boolean inNewExpr) |
void |
jsFunction_close()Users are expected to close the file after reading, writing & appending to the file. |
boolean |
jsFunction_createFile()Creates the file if it does not exist. |
boolean |
jsFunction_deleteFile()Deletes this file from the file system. |
static boolean |
jsFunction_move(org.mozilla.javascript.Context cx,
org.mozilla.javascript.Scriptable thisObj,
java.lang.Object[] arguments,
org.mozilla.javascript.Function funObj)Move the file to the given target file. |
void |
jsFunction_openForAppending()Open the file for appending. |
void |
jsFunction_openForReading()Open the file for reading. |
void |
jsFunction_openForWriting()Open the file for writing. |
java.lang.String |
jsFunction_read(int noOfCharacters)Reads the given number of characters from the file and return a string representation of those characters. |
java.lang.String |
jsFunction_readAll()Reads all the content in the file and return a string representation of the content. |
java.lang.String |
jsFunction_readLine()Reads a line from the file and return a string representation of the line. |
java.lang.String |
jsFunction_toString() |
void |
jsFunction_write(java.lang.Object object)Writes the String representation of the object to the file. |
void |
jsFunction_writeLine(java.lang.Object object)Writes the String representation of the object to the file together with a line separator at the end. |
boolean |
jsGet_exists()Checks whether this file actually exists. |
java.lang.String |
jsGet_lastModified() |
long |
jsGet_length() |
java.lang.String |
jsGet_name() |
java.lang.String |
jsGet_path() |
| Methods inherited from class org.mozilla.javascript.ScriptableObject |
|---|
associateValue, callMethod, callMethod, defineClass,
defineClass, defineClass, defineConst, defineConstProperty,
defineFunctionProperties, defineProperty, defineProperty,
defineProperty, defineProperty, delete, delete, deleteProperty,
deleteProperty, get, get, getAllIds, getAssociatedValue,
getAttributes, getAttributes, getAttributes, getAttributes,
getClassPrototype, getDefaultValue, getDefaultValue,
getFunctionPrototype, getGetterOrSetter, getIds,
getObjectPrototype, getParentScope, getProperty, getProperty,
getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue,
has, has, hasInstance, hasProperty, hasProperty, isConst, isSealed,
put, put, putConst, putConstProperty, putProperty, putProperty,
redefineProperty, sealObject, setAttributes, setAttributes,
setAttributes, setAttributes, setGetterOrSetter, setParentScope,
setPrototype |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString,
wait, wait, wait |
| Constructor Detail |
|---|
public JavaScriptFileObject()
| Method Detail |
|---|
public static org.mozilla.javascript.Scriptable jsConstructor(org.mozilla.javascript.Context cx,
java.lang.Object[] args,
org.mozilla.javascript.Function ctorObj,
boolean inNewExpr)
throws org.wso2.mashup.MashupFault
org.wso2.mashup.MashupFaultpublic java.lang.String getClassName()
getClassName in interface
org.mozilla.javascript.ScriptablegetClassName in class
org.mozilla.javascript.ScriptableObject
public void jsFunction_openForReading()
throws org.wso2.mashup.MashupFault
Open the file for reading.
java.io.IOException - if the file is already open
for either appending or reading, if the file does not exist, if the
file cannot be opened for any other file system specific
reason.org.wso2.mashup.MashupFault
public void jsFunction_openForWriting()
throws org.wso2.mashup.MashupFault
Open the file for writing. Using write() or writeLine() on a file which is open for writing will write those content to the beginning of the file overwriting the content of the file.
If the file does not exist, this will create the file.
java.io.IOException - if the file is already open
for either appending or reading, if the file cannot be opened for
any other file system specific reason.org.wso2.mashup.MashupFault
public void jsFunction_openForAppending()
throws org.wso2.mashup.MashupFault
Open the file for appending. Using write() or writeLine() on a file which is open for appending will write those content to the end of the file rather than the beginning.
If the file does not exist, this will create the file.
java.io.IOException - if the file is already open
for either writing or reading, if the file cannot be opened for any
other file system specific reason.org.wso2.mashup.MashupFault
public void jsFunction_write(java.lang.Object object)
throws org.wso2.mashup.MashupFault
Writes the String representation of the object to the file. Users are required to open the file for writing or for appending before writing to the file.
If the file is not open for either reading or writing or appending, then calling this will automatically opens the file for writing(Overwrites the current content of the file).
var file = new File("readme.txt");
file.openForWriting();
//file.openForAppending();
file.write("Hello World!");
file.close();
object -java.io.IOExceptionorg.wso2.mashup.MashupFault
public void jsFunction_writeLine(java.lang.Object object)
throws org.wso2.mashup.MashupFault
Writes the String representation of the object to the file together with a line separator at the end. Users are required to open the file for writing or for appending before writing to the file.
If the file is not open for either reading or writing or appending, then calling this will automatically opens the file for writing(Overwrites the current content of the file).
var file = new File("readme.txt");
file.openForWriting();
//file.openForAppending();
file.writeLine("Hello World!");
file.close();
object -java.io.IOExceptionorg.wso2.mashup.MashupFault
public java.lang.String jsFunction_read(int noOfCharacters)
throws org.wso2.mashup.MashupFault
Reads the given number of characters from the file and return a string representation of those characters. Users are required to open the file for reading before reading from the file.
If the file is not open for either reading or writing or appending, then calling this will automatically opens the file for reading.
var file = new File("readme.txt");
file.openForReading();
var x = file.read(5);
print(x);
file.close();
noOfCharacters - of characters to be readjava.io.IOExceptionorg.wso2.mashup.MashupFault
public java.lang.String jsFunction_readLine()
throws org.wso2.mashup.MashupFault
Reads a line from the file and return a string representation of the line. Users are required to open the file for reading before reading from the file.
If the file is not open for either reading or writing or appending, then calling this will automatically opens the file for reading.
var file = new File("readme.txt");
file.openForReading();
var x = file.readLine();
print(x);
file.close();
java.io.IOExceptionorg.wso2.mashup.MashupFault
public java.lang.String jsFunction_readAll()
throws org.wso2.mashup.MashupFault
Reads all the content in the file and return a string representation of the content. Users are required to open the file for reading before reading from the file.
If the file is not open for either reading or writing or appending, then calling this will automatically opens the file for reading.
var file = new File("readme.txt");
file.openForReading();
var x = file.readAll();
print(x);
file.close();
java.io.IOExceptionorg.wso2.mashup.MashupFault
public void jsFunction_close()
throws org.wso2.mashup.MashupFault
Users are expected to close the file after reading, writing & appending to the file.
var file = new File("readme.txt");
file.openForReading();
var x = file.readLine();
file.close();
file.openForAppending();
file.write("Hello world!");
file.close();
java.io.IOExceptionorg.wso2.mashup.MashupFault
public boolean jsFunction_createFile()
throws org.wso2.mashup.MashupFault
Creates the file if it does not exist. Also creates the parent directories if they are not present.
var file = new File("readme.txt");
file.createFile();
java.io.IOExceptionorg.wso2.mashup.MashupFault
public static boolean jsFunction_move(org.mozilla.javascript.Context cx,
org.mozilla.javascript.Scriptable thisObj,
java.lang.Object[] arguments,
org.mozilla.javascript.Function funObj)
throws org.wso2.mashup.MashupFault
arguments - {String} The destination file
namejava.io.IOExceptionorg.wso2.mashup.MashupFaultpublic boolean jsFunction_deleteFile()
public java.lang.String jsFunction_toString()
throws org.wso2.mashup.MashupFault
org.wso2.mashup.MashupFaultpublic long jsGet_length()
public java.lang.String jsGet_lastModified()
public java.lang.String jsGet_path()
public java.lang.String jsGet_name()
public boolean jsGet_exists()
public java.io.File getFile()