Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.caucho.es
Class Resin

    java.lang.Object
      |
      +--com.caucho.es.Resin

public class Resin
extends java.lang.Object

Resin is the primary public entry to the JavaScript compiler.

The script must first be compiled, then executed.

JavaScript import uses a script path to located the imported script. The scriptPath is just an array of Paths. If the scriptPath is null, Resin will default to the script's directory, followed by $RESIN_HOME/scripts.

Here's the default, where 'is' is the input stream:

     Path scriptPath[] = new Path[] {
       is.getPath().getParent(),
       CauchoSystem.getResinHome().lookup("scripts")
     }

As described in the Script object, programs set global variables with a hash map. So a simple call might look like:

     Script script = Resin.parse(Pwd.lookup("foo.js"), scriptPath);

     HashMap props = new HashMap();
     props.put("out", System.out);

     script.execute(props, null);

Executing the Script object is threadsafe. The ScriptClosure object, of course, is not threadsafe.

Method Summary
`static void` | `init(ESFactory factory)`
`static void` | `main(java.lang.String[] argv)`
`static Script` | `parse(java.lang.ClassLoader parentLoader, Path[] scriptPath, ReadStream is, com.caucho.java.LineMap lineMap)`
`static Script` | `parse(java.lang.ClassLoader parentLoader, Path[] scriptPath, ReadStream is, com.caucho.java.LineMap lineMap, long lastModified)`
`static Script` | `parse(java.lang.ClassLoader parentLoader, Path[] scriptPath, ReadStream is, java.lang.String name, int line)` Parse a JavaScript file.
`static Script` | `parse(Path path, Path[] scriptPath)` Parse a JavaScript file and return a script object.
`static Script` | `parse(ReadStream is, Path[] scriptPath)` Parse a JavaScript file and return a script object.
`static Script` | `parseFile(Path path, Path[] scriptPath)` parseFile is a temporary testing API to distinguigh the parse routines for JavaScript

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### init

    public static void init(ESFactory factory)

### parse

    public static Script parse(java.lang.ClassLoader parentLoader,
                               Path[] scriptPath,
                               ReadStream is,
                               java.lang.String name,
                               int line)
                        throws java.io.IOException,
                               ESException

  Parse a JavaScript file. This is primarily a testing API, allowing JavaScript embedded in another file to get proper line numbers.
  Parameters:
    `scriptPath` - List of paths for JavaScript import
    `is` - The stream containing the JavaScript
    `name` - User name of the script for error messages
    `line` - Starting line of the script for error messages

### parse

    public static Script parse(java.lang.ClassLoader parentLoader,
                               Path[] scriptPath,
                               ReadStream is,
                               com.caucho.java.LineMap lineMap)
                        throws java.io.IOException,
                               ESException

### parse

    public static Script parse(java.lang.ClassLoader parentLoader,
                               Path[] scriptPath,
                               ReadStream is,
                               com.caucho.java.LineMap lineMap,
                               long lastModified)
                        throws java.io.IOException,
                               ESException

### parse

    public static Script parse(ReadStream is,
                               Path[] scriptPath)
                        throws java.io.IOException,
                               ESException

  Parse a JavaScript file and return a script object.

  The scriptPath is just an array of Paths. The default is the directory of the script, followed by $RESIN_HOME/scripts.

  Here's the default:

       Path scriptPath[] = new Path[] {
         is.getPath().getParent(),
         CauchoSystem.getResinHome().lookup("scripts")
       }

  Parameters:
    `is` - The input stream to read the file.
    `scriptPath` - A path of directories to search for JavaScript imported files.

### parse

    public static Script parse(Path path,
                               Path[] scriptPath)
                        throws java.io.IOException,
                               ESException

  Parse a JavaScript file and return a script object. This is a convenience function for those too lazy to open a stream.
  Parameters:
    `path` - The file path.
    `scriptPath` - A path of directories to search for JavaScript imported files.

### parseFile

    public static Script parseFile(Path path,
                                   Path[] scriptPath)
                            throws java.io.IOException,
                                   ESException

  parseFile is a temporary testing API to distinguigh the parse routines for JavaScript

### main

    public static void main(java.lang.String[] argv)

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD