FELIX-2123 Introduce new WebConsoleUtil.urlDecode method to hide the fact that some platforms do not provide the Java 1.4 URLDecoder.decode(String, String) method.
(Also change the ZIP compression for zipped configuration status download to "best speed"
which still gives good compression but is much faster)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@918391 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
index 2b4f098..850ee4d 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
@@ -20,6 +20,7 @@
 
 
 import java.io.IOException;
+import java.net.URLDecoder;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -333,4 +334,31 @@
         }
     }
 
+
+    /**
+     * Decode the given value expected to be URL encoded.
+     * <p>
+     * This method first tries to use the Java 1.4 method
+     * <code>URLDecoder.decode(String, String)</code> method and falls back to
+     * the now deprecated <code>URLDecoder.decode(String, String)</code>
+     * which uses the platform character set to decode the string. This is
+     * because the platforms before 1.4 and most notably some OSGi Execution
+     * Environments (such as Minimum EE) do not provide the newer method.
+     *
+     * @param value
+     * @return
+     */
+    public static String urlDecode( final String value )
+    {
+        try
+        {
+            return URLDecoder.decode( value, "UTF-8" );
+        }
+        catch ( Throwable t )
+        {
+            // expected NoSuchMethodError: if platform does not support it
+            // expected UnsupportedEncoding (not really: UTF-8 is required)
+            return URLDecoder.decode( value );
+        }
+    }
 }
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
index cd85060..1527cd6 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
@@ -19,9 +19,9 @@
 
 import java.io.*;
 import java.net.URL;
-import java.net.URLDecoder;
 import java.text.*;
 import java.util.*;
+import java.util.zip.Deflater;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
@@ -113,7 +113,7 @@
             response.setContentType( type );
 
             ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
-            zip.setLevel( 9 );
+            zip.setLevel( Deflater.BEST_SPEED );
             zip.setMethod( ZipOutputStream.DEFLATED );
 
             final ConfigurationWriter pw = new ZipConfigurationWriter( zip );
@@ -131,7 +131,7 @@
             String name = request.getPathInfo();
             name = name.substring( name.lastIndexOf('/') + 1);
             name = name.substring(0, name.length() - 4);
-            name = URLDecoder.decode( name, "UTF-8" );
+            name = WebConsoleUtil.urlDecode( name );
 
             ConfigurationWriter pw = new HtmlConfigurationWriter( response.getWriter() );
             pw.println ( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" );
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java
index 4b35993..8798038 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ShellServlet.java
@@ -24,8 +24,6 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.net.URLDecoder;
-
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -74,7 +72,10 @@
         try
         {
             String command = request.getParameter( "command" );
-            if (command != null) command = URLDecoder.decode(command);
+            if ( command != null )
+            {
+                command = WebConsoleUtil.urlDecode( command );
+            }
 
             pw.print( "<span class=\"consolecommand\">-&gt; " );
             pw.print( command == null ? "" : WebConsoleUtil.escapeHtml( command ) );