Class VelocityScriptEngine

  • All Implemented Interfaces:
    javax.script.Compilable, javax.script.ScriptEngine

    public class VelocityScriptEngine
    extends javax.script.AbstractScriptEngine
    implements javax.script.Compilable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.script.ScriptEngineFactory factory  
      static java.lang.String VELOCITY_PROPERTIES_KEY
      Key used to provide this engine with the pathname of the Velocity properties file.
      private RuntimeInstance velocityEngine  
      • 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​(javax.script.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
      javax.script.CompiledScript compile​(java.io.Reader script)
      Compile a template
      javax.script.CompiledScript compile​(java.lang.String script)
      Compile a template
      javax.script.Bindings createBindings()
      creates a new Bindings to be used with this script
      java.lang.Object eval​(java.io.Reader reader, javax.script.ScriptContext ctx)
      Evaluate the given script.
      java.lang.Object eval​(java.lang.String str, javax.script.ScriptContext ctx)
      Evaluate the given script.
      javax.script.ScriptEngineFactory getFactory()
      get the factory used to create this script engine
      protected static java.lang.String getFilename​(javax.script.ScriptContext ctx)  
      protected static VelocityContext getVelocityContext​(javax.script.ScriptContext ctx)  
      protected RuntimeInstance getVelocityEngine()
      get the internal Velocity RuntimeInstance
      protected static java.util.Properties getVelocityProperties​(javax.script.ScriptContext ctx)  
      private void initVelocityEngine​(javax.script.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 Detail

      • VELOCITY_PROPERTIES_KEY

        public static final java.lang.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
      • factory

        private volatile javax.script.ScriptEngineFactory factory
    • Constructor Detail

      • VelocityScriptEngine

        public VelocityScriptEngine​(javax.script.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 java.lang.Object eval​(java.lang.String str,
                                     javax.script.ScriptContext ctx)
                              throws javax.script.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 javax.script.ScriptEngine
        Parameters:
        str - script source
        ctx - script context
        Returns:
        the script context writer (by default a PrintWriter towards System.out)
        Throws:
        javax.script.ScriptException
      • eval

        public java.lang.Object eval​(java.io.Reader reader,
                                     javax.script.ScriptContext ctx)
                              throws javax.script.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 javax.script.ScriptEngine
        Parameters:
        reader - script source reader
        ctx - script context
        Returns:
        the script context writer (by default a PrintWriter towards System.out)
        Throws:
        javax.script.ScriptException
      • getFactory

        public javax.script.ScriptEngineFactory getFactory()
        get the factory used to create this script engine
        Specified by:
        getFactory in interface javax.script.ScriptEngine
        Returns:
        factory
      • createBindings

        public javax.script.Bindings createBindings()
        creates a new Bindings to be used with this script
        Specified by:
        createBindings in interface javax.script.ScriptEngine
        Returns:
        new bindings
      • initVelocityEngine

        private void initVelocityEngine​(javax.script.ScriptContext ctx)
      • getVelocityContext

        protected static VelocityContext getVelocityContext​(javax.script.ScriptContext ctx)
      • getFilename

        protected static java.lang.String getFilename​(javax.script.ScriptContext ctx)
      • getVelocityProperties

        protected static java.util.Properties getVelocityProperties​(javax.script.ScriptContext ctx)
      • compile

        public javax.script.CompiledScript compile​(java.lang.String script)
                                            throws javax.script.ScriptException
        Compile a template
        Specified by:
        compile in interface javax.script.Compilable
        Parameters:
        script - template source
        Returns:
        compiled template
        Throws:
        javax.script.ScriptException
      • compile

        public javax.script.CompiledScript compile​(java.io.Reader script)
                                            throws javax.script.ScriptException
        Compile a template
        Specified by:
        compile in interface javax.script.Compilable
        Parameters:
        script - template source
        Returns:
        compiled template
        Throws:
        javax.script.ScriptException