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 class`
`VelocityScriptEngine.SingleResourceReader`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`VELOCITY_PROPERTIES_KEY`
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

Constructors
Constructor
Description
`VelocityScriptEngine()`
constructs a new standalone Velocity script engine
`VelocityScriptEngine(ScriptEngineFactory factory)`
constructs a new Velocity script engine, linked to the given factory

## Method Summary

Modifier and Type
Method
Description
`CompiledScript`
`compile(Reader script)`
Compile a template
`CompiledScript`
`compile(String script)`
Compile a template
`Bindings`
`createBindings()`
creates a new Bindings to be used with this script
`Object`
`eval(Reader reader, ScriptContext ctx)`
Evaluate the given script.
`Object`
`eval(String str, ScriptContext ctx)`
Evaluate the given script.
`ScriptEngineFactory`
`getFactory()`
get the factory used to create this script engine
`protected static String`
`getFilename(ScriptContext ctx)`
`protected static VelocityContext`
`getVelocityContext(ScriptContext ctx)`
`protected RuntimeInstance`
`getVelocityEngine()`
get the internal Velocity RuntimeInstance
`protected static Properties`
`getVelocityProperties(ScriptContext ctx)`

### Methods inherited from class javax.script.AbstractScriptEngine

`eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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 Details

### 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 Details

### 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:
  `eval` in interface `ScriptEngine`
Parameters:
  `str` - script source
  `ctx` - 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:
  `eval` in interface `ScriptEngine`
Parameters:
  `reader` - script source reader
  `ctx` - 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:
  `getFactory` in interface `ScriptEngine`
Returns:
  factory

### createBindings

public Bindings createBindings()
creates a new Bindings to be used with this script

Specified by:
  `createBindings` in interface `ScriptEngine`
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:
  `compile` in interface `Compilable`
Parameters:
  `script` - template source
Returns:
  compiled template
Throws:
  `ScriptException`

### compile

public CompiledScript compile(Reader script) throws ScriptException
Compile a template

Specified by:
  `compile` in interface `Compilable`
Parameters:
  `script` - template source
Returns:
  compiled template
Throws:
  `ScriptException`