Package org.apache.velocity.script
Class VelocityScriptEngine
- java.lang.Object
-
- javax.script.AbstractScriptEngine
-
- org.apache.velocity.script.VelocityScriptEngine
-
- All Implemented Interfaces:
Compilable,ScriptEngine
public class VelocityScriptEngine extends AbstractScriptEngine implements Compilable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classVelocityScriptEngine.SingleResourceReader
-
Field Summary
Fields Modifier and Type Field Description static StringVELOCITY_PROPERTIES_KEYKey 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
Constructors Constructor Description VelocityScriptEngine()constructs a new standalone Velocity script engineVelocityScriptEngine(ScriptEngineFactory factory)constructs a new Velocity script engine, linked to the given factory
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompiledScriptcompile(Reader script)Compile a templateCompiledScriptcompile(String script)Compile a templateBindingscreateBindings()creates a new Bindings to be used with this scriptObjecteval(Reader reader, ScriptContext ctx)Evaluate the given script.Objecteval(String str, ScriptContext ctx)Evaluate the given script.ScriptEngineFactorygetFactory()get the factory used to create this script engineprotected static StringgetFilename(ScriptContext ctx)protected static VelocityContextgetVelocityContext(ScriptContext ctx)protected RuntimeInstancegetVelocityEngine()get the internal Velocity RuntimeInstanceprotected static PropertiesgetVelocityProperties(ScriptContext ctx)-
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
-
-
-
-
Field Detail
-
VELOCITY_PROPERTIES_KEY
public static final String 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:
- Constant Field Values
-
-
Constructor Detail
-
VelocityScriptEngine
public VelocityScriptEngine(ScriptEngineFactory factory)
constructs a new Velocity script engine, linked to the given factory- Parameters:
factory-
-
VelocityScriptEngine
public VelocityScriptEngine()
constructs a new standalone Velocity script engine
-
-
Method Detail
-
getVelocityEngine
protected RuntimeInstance getVelocityEngine()
get the internal Velocity RuntimeInstance- Returns:
- the internal Velocity RuntimeInstance
-
eval
public Object eval(String str, ScriptContext ctx) throws ScriptException
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:
evalin interfaceScriptEngine- Parameters:
str- script sourcectx- script context- Returns:
- the script context writer (by default a PrintWriter towards System.out)
- Throws:
ScriptException
-
eval
public Object eval(Reader reader, ScriptContext ctx) throws ScriptException
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:
evalin interfaceScriptEngine- Parameters:
reader- script source readerctx- script context- Returns:
- the script context writer (by default a PrintWriter towards System.out)
- Throws:
ScriptException
-
getFactory
public ScriptEngineFactory getFactory()
get the factory used to create this script engine- Specified by:
getFactoryin interfaceScriptEngine- Returns:
- factory
-
createBindings
public Bindings createBindings()
creates a new Bindings to be used with this script- Specified by:
createBindingsin interfaceScriptEngine- Returns:
- new bindings
-
getVelocityContext
protected static VelocityContext getVelocityContext(ScriptContext ctx)
-
getFilename
protected static String getFilename(ScriptContext ctx)
-
getVelocityProperties
protected static Properties getVelocityProperties(ScriptContext ctx)
-
compile
public CompiledScript compile(String script) throws ScriptException
Compile a template- Specified by:
compilein interfaceCompilable- Parameters:
script- template source- Returns:
- compiled template
- Throws:
ScriptException
-
compile
public CompiledScript compile(Reader script) throws ScriptException
Compile a template- Specified by:
compilein interfaceCompilable- Parameters:
script- template source- Returns:
- compiled template
- Throws:
ScriptException
-
-