You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sa...@apache.org on 2012/04/03 15:36:04 UTC

svn commit: r1308896 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java

Author: sascharodekamp
Date: Tue Apr  3 13:36:03 2012
New Revision: 1308896

URL: http://svn.apache.org/viewvc?rev=1308896&view=rev
Log:
Changed the FileReader to a BufferedReader during script loading. The file reader throws an exception when the file path contains spaces (which are encoded). The result was that scripts aren't loaded and pages only showed an error message. Working with an InputStream solves this issue.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java?rev=1308896&r1=1308895&r2=1308896&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ScriptUtil.java Tue Apr  3 13:36:03 2012
@@ -18,10 +18,11 @@
  *******************************************************************************/
 package org.ofbiz.base.util;
 
+import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.FileReader;
-import java.net.MalformedURLException;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.Collection;
 import java.util.Collections;
@@ -115,12 +116,11 @@ public final class ScriptUtil {
      * 
      * @param filePath Script path and file name.
      * @return The compiled script, or <code>null</code> if the script engine does not support compilation.
-     * @throws FileNotFoundException
      * @throws IllegalArgumentException
      * @throws ScriptException
-     * @throws MalformedURLException
+     * @throws IOException
      */
-    public static CompiledScript compileScriptFile(String filePath) throws FileNotFoundException, ScriptException, MalformedURLException {
+    public static CompiledScript compileScriptFile(String filePath) throws ScriptException, IOException {
         Assert.notNull("filePath", filePath);
         CompiledScript script = parsedScripts.get(filePath);
         if (script == null) {
@@ -132,7 +132,7 @@ public final class ScriptUtil {
             try {
                 Compilable compilableEngine = (Compilable) engine;
                 URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
-                FileReader reader = new FileReader(new File(scriptUrl.getFile()));
+                BufferedReader reader = new BufferedReader(new InputStreamReader(scriptUrl.openStream()));
                 script = compilableEngine.compile(reader);
                 if (Debug.verboseOn()) {
                     Debug.logVerbose("Compiled script " + filePath + " using engine " + engine.getClass().getName(), module);
@@ -345,13 +345,12 @@ public final class ScriptUtil {
      * @param scriptContext Script execution context.
      * @param args Function/method arguments.
      * @return The script result.
-     * @throws ScriptException 
-     * @throws MalformedURLException 
-     * @throws FileNotFoundException 
-     * @throws NoSuchMethodException 
+     * @throws ScriptException
+     * @throws NoSuchMethodException
+     * @throws IOException
      * @throws IllegalArgumentException
      */
-    public static Object executeScript(String filePath, String functionName, ScriptContext scriptContext, Object[] args) throws FileNotFoundException, MalformedURLException, ScriptException, NoSuchMethodException {
+    public static Object executeScript(String filePath, String functionName, ScriptContext scriptContext, Object[] args) throws ScriptException, NoSuchMethodException, IOException {
         Assert.notNull("filePath", filePath, "scriptContext", scriptContext);
         scriptContext.setAttribute(ScriptEngine.FILENAME, filePath, ScriptContext.ENGINE_SCOPE);
         if (functionName == null) {