EXTSCRIPT-166 fixing up the encoding code for the url handling so that it should work properly no matter which system

git-svn-id: https://svn.apache.org/repos/asf/myfaces/extensions/scripting/trunk@1362077 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/common/util/ClassLoaderUtils.java b/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/common/util/ClassLoaderUtils.java
index 221a736..ef23e99 100644
--- a/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/common/util/ClassLoaderUtils.java
+++ b/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/common/util/ClassLoaderUtils.java
@@ -27,6 +27,7 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -93,7 +94,7 @@
         for (URL url : urls) {
             try
             {
-                classpath.append(URLDecoder.decode(url.getPath(), "UTF-8"));
+                classpath.append(URLDecoder.decode(url.getPath(), Charset.defaultCharset().toString()));
                 // Note that the classpath separator character is platform
                 // dependent. On Windows systems it's ";" whereas on other
                 // UNIX systems it's ":".
diff --git a/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java b/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java
index f245f52..c887348 100644
--- a/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java
+++ b/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseEngine.java
@@ -31,6 +31,7 @@
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -238,7 +239,8 @@
             URL resource = ClassUtils.getContextClassLoader().getResource("./");
             try
             {
-                pathSeparatedList = FilenameUtils.normalize(URLDecoder.decode(resource.getPath(),"UTF-8")
+                pathSeparatedList = FilenameUtils.normalize(URLDecoder.decode(resource.getPath(),
+                        Charset.defaultCharset().toString())
                         + "../.." + defaultValue);
             }
             catch (UnsupportedEncodingException e)
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompilerTest.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompilerTest.java
index 3eaf821..58eda6b 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompilerTest.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompilerTest.java
@@ -29,9 +29,12 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -70,7 +73,17 @@
         //and the ide cannot cope with resource paths for now
         ClassLoader loader = Thread.currentThread().getContextClassLoader();
 
-        String currentPath = URLDecoder.decode(loader.getResource("./").getPath());
+        String currentPath = null;
+
+        try
+        {
+            currentPath = URLDecoder.decode(loader.getResource("./").getPath(),
+                    Charset.defaultCharset().toString());
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            fail(e.getMessage());
+        }
         String sourcePath1 = currentPath + PROBE1;
         String sourcePath2 = currentPath + PROBE2;
         String rootPath = currentPath + RESOURCES;
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JavaCompilerTest.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JavaCompilerTest.java
index fc716d1..1f967a8 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JavaCompilerTest.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JavaCompilerTest.java
@@ -38,11 +38,14 @@
 import javax.tools.ToolProvider;
 import java.io.File;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Locale;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -79,7 +82,15 @@
         //and the ide cannot cope with resource paths for now
         ClassLoader loader = Thread.currentThread().getContextClassLoader();
 
-        String currentPath = URLDecoder.decode(loader.getResource("./").getPath());
+        String currentPath = null;
+        try
+        {
+            currentPath = URLDecoder.decode(loader.getResource("./").getPath(), Charset.defaultCharset().toString());
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            fail(e.getMessage());
+        }
         String sourcePath1 = currentPath + PROBE1;
         String sourcePath2 = currentPath + PROBE2;
         String rootPath = currentPath + RESOURCES;
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ScalaCompilerTest.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ScalaCompilerTest.java
index 8bb866f..a71dea0 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ScalaCompilerTest.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ScalaCompilerTest.java
@@ -32,9 +32,12 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -71,7 +74,17 @@
         //and the ide cannot cope with resource paths for now
         ClassLoader loader = Thread.currentThread().getContextClassLoader();
 
-        String currentPath = URLDecoder.decode(loader.getResource("./").getPath());
+        String currentPath = null;
+
+        try
+        {
+            currentPath = URLDecoder.decode(loader.getResource("./").getPath(), Charset.defaultCharset().toString());
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            fail(e.getMessage());
+        }
+
         String sourcePath1 = currentPath + PROBE1;
         String sourcePath2 = currentPath + PROBE2;
         String rootPath = currentPath + RESOURCES;
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java
index 38ae7ff..3c82d1f 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/AbstractGeneratorTestCase.java
@@ -25,6 +25,7 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 
 /**
  * <p>Base class for test cases that generate Java source files.</p>
@@ -46,7 +47,7 @@
     public void setUp() throws Exception {
         // Create the test directory within the directory that the class file of this test case is located in
         testDirectory =
-                new File(URLDecoder.decode(getClass().getResource(".").toURI().getPath()), "test");
+                new File(URLDecoder.decode(getClass().getResource(".").toURI().getPath(), Charset.defaultCharset().toString()), "test");
         if (!testDirectory.mkdirs() && !testDirectory.exists()) {
             throw new IllegalStateException(
                     "Couldn't setup the test case for the test case '" + getClass().getName()
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java
index 80fb367..330d8ba 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/MockServletContext.java
@@ -24,8 +24,10 @@
 import org.apache.myfaces.extensions.scripting.jsf.startup.StartupServletContextPluginChainLoader;
 
 import java.io.File;
+import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -99,11 +101,18 @@
     public void setResourceRoot(String newRoot)
     {
         _resourceRoot = newRoot;
-        super.setDocumentRoot(new File(FilenameUtils.normalize(URLDecoder.decode(Thread.currentThread()
-                .getContextClassLoader()
-                .getResource("./")
-                .getPath()) +
-                _resourceRoot)));
+        try
+        {
+            super.setDocumentRoot(new File(FilenameUtils.normalize(URLDecoder.decode(Thread.currentThread()
+                    .getContextClassLoader()
+                    .getResource("./")
+                    .getPath(), Charset.defaultCharset().toString()) +
+                    _resourceRoot)));
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            throw new RuntimeException(e);
+        }
     }
 
 }
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java
index 0e6b269..d4506bc 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/PathUtils.java
@@ -20,7 +20,9 @@
 package org.apache.myfaces.extensions.scripting.core.support;
 
 import java.io.File;
+import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.nio.charset.Charset;
 
 /**
  * Supportive utils to access the source
@@ -40,7 +42,14 @@
         //we use a location relative to our current root one to reach the sources
         //because the test also has to be performed outside of maven
         //and the ide cannot cope with resource paths for now
-        _currentPath = URLDecoder.decode(loader.getResource("./").getPath());
+        try
+        {
+            _currentPath = URLDecoder.decode(loader.getResource("./").getPath(), Charset.defaultCharset().toString());
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            throw new RuntimeException(e);
+        }
         _resourceRoot = _currentPath + "../../src/test/resources";
     }