velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dish...@apache.org
Subject svn commit: r1352286 - /velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
Date Wed, 20 Jun 2012 19:56:34 GMT
Author: dishara
Date: Wed Jun 20 19:56:33 2012
New Revision: 1352286

URL: http://svn.apache.org/viewvc?rev=1352286&view=rev
Log:
Added enhancements to script engine

Modified:
    velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java

Modified: velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
URL: http://svn.apache.org/viewvc/velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java?rev=1352286&r1=1352285&r2=1352286&view=diff
==============================================================================
--- velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
(original)
+++ velocity/sandbox/jsr223/velocity-engine-scripting/src/main/java/org/apache/velocity/script/VelocityScriptEngine.java
Wed Jun 20 19:56:33 2012
@@ -34,11 +34,24 @@ public class VelocityScriptEngine implem
     private ScriptEngineFactory scriptEngineFactory;
     private VelocityEngine velocityEngine;
     public static final String VELOCITY_PROPERTIES = "org.apache.velocity.engine.properties";
+    private ScriptContext scriptContext;
 
     public VelocityScriptEngine(ScriptEngineFactory scriptEngineFactory) {
         this.scriptEngineFactory = scriptEngineFactory;
+        this.scriptContext = new VelocityScriptContext();
     }
 
+    public VelocityScriptEngine(ScriptEngineFactory scriptEngineFactory,Bindings bindings)
{
+        this.scriptEngineFactory = scriptEngineFactory;
+        this.scriptContext = new VelocityScriptContext();
+        if(bindings != null ) {
+            this.scriptContext.setBindings(bindings,ScriptContext.ENGINE_SCOPE);
+        } else {
+            throw new NullPointerException("Bindings cannot be null");
+        }
+    }
+
+
     /**
      * @return a  ScriptEngineFactory , if null return a newly created one . Added creation
inside sync block to avoid creating
      *         two factories from a engine by two parallel threads at the same time. Also
the additional null check out from sync block is to avoid every
@@ -143,23 +156,48 @@ public class VelocityScriptEngine implem
     }
 
     public Object eval(Reader reader, Bindings bindings) throws ScriptException {
+//       ScriptContext scriptContext = get
         return null;  //To change body of implemented methods use File | Settings | File
Templates.
     }
 
+    private ScriptContext getGeneratedScriptContextFromBinding(Bindings bindings) {
+        ScriptContext tmpContext = new VelocityScriptContext();
+        Bindings globalScope = scriptContext.getBindings(ScriptContext.GLOBAL_SCOPE);
+
+        //Setting global and engine scopes to context
+        if(globalScope != null) {
+            tmpContext.setBindings(globalScope,ScriptContext.GLOBAL_SCOPE);
+        }
+
+        if(bindings != null) {
+           tmpContext.setBindings(bindings,ScriptContext.ENGINE_SCOPE);
+        } else {
+            throw new NullPointerException("Engine scope Bindings cannot be null.");
+        }
+
+        tmpContext.setReader(scriptContext.getReader());
+        tmpContext.setWriter(scriptContext.getWriter());
+        tmpContext.setErrorWriter(scriptContext.getErrorWriter());
+
+        return tmpContext;
+    }
+
     public void put(String s, Object o) {
-        //To change body of implemented methods use File | Settings | File Templates.
+       Bindings engineScope = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
+       engineScope.put(s,o);
     }
 
     public Object get(String s) {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        Bindings engineScope = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
+        return engineScope.get(s);
     }
 
     public Bindings getBindings(int i) {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        return scriptContext.getBindings(i);  //To change body of implemented methods use
File | Settings | File Templates.
     }
 
     public void setBindings(Bindings bindings, int i) {
-        //To change body of implemented methods use File | Settings | File Templates.
+        scriptContext.setBindings(bindings,i);
     }
 
     public Bindings createBindings() {
@@ -167,7 +205,7 @@ public class VelocityScriptEngine implem
     }
 
     public ScriptContext getContext() {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        return  scriptContext;
     }
 
     public void setContext(ScriptContext scriptContext) {



Mime
View raw message