|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.caucho.es.parser.Parser
Parser is a factory for generating compiled Script objects.
Most applications will use the parse(String)
interface
to parse JavaScript. That method will try to load a precompiled
script from the work directory before trying to parse it.
Applications will often set the script path a directory for
script and include the classpath in the path. Applications will
often override the work dir for a more appropriate work directory.
package com.caucho.vfs.*;
package com.caucho.es.*;
...
com.caucho.es.parser.Parser parser;
parser = new com.caucho.es.parser.Parser();
// configure the path to search for *.js files
MergePath scriptPath = new MergePath();
scriptPath.addMergePath(Vfs.lookup("/home/ferg/js"));
ClassLoader loader = Thread.currentThread().contextClassLoader();
scriptPath.addClassPath(loader);
parser.setScriptPath(scriptPath);
// configure the directory storing compiled scripts
Path workPath = Vfs.lookup("/tmp/caucho/work");
parser.setWorkDir(workPath);
Script script = parser.parse("test.js");
Constructor Summary | |
Parser()
|
Method Summary | |
void |
addImport(java.lang.String name)
Adds a package/script to be automatically imported by the script. |
java.lang.String |
getFilename()
Returns the current filename being parsed. |
Path |
getScriptPath()
Returns the path to search for imported javascript. |
Path |
getWorkDir()
Returns the directory for generated *.java and *.class files. |
Script |
parse(ReadStream is)
Alternative parsing method when the application only has an open stream to the file. |
Script |
parse(ReadStream is,
java.lang.String name,
int line)
An alternative parsing method given an open stream, a filename and a line number. |
Script |
parse(java.lang.String name)
Main application parsing method. |
Script |
parseEval(ReadStream is,
java.lang.String name,
int line)
Parses a script for the JavaScript "eval" expression. |
void |
setClassLoader(java.lang.ClassLoader loader)
Internal method to set the actual class loader. |
void |
setClassName(java.lang.String name)
Sets the name of the generated java class. |
void |
setFast(boolean isFast)
Sets "fast" mode, i.e. |
void |
setLineMap(com.caucho.java.LineMap lineMap)
Sets a line number map. |
void |
setParentLoader(java.lang.ClassLoader parentLoader)
Sets the parent class loader. |
void |
setScriptPath(Path scriptPath)
Sets the path to search for imported javascript source files. |
void |
setWorkDir(Path path)
Sets the directory for generated *.java and *.class files. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Parser()
Method Detail |
public void setParentLoader(java.lang.ClassLoader parentLoader)
parentLoader
- the classloader to be used for the script's parent.public void setClassLoader(java.lang.ClassLoader loader)
public void setScriptPath(Path scriptPath)
If the ScriptPath is not specified, it will use the
current directory and the classpath from the context class loader.
MergePath scriptPath = new MergePath();
scriptPath.addMergePath(Vfs.lookup("/home/ferg/js"));
ClassLoader loader = Thread.currentThread().contextClassLoader();
scriptPath.addClassPath(loader);
parser.setScriptPath(scriptPath);
scriptPath
- path to search for imported scripts.public Path getScriptPath()
scriptPath
- path to search for imported scripts.public void addImport(java.lang.String name)
package name;
name
- package or script name to be automatically imported.public void setFast(boolean isFast)
public void setLineMap(com.caucho.java.LineMap lineMap)
public void setClassName(java.lang.String name)
public void setWorkDir(Path path)
path
- the work directory.public Path getWorkDir()
public Script parse(java.lang.String name) throws ESException, java.io.IOException
name
- the name of the javascript source.public Script parse(ReadStream is) throws ESException, java.io.IOException
parse(String)
method.is
- a read stream to the javascript source.public Script parse(ReadStream is, java.lang.String name, int line) throws ESException, java.io.IOException
is
- a stream to the javascript source.name
- filename to use for error messages.line
- initial line number.public Script parseEval(ReadStream is, java.lang.String name, int line) throws ESException, java.io.IOException
is
- stream to the eval source.name
- filename to use for error messagesline
- initial line number to use for error messages.public java.lang.String getFilename()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |