org.wso2.mashup.hostobjects.file
Class JavaScriptFileObject

java.lang.Object
  extended by org.mozilla.javascript.ScriptableObject
      extended by org.wso2.mashup.hostobjects.file.JavaScriptFileObject
All Implemented Interfaces:
java.io.Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable

public class JavaScriptFileObject
extends org.mozilla.javascript.ScriptableObject
This is a JavaScript Rhino host object to provide the ability for the users to manipulate with Files inside the WSO2 Mashup environment. For more information refer to JavaScript File Host Object.
See Also:
Serialized Form

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

JavaScriptFileObject

public JavaScriptFileObject()
Method Detail

jsConstructor

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
Throws:
org.wso2.mashup.MashupFault

getClassName

public java.lang.String getClassName()
Specified by:
getClassName in interface org.mozilla.javascript.Scriptable
Specified by:
getClassName in class org.mozilla.javascript.ScriptableObject

jsFunction_openForReading

public void jsFunction_openForReading()
                               throws org.wso2.mashup.MashupFault

Open the file for reading.

Throws:
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

jsFunction_openForWriting

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.

Throws:
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

jsFunction_openForAppending

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.

Throws:
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

jsFunction_write

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();
 
Parameters:
object -
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_writeLine

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();
 
Parameters:
object -
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_read

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();
 
Parameters:
noOfCharacters - of characters to be read
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_readLine

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();
 
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_readAll

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();
 
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_close

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();
 
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_createFile

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();
 
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_move

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
Move the file to the given target file.
Parameters:
arguments - {String} The destination file name
Returns:
true if the file was successfully moved.
Throws:
java.io.IOException
org.wso2.mashup.MashupFault

jsFunction_deleteFile

public boolean jsFunction_deleteFile()
Deletes this file from the file system.
Returns:
true if the file was successfully deleted.

jsFunction_toString

public java.lang.String jsFunction_toString()
                                     throws org.wso2.mashup.MashupFault
Throws:
org.wso2.mashup.MashupFault

jsGet_length

public long jsGet_length()
Returns:
the length of the file in bytes

jsGet_lastModified

public java.lang.String jsGet_lastModified()
Returns:
the last modified time of this file.

jsGet_path

public java.lang.String jsGet_path()
Returns:
the path name of the file.

jsGet_name

public java.lang.String jsGet_name()
Returns:
the name of the file without the path.

jsGet_exists

public boolean jsGet_exists()
Checks whether this file actually exists.
Returns:
true if the file exists.

getFile

public java.io.File getFile()
To access the file from java classes