Package org.apache.velocity.script
Class VelocityScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
org.apache.velocity.script.VelocityScriptEngine
- All Implemented Interfaces:
Compilable
,ScriptEngine
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Key used to provide this engine with the pathname of the Velocity properties file.Fields inherited from class javax.script.AbstractScriptEngine
context
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
-
Constructor Summary
ConstructorDescriptionconstructs a new standalone Velocity script engineVelocityScriptEngine
(ScriptEngineFactory factory) constructs a new Velocity script engine, linked to the given factory -
Method Summary
Modifier and TypeMethodDescriptionCompile a templateCompile a templatecreates a new Bindings to be used with this scripteval
(Reader reader, ScriptContext ctx) Evaluate the given script.eval
(String str, ScriptContext ctx) Evaluate the given script.get the factory used to create this script engineprotected static String
getFilename
(ScriptContext ctx) protected static VelocityContext
protected RuntimeInstance
get the internal Velocity RuntimeInstanceprotected static Properties
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
-
Field Details
-
VELOCITY_PROPERTIES_KEY
Key used to provide this engine with the pathname of the Velocity properties file. This key is first searched in the ScriptContext attributes, then as a System property- See Also:
-
-
Constructor Details
-
VelocityScriptEngine
constructs a new Velocity script engine, linked to the given factory- Parameters:
factory
-
-
VelocityScriptEngine
public VelocityScriptEngine()constructs a new standalone Velocity script engine
-
-
Method Details
-
getVelocityEngine
get the internal Velocity RuntimeInstance- Returns:
- the internal Velocity RuntimeInstance
-
eval
Evaluate the given script. If you wish to get a resulting string, call getContext().setWriter(new StringWriter()) then call toString() on the returned writer.- Specified by:
eval
in interfaceScriptEngine
- Parameters:
str
- script sourcectx
- script context- Returns:
- the script context writer (by default a PrintWriter towards System.out)
- Throws:
ScriptException
-
eval
Evaluate the given script. If you wish to get a resulting string, call getContext().setWriter(new StringWriter()) then call toString() on the returned writer.- Specified by:
eval
in interfaceScriptEngine
- Parameters:
reader
- script source readerctx
- script context- Returns:
- the script context writer (by default a PrintWriter towards System.out)
- Throws:
ScriptException
-
getFactory
get the factory used to create this script engine- Specified by:
getFactory
in interfaceScriptEngine
- Returns:
- factory
-
createBindings
creates a new Bindings to be used with this script- Specified by:
createBindings
in interfaceScriptEngine
- Returns:
- new bindings
-
getVelocityContext
-
getFilename
-
getVelocityProperties
-
compile
Compile a template- Specified by:
compile
in interfaceCompilable
- Parameters:
script
- template source- Returns:
- compiled template
- Throws:
ScriptException
-
compile
Compile a template- Specified by:
compile
in interfaceCompilable
- Parameters:
script
- template source- Returns:
- compiled template
- Throws:
ScriptException
-