Author: sebb
Date: Wed Mar 25 00:35:59 2009
New Revision: 758103

URL: http://svn.apache.org/viewvc?rev=758103&view=rev
Log:
Detab

Modified:
    jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/Main.java
    
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/GenericHttpScriptContext.java
    
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptContext.java
    
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptRequest.java
    
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptServlet.java
    
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/ScriptEnginePool.java

Modified: 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/Main.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/Main.java?rev=758103&r1=758102&r2=758103&view=diff
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/Main.java 
(original)
+++ jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/Main.java Wed 
Mar 25 00:35:59 2009
@@ -39,93 +39,93 @@
  * @author   Sam Ruby
  */
 public class Main {
-       private static final String ARG_IN = "-in";
-       private static final String ARG_LANG = "-lang";
-       private static final String ARG_OUT = "-out";
-       private static final String DEFAULT_IN_FILE_NAME = "<STDIN>";
-       private static final String DEFAULT_CLASS_NAME = "Test";
-
-       /**
-        * Static driver to be able to run BSF scripts from the command line.
-        *
-        * @param args command line arguments
-        */
-       public static void main(String[] args) throws IOException {
-               if ((args.length == 0) || (args.length % 2 != 0)) {
-                       printHelp();
-                       System.exit(1);
-               }
-
-               Hashtable argsTable = new Hashtable();
-
-               argsTable.put(ARG_OUT, DEFAULT_CLASS_NAME);
-
-               for (int i = 0; i < args.length; i += 2) {
-                       argsTable.put(args[i], args[i + 1]);
-               }
-
-               String inFileName = (String) argsTable.get(ARG_IN);
-               String language = (String) argsTable.get(ARG_LANG);
-
-               
-               if (language == null && inFileName != null) {
-                       int i = inFileName.lastIndexOf('.');
-                       if (i > 0) {
-                               language = inFileName.substring(i+1);
-                       }
-                       if (language == null) {
-                               throw new IllegalArgumentException("unable to 
determine language");
-                       }
-               }
-
-               ScriptEngineManager mgr = new ScriptEngineManager();
-
-               Reader in;
-
-               if (inFileName != null) {
-                       in = new FileReader(inFileName);
-               } else {
-                       in = new InputStreamReader(System.in);
-                       inFileName = DEFAULT_IN_FILE_NAME;
-               }
-
-               try {
-                       ScriptEngine engine = 
mgr.getEngineByExtension(language);
-                       Bindings bindings = 
engine.getBindings(ScriptContext.ENGINE_SCOPE);
-                       bindings.put("args", args);
-                       Object obj = engine.eval(in);
-                       System.err.println("Result: " + obj);
-               } catch (ScriptException e) {
-                   e.printStackTrace();
-               }
-       }
-
-       private static void printHelp() {
-               System.err.println("Usage:");
-               System.err.println();
-               System.err.println("  java " + Main.class.getName() + " 
[args]");
-               System.err.println();
-               System.err.println("    args:");
-               System.err.println();
-               System.err.println(
-                       "      [-in                fileName]   default: " + 
DEFAULT_IN_FILE_NAME);
-               System.err.println(
-                       "      [-lang          languageName]   default: "
-                               + "<If -in is specified and -lang");
-               System.err.println(
-                       "                                               "
-                               + " is not, attempt to determine");
-               System.err.println(
-                       "                                               "
-                               + " language from file extension;");
-               System.err.println(
-                       "                                               "
-                               + " otherwise, -lang is required.>");
-               System.err.println();
-               System.err.println(
-                       "    Additional args used only if -mode is " + "set to 
\"compile\":");
-               System.err.println();
-               System.err.println(
-                       "      [-out              className]   default: " + 
DEFAULT_CLASS_NAME);
-       }
+    private static final String ARG_IN = "-in";
+    private static final String ARG_LANG = "-lang";
+    private static final String ARG_OUT = "-out";
+    private static final String DEFAULT_IN_FILE_NAME = "<STDIN>";
+    private static final String DEFAULT_CLASS_NAME = "Test";
+
+    /**
+     * Static driver to be able to run BSF scripts from the command line.
+     *
+     * @param args command line arguments
+     */
+    public static void main(String[] args) throws IOException {
+        if ((args.length == 0) || (args.length % 2 != 0)) {
+            printHelp();
+            System.exit(1);
+        }
+
+        Hashtable argsTable = new Hashtable();
+
+        argsTable.put(ARG_OUT, DEFAULT_CLASS_NAME);
+
+        for (int i = 0; i < args.length; i += 2) {
+            argsTable.put(args[i], args[i + 1]);
+        }
+
+        String inFileName = (String) argsTable.get(ARG_IN);
+        String language = (String) argsTable.get(ARG_LANG);
+
+
+        if (language == null && inFileName != null) {
+            int i = inFileName.lastIndexOf('.');
+            if (i > 0) {
+                language = inFileName.substring(i+1);
+            }
+            if (language == null) {
+                throw new IllegalArgumentException("unable to determine 
language");
+            }
+        }
+
+        ScriptEngineManager mgr = new ScriptEngineManager();
+
+        Reader in;
+
+        if (inFileName != null) {
+            in = new FileReader(inFileName);
+        } else {
+            in = new InputStreamReader(System.in);
+            inFileName = DEFAULT_IN_FILE_NAME;
+        }
+
+        try {
+            ScriptEngine engine = mgr.getEngineByExtension(language);
+            Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
+            bindings.put("args", args);
+            Object obj = engine.eval(in);
+            System.err.println("Result: " + obj);
+        } catch (ScriptException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static void printHelp() {
+        System.err.println("Usage:");
+        System.err.println();
+        System.err.println("  java " + Main.class.getName() + " [args]");
+        System.err.println();
+        System.err.println("    args:");
+        System.err.println();
+        System.err.println(
+            "      [-in                fileName]   default: " + 
DEFAULT_IN_FILE_NAME);
+        System.err.println(
+            "      [-lang          languageName]   default: "
+                + "<If -in is specified and -lang");
+        System.err.println(
+            "                                               "
+                + " is not, attempt to determine");
+        System.err.println(
+            "                                               "
+                + " language from file extension;");
+        System.err.println(
+            "                                               "
+                + " otherwise, -lang is required.>");
+        System.err.println();
+        System.err.println(
+            "    Additional args used only if -mode is " + "set to 
\"compile\":");
+        System.err.println();
+        System.err.println(
+            "      [-out              className]   default: " + 
DEFAULT_CLASS_NAME);
+    }
 }
\ No newline at end of file

Modified: 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/GenericHttpScriptContext.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/GenericHttpScriptContext.java?rev=758103&r1=758102&r2=758103&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/GenericHttpScriptContext.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/GenericHttpScriptContext.java
 Wed Mar 25 00:35:59 2009
@@ -32,8 +32,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-public class GenericHttpScriptContext extends SimpleScriptContext implements   
HttpScriptContext {
-    
+public class GenericHttpScriptContext extends SimpleScriptContext implements   
  HttpScriptContext {
+
     public static final String[] defaultMethods = {"GET", "POST"};
     protected boolean disableScript = false;
     protected boolean displayResults = false;
@@ -44,109 +44,109 @@
     protected HttpServletResponse response;
     protected Servlet servlet;
     protected boolean useSession = true;
-    
+
     public GenericHttpScriptContext() {
         super();
     }
-    
+
     public boolean disableScript() {
         return disableScript;
-        
+
     }
-    
+
     public boolean displayResults() {
         return displayResults;
-        
+
     }
-       
+
     public String[] getAllowedLanguages() {
         return languages;
     }
-    
+
     public Object getAttribute(String key, Object value, int scope){
-       
-       switch (scope) {
-               case HttpScriptContext.ENGINE_SCOPE:
-                       return request.getAttribute(key);
-               case HttpScriptContext.SESSION_SCOPE:
-                       if (useSession()) {
-                               return request.getSession().getAttribute(key);
-                       } else {
-                               return null;
-                       }
-               case HttpScriptContext.APPLICATION_SCOPE:
-                       return 
servlet.getServletConfig().getServletContext().getAttribute(key);
-               default:
-                       return null;
-       }
+
+        switch (scope) {
+            case HttpScriptContext.ENGINE_SCOPE:
+                return request.getAttribute(key);
+            case HttpScriptContext.SESSION_SCOPE:
+                if (useSession()) {
+                    return request.getSession().getAttribute(key);
+                } else {
+                    return null;
+                }
+            case HttpScriptContext.APPLICATION_SCOPE:
+                return 
servlet.getServletConfig().getServletContext().getAttribute(key);
+            default:
+                return null;
+        }
     }
 
-    
+
     public void setAttribute(String key, Object value, int scope)
             throws IllegalArgumentException {
-       
-       switch (scope) {
-               case HttpScriptContext.REQUEST_SCOPE:
-                       request.setAttribute(key, value);
-                       break;
-               case HttpScriptContext.SESSION_SCOPE:
-                       if (useSession()) {
+
+        switch (scope) {
+            case HttpScriptContext.REQUEST_SCOPE:
+                request.setAttribute(key, value);
+                break;
+            case HttpScriptContext.SESSION_SCOPE:
+                if (useSession()) {
                     request.getSession().setAttribute(key, value);
                 } else {
                     throw new IllegalArgumentException("Session is disabled");
                 }
-                       break;
-               case HttpScriptContext.APPLICATION_SCOPE:
-                       
servlet.getServletConfig().getServletContext().setAttribute(
-                       key, value);
-                       break;
-               default:
-                       throw new IllegalArgumentException("Invalid scope");
-       }
-    }
-    
-       public void forward(String relativePath) throws ServletException, 
IOException {
-        
-               ServletContext context =  
servlet.getServletConfig().getServletContext();
+                break;
+            case HttpScriptContext.APPLICATION_SCOPE:
+                servlet.getServletConfig().getServletContext().setAttribute(
+                    key, value);
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid scope");
+        }
+    }
+
+    public void forward(String relativePath) throws ServletException, 
IOException {
+
+        ServletContext context =  
servlet.getServletConfig().getServletContext();
 
         String baseURI;
         String requestURI = request.getRequestURI();
-        
+
         if(relativePath.startsWith("/")){
             baseURI = requestURI.substring(0, 
request.getContextPath().length());
-            
+
         }else{
             baseURI = requestURI.substring(0, requestURI.lastIndexOf("/"));
         }
-        
+
         context.getRequestDispatcher(baseURI+relativePath).forward(request, 
response);
-       }
-       
+    }
 
-       public String[] getMethods() {
-               return methods;
-       }
 
-       public HttpServletRequest getRequest() {
+    public String[] getMethods() {
+        return methods;
+    }
+
+    public HttpServletRequest getRequest() {
         return new HttpScriptRequest(this, request);        
-       }
-       
-       public HttpServletResponse getResponse() {
-               return new HttpScriptResponse(this, response);
-       }
-       
+    }
+
+    public HttpServletResponse getResponse() {
+        return new HttpScriptResponse(this, response);
+    }
+
     public Reader getScriptSource() {
-        
-       String requestURI = request.getRequestURI();
+
+        String requestURI = request.getRequestURI();
         String resourcePath =
             requestURI.substring(request.getContextPath().length());
-        
+
         if(scriptDir == null){
         // should I construct a reader by combing contextRoot+ resourcePath
         }else{
             String fullPath;
             if(scriptDir.endsWith("/") || resourcePath.startsWith("/")){
-               fullPath = scriptDir + resourcePath;
+                fullPath = scriptDir + resourcePath;
             }else{
                 fullPath = scriptDir+"/"+resourcePath;
             }
@@ -155,94 +155,94 @@
             }catch(IOException ioe){
             }
         }
-        
+
         return null;
-       }
-       
-       public Servlet getServlet() {
-               return servlet;
-       }
-       
+    }
+
+    public Servlet getServlet() {
+        return servlet;
+    }
+
     public void include(String relativePath) throws ServletException, 
IOException {
         ServletContext context =  
servlet.getServletConfig().getServletContext();
 
         String baseURI;
         String requestURI = request.getRequestURI();
-        
+
         if(relativePath.startsWith("/")){
             baseURI = requestURI.substring(0, 
request.getContextPath().length());
-            
+
         }else{
             baseURI = requestURI.substring(0, requestURI.lastIndexOf("/"));
         }
-        
+
         context.getRequestDispatcher(baseURI+relativePath).include(request, 
response);       
-       }
-       
+    }
+
     public void initialize(Servlet servlet, HttpServletRequest request,
             HttpServletResponse response) throws ServletException {
-               
+
         this.request = request;
-               this.response = response;
+        this.response = response;
         this.servlet = servlet;
-        
+
         ServletContext context = 
servlet.getServletConfig().getServletContext();
-        
+
         scriptDir = context.getInitParameter("script-directory");
-        
+
         if(scriptDir == null || !(new File(scriptDir).isDirectory())){
             throw new ServletException("Specifed script directory either does 
" +
                     "not exist or not a directory");
         }
-       
+
         String disable = context.getInitParameter("script-disable");
         if(disable != null && disable.equals("true")){
             disableScript = true;
             return;
         }
-        
+
         String session = context.getInitParameter("script-use-session");
         if(session != null && session.equals("false")){
             useSession = false;
         }
-        
+
         String display = context.getInitParameter("script-display-results");
         if(display != null && display.equals("true")){
             displayResults = true;
         }
-        
+
         String methodNames = context.getInitParameter("script-methods");
         if(methodNames != null){
             methods = methodNames.split(",");
         }else{
             methods = defaultMethods;
         }
-        
+
         String languageNames = context.getInitParameter("allowed-languages");
         if(languageNames != null){
             languages = languageNames.split(",");
         }       
     }
-       
-       public void release() {
+
+    public void release() {
         disableScript = false;
         displayResults = false;
         useSession = true;
-               servlet = null;
-               request = null;
-               response = null;
-       }
-       
-       
-       public boolean useSession() {
-               return useSession;
-       }
+        servlet = null;
+        request = null;
+        response = null;
+    }
+
+
+    public boolean useSession() {
+        return useSession;
+    }
 
     public Writer getWriter() {
         try{
             return response.getWriter();
        }catch(IOException ioe){
-                       return null;
+               return null;
        }
     }
 }

Modified: 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptContext.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptContext.java?rev=758103&r1=758102&r2=758103&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptContext.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptContext.java
 Wed Mar 25 00:35:59 2009
@@ -37,18 +37,18 @@
  * @author Sanka Samaranayake  <sa...@opensource.lk>
  */
 public interface HttpScriptContext extends ScriptContext {
-       
-       // TODO: Workout what these scope values need to be
-       
+
+    // TODO: Workout what these scope values need to be
+
     /** Integer value for the level of SCRIPT_SCOPE */
-       public static final int REQUEST_SCOPE = 0;
-    
-       /** Integer value for the level of SESSION_SCOPE */   
-       public static final int SESSION_SCOPE = 300;
-    
-       /** Integer value for the level of APPLICATION_SCOPE */
-       public static final int APPLICATION_SCOPE = 400;
-    
+    public static final int REQUEST_SCOPE = 0;
+
+    /** Integer value for the level of SESSION_SCOPE */   
+    public static final int SESSION_SCOPE = 300;
+
+    /** Integer value for the level of APPLICATION_SCOPE */
+    public static final int APPLICATION_SCOPE = 400;
+
     /**
      * Retrieves a boolean value which indicates whether the script 
      * execution has been disabled in the Web Application.
@@ -57,7 +57,7 @@
      *         allowed
      */
     public boolean disableScript();
-    
+
     /**
      * Retrieves a boolean value which indicates whether the
      * HttpScriptServlet executing in this context should display the
@@ -67,7 +67,7 @@
      *         eveluations should be displayed
      */
     public boolean displayResults();
-    
+
     /**
      * Forwards the request to the resource identified by the 
      * specified relative path.
@@ -79,7 +79,7 @@
      */
     public void forward(String relativePath) 
             throws ServletException, IOException;
-    
+
     /**
      * Retrieves an array of Strings describing the languages that may
      * be used by scripts which is running in the associated 
@@ -88,7 +88,7 @@
      * @return a String array of permitted languages 
      */
     public String[] getAllowedLanguages();
-    
+
     /**
      * Retrieves the value for the specified key in the lowest scope 
      * in which the key is defined. Returns null if the specified key
@@ -98,7 +98,7 @@
      * @return the value associated with the specified key
      */
     public Object getAttribute(String name);
-    
+
     /**
      * Retrieves the value associated with the specified key in 
      * specified level of scope. 
@@ -111,7 +111,7 @@
      */
     public Object getAttribute(String name,int scope) throws 
             IllegalArgumentException;
-    
+
     /**
      * Retrieves an array of string describing HTTP request methods 
      * which are handled by servlets executing in current context.
@@ -120,7 +120,7 @@
      *         servelts in the current context
      */
     public String[] getMethods();
-    
+
     /**
      * Retrieves a HttpScriptRequest for the current request. If the
      * session state is disabled, an adapter whose getSession() 
@@ -129,14 +129,14 @@
      * @return the current request
      */
     public HttpServletRequest getRequest();
-    
+
     /**
      * Retrieves a HttpScriptResponse for the current request.
      * 
      * @return the current response
      */
     public HttpServletResponse getResponse();
-    
+
     /**
      * Retrieves a reader form which the executing script can be 
      * read.
@@ -144,14 +144,14 @@
      * @return a reader from which the script can be read.
      */
     public Reader getScriptSource();
-    
+
     /**
      * Retrieves the associated HttpScriptServlet.
      * 
      * @return a reader form which the script source can be read
      */
     public Servlet getServlet();
-    
+
     /**
      * Includes the resource in the sepcified relative path.
      *  
@@ -163,7 +163,7 @@
      */
     public void include(String relativePath) throws IOException, 
             ServletException;
-    
+
     /**
      * Initialize the current HttpScriptContext for processing of 
      * single request. Implementation must initialize request, 
@@ -176,16 +176,16 @@
      * @throws ServletException if the servlet cannot handle the HTTP
      *         request
      */
-       public void initialize(Servlet servlet,
-                       HttpServletRequest req,HttpServletResponse res) throws 
+    public void initialize(Servlet servlet,
+            HttpServletRequest req,HttpServletResponse res) throws 
             ServletException;
 
-       /**
+    /**
      * Clears any state stored in the current HttpScriptContext such 
      * that it can be reused to serve another request.
      */
     public void release();
-       
+
     /**
      * Sets the value for the specified key in the specified level of
      * scope.
@@ -199,7 +199,7 @@
      *         or diabled
      */
     public void setAttribute(String name,Object value,int scope);
-    
+
     /**
      * Retrieves a boolean value which indicates whether the 
      * HttpSession associated with the current request is exposed in 
@@ -208,5 +208,5 @@
      * @return a boolean value which indicates whether the session is
      *         vaild 
      */
-       public boolean useSession();
+    public boolean useSession();
 }

Modified: 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptRequest.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptRequest.java?rev=758103&r1=758102&r2=758103&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptRequest.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptRequest.java
 Wed Mar 25 00:35:59 2009
@@ -31,18 +31,18 @@
  * @author Sanka Samaranayake <sa...@opensource.lk>
  */
 public class HttpScriptRequest extends HttpServletRequestWrapper {
-    
-       private final HttpScriptContext context;
-    
+
+    private final HttpScriptContext context;
+
     public HttpScriptRequest(HttpScriptContext context, HttpServletRequest 
req){
         super(req);
         this.context = context;
     }
-    
+
     public RequestDispatcher getRequestDispatcher(String path) {
         return null;
     }
-    
+
     public HttpSession getSession() {
         return (context.useSession()) ? super.getSession() : null;
     }

Modified: 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptServlet.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptServlet.java?rev=758103&r1=758102&r2=758103&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptServlet.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/HttpScriptServlet.java
 Wed Mar 25 00:35:59 2009
@@ -42,27 +42,27 @@
  * @author Sanka Samaranayake  <sa...@opensource.lk>
  */
 public class HttpScriptServlet extends GenericServlet {
-       private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-       public HttpScriptServlet(){
+    public HttpScriptServlet(){
     }
-   
-       /**
+
+    /**
      * Retrieves a HttpScriptContext initialized using specified 
      * HttpServletRequest, HttpServletResponse and a reference to 
      * this HttpScriptServlet.
      * 
-        * @param req the supplied HttpServletRequest instance
-        * @param res the supplied HttpServletResponse instance
-        * @return an initialized HttpScriptContext
-        * @throws ServletException if an error occurs
-        */
+     * @param req the supplied HttpServletRequest instance
+     * @param res the supplied HttpServletResponse instance
+     * @return an initialized HttpScriptContext
+     * @throws ServletException if an error occurs
+     */
     public HttpScriptContext getContext(HttpServletRequest req,
-                       HttpServletResponse res) throws ServletException {
-       
-       return null; // TODO
+            HttpServletResponse res) throws ServletException {
+
+        return null; // TODO
     }
-       
+
     /**
      * Returns a ScriptEngine instance which is used by the 
      * HttpScriptServlet to executes a single request.
@@ -71,10 +71,10 @@
      * @return an instance of a ScriptEngine which is used by the 
      *         HttpScriptServlet to executes a single request
      */
-       public ScriptEngine getEngine(HttpServletRequest req) {
-       return null; // TODO            
-       }
-       
+    public ScriptEngine getEngine(HttpServletRequest req) {
+       return null; // TODO        
+    }
+
     /**
      * Called to indicate that the ScriptEngine returned by call to
      * getEngine() is no longer in use.
@@ -82,9 +82,9 @@
      * @param eng the ScriptEngine which is no longer in use
      */
     public void releaseEngine(ScriptEngine eng) {
-       
+
     }
-    
+
     /**
      * Executes a script using the HttpScriptContext obtained by a 
      * call to getContext() and the ScriptEngine obtained by a call
@@ -99,55 +99,55 @@
      * @throws ServletException if error occurs in processing the 
      *         request
      */
-       public void service(ServletRequest req,ServletResponse res)
-                         throws IllegalArgumentException, IOException, 
ServletException {
-        
+    public void service(ServletRequest req,ServletResponse res)
+              throws IllegalArgumentException, IOException, ServletException {
+
         HttpServletRequest request;
         HttpServletResponse response;
         HttpScriptContext context;
         ScriptEngine engine;
         Object retValue;
-        
+
         if( !(req instanceof HttpServletRequest) || 
                     !(res instanceof HttpServletResponse)){
             throw new IllegalArgumentException(
                     "Method arguments should be HttpServletRequest and " +
                     "HttpServletResponse type");
         }
-        
+
         request = (HttpServletRequest)req;
         response =(HttpServletResponse)res;
-        
+
         context = getContext(request, response);
         if (context.disableScript()) {
             response.setStatus(HttpServletResponse.SC_FORBIDDEN);
             return;
         }
-        
+
         String requestMethod = request.getMethod();
         String[] allowedMethods = context.getMethods();
         int score;
-        
+
         for (score=0; score<allowedMethods.length; score++ ) {
             if (requestMethod.equalsIgnoreCase(allowedMethods[score])) {
                 break;                
             }
         }
-        
+
         if (score == allowedMethods.length) {
             response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
             return;
         }
-        
+
         engine = getEngine(request);
-        
+
         String[] languages = context.getAllowedLanguages();
         List names     = engine.getFactory().getNames();
-        
+
         if (languages != null) {
-            
+
             boolean found = false;
-            
+
             for (int i=0; i<languages.length; i++) {
                 for (int j=0; j<names.size(); j++) {
                     if (languages[i].equals(names.get(i))) {
@@ -155,44 +155,44 @@
                     }
                 }
             }
-            
+
             if (!found) {
                 response.setStatus(HttpServletResponse.SC_FORBIDDEN);
                 return;                
             }
         }
-      
+
         try {
-                          
-               Reader reader = context.getScriptSource();
+
+            Reader reader = context.getScriptSource();
             if (reader == null) {
                 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
                 return;
             }
-            
+
             engine.put("javax.script.filename", request.getRequestURI());
             engine.put("Request", context.getRequest());
             engine.put("Response",context.getResponse());
             engine.put("Servlet", context.getServlet());
             engine.put("Context", context);
-            
+
             retValue = engine.eval(reader, context);
-            
+
             response.setContentType("text/html");
             if ((retValue != null) && (context.displayResults())) {
                 response.getWriter().write(retValue.toString());
             }
-            
+
             response.getWriter().close();
           } catch (ScriptException se) {
-  
-               
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+
+              response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
             throw new ServletException(se);
-            
+
         } finally {
-   
+
             releaseEngine(engine);
             context.release();
         }
-       }
+    }
 }

Modified: 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/ScriptEnginePool.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/ScriptEnginePool.java?rev=758103&r1=758102&r2=758103&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/ScriptEnginePool.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-utils/src/main/java/org/apache/bsf/utils/http/ScriptEnginePool.java
 Wed Mar 25 00:35:59 2009
@@ -33,11 +33,11 @@
     private final int capacity;
     private final ScriptEngineFactory factory;
     private final boolean isMultithreaded;
-    
+
     public ScriptEnginePool(ScriptEngineFactory factory, int capacity){
-       this.factory = factory;
+        this.factory = factory;
         this.capacity = capacity;
-        
+
         String param = (String)factory.getParameter("THREADING");
         if (param != null && param.equals("MULTITHREADED")) {
             this.isMultithreaded = true;
@@ -46,16 +46,16 @@
             this.isMultithreaded = false;
         }
     }
-    
+
     public ScriptEnginePool(ScriptEngineFactory factory){
         this(factory,DEFAULT_SIZE);
      }
-       
+
     public synchronized void free(ScriptEngine eng){
         pool.add(eng); // should I clear the engine namespaces .. 
         notifyAll();
     }
-    
+
     public synchronized ScriptEngine get(){
         if (isMultithreadingSupported()) {
             return (ScriptEngine) pool.getFirst();
@@ -77,9 +77,9 @@
             }
         }
     }
-    
+
     public boolean isMultithreadingSupported(){
         return this.isMultithreaded;
     }
-    
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: bsf-dev-h...@jakarta.apache.org

Reply via email to