FELIX-4738 : Deprecate WebConsoleUtil#keyVal

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1648373 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 d7ae364..ea60515 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
@@ -331,7 +331,7 @@
      *
      * @deprecated Plugins should use their own json code/library
      */
-    public static final void keyVal(JSONWriter jw, String key, Object value)
+    public static final void keyVals(JSONWriter jw, String key, Object value)
         throws JSONException
     {
         if (key != null && value != null)
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
index c90cb63..eace029 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
@@ -23,6 +23,8 @@
 import java.util.Enumeration;
 import java.util.Locale;
 
+import org.json.JSONException;
+import org.json.JSONWriter;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
@@ -142,12 +144,12 @@
         }
         return l;
     }
-    
+
     /**
      * This method expects a locale string in format language_COUNTRY, or
      * language. The method will determine which is the correct form of locale
      * string and construct a <code>Locale</code> object.
-     * 
+     *
      * @param locale the locale string, if <code>null</code> - default locale is
      *          returned
      * @return a locale object
@@ -242,4 +244,27 @@
             return 1;
         }
     }
+
+    /**
+     * Writes a key-value pair in a JSON writer. Write is performed only if both key and
+     * value are not null.
+     *
+     * @param jw the writer, where to write the data
+     * @param key the key value, stored under 'key'
+     * @param value the value stored under 'value'
+     * @throws JSONException if the value cannot be serialized.
+     */
+    public static final void keyVal(JSONWriter jw, String key, Object value)
+        throws JSONException
+    {
+        if (key != null && value != null)
+        {
+            jw.object();
+            jw.key("key"); //$NON-NLS-1$
+            jw.value(key);
+            jw.key("value"); //$NON-NLS-1$
+            jw.value(value);
+            jw.endObject();
+        }
+    }
 }
\ No newline at end of file
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index 682405f..7b60b9f 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -456,7 +456,7 @@
             super.doPost( req, resp );
         }
     }
-    
+
     private String getServicesRoot(HttpServletRequest request)
     {
         return ( ( String ) request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT ) ) +
@@ -800,24 +800,24 @@
 
         jw.key( "props" );
         jw.array();
-        WebConsoleUtil.keyVal( jw, "Symbolic Name", bundle.getSymbolicName() );
-        WebConsoleUtil.keyVal( jw, "Version", headers.get( Constants.BUNDLE_VERSION ) );
-        WebConsoleUtil.keyVal( jw, "Bundle Location", bundle.getLocation() );
-        WebConsoleUtil.keyVal( jw, "Last Modification", new Date( bundle.getLastModified() ) );
+        Util.keyVal( jw, "Symbolic Name", bundle.getSymbolicName() );
+        Util.keyVal( jw, "Version", headers.get( Constants.BUNDLE_VERSION ) );
+        Util.keyVal( jw, "Bundle Location", bundle.getLocation() );
+        Util.keyVal( jw, "Last Modification", new Date( bundle.getLastModified() ) );
 
         String docUrl = ( String ) headers.get( Constants.BUNDLE_DOCURL );
         if ( docUrl != null )
         {
-            WebConsoleUtil.keyVal( jw, "Bundle Documentation", docUrl );
+            Util.keyVal( jw, "Bundle Documentation", docUrl );
         }
 
-        WebConsoleUtil.keyVal( jw, "Vendor", headers.get( Constants.BUNDLE_VENDOR ) );
-        WebConsoleUtil.keyVal( jw, "Copyright", headers.get( Constants.BUNDLE_COPYRIGHT ) );
-        WebConsoleUtil.keyVal( jw, "Description", headers.get( Constants.BUNDLE_DESCRIPTION ) );
+        Util.keyVal( jw, "Vendor", headers.get( Constants.BUNDLE_VENDOR ) );
+        Util.keyVal( jw, "Copyright", headers.get( Constants.BUNDLE_COPYRIGHT ) );
+        Util.keyVal( jw, "Description", headers.get( Constants.BUNDLE_DESCRIPTION ) );
 
-        WebConsoleUtil.keyVal( jw, "Start Level", getStartLevel( bundle ) );
+        Util.keyVal( jw, "Start Level", getStartLevel( bundle ) );
 
-        WebConsoleUtil.keyVal( jw, "Bundle Classpath", headers.get( Constants.BUNDLE_CLASSPATH ) );
+        Util.keyVal( jw, "Bundle Classpath", headers.get( Constants.BUNDLE_CLASSPATH ) );
 
         listFragmentInfo( jw, bundle, pluginRoot );
 
@@ -948,11 +948,11 @@
                     }
                 }
             }
-            WebConsoleUtil.keyVal( jw, "Exported Packages", val );
+            Util.keyVal( jw, "Exported Packages", val );
         }
         else
         {
-            WebConsoleUtil.keyVal( jw, "Exported Packages", "---" );
+            Util.keyVal( jw, "Exported Packages", "---" );
         }
 
         exports = packageAdmin.getExportedPackages( ( Bundle ) null );
@@ -1006,7 +1006,7 @@
                 val.put( "None" );
             }
 
-            WebConsoleUtil.keyVal( jw, "Imported Packages", val );
+            Util.keyVal( jw, "Imported Packages", val );
         }
 
         if ( !usingBundles.isEmpty() )
@@ -1017,7 +1017,7 @@
                 Bundle usingBundle = ( Bundle ) ui.next();
                 val.put( getBundleDescriptor( usingBundle, pluginRoot ) );
             }
-            WebConsoleUtil.keyVal( jw, "Importing Bundles", val );
+            Util.keyVal( jw, "Importing Bundles", val );
         }
     }
 
@@ -1053,11 +1053,11 @@
                     Clause export = new Clause( pkgs[i].getName(), pkgs[i].getDirectives(), pkgs[i].getAttributes() );
                     collectExport( val, export.getName(), export.getAttribute( Constants.VERSION_ATTRIBUTE ) );
                 }
-                WebConsoleUtil.keyVal( jw, "Exported Packages", val );
+                Util.keyVal( jw, "Exported Packages", val );
             }
             else
             {
-                WebConsoleUtil.keyVal( jw, "Exported Packages", "---" );
+                Util.keyVal( jw, "Exported Packages", "---" );
             }
         }
 
@@ -1127,7 +1127,7 @@
                     val.put( "---" );
                 }
 
-                WebConsoleUtil.keyVal( jw, "Imported Packages", val );
+                Util.keyVal( jw, "Imported Packages", val );
             }
         }
     }
@@ -1175,7 +1175,7 @@
             appendProperty( val, refs[i], Constants.SERVICE_DESCRIPTION, "Description" );
             appendProperty( val, refs[i], Constants.SERVICE_VENDOR, "Vendor" );
 
-            WebConsoleUtil.keyVal( jw, key, val);
+            Util.keyVal( jw, key, val);
         }
     }
 
@@ -1196,7 +1196,7 @@
             val.put( header + ": " + value );
         }
 
-        WebConsoleUtil.keyVal( jw, "Manifest Headers", val );
+        Util.keyVal( jw, "Manifest Headers", val );
     }
 
     private static final String enableLineWrapping(final String value)
@@ -1231,7 +1231,7 @@
                 {
                     val.put( getBundleDescriptor( hostBundles[i], pluginRoot ) );
                 }
-                WebConsoleUtil.keyVal( jw, "Host Bundles", val );
+                Util.keyVal( jw, "Host Bundles", val );
             }
         }
         else
@@ -1244,7 +1244,7 @@
                 {
                     val.put( getBundleDescriptor( fragmentBundles[i], pluginRoot ) );
                 }
-                WebConsoleUtil.keyVal( jw, "Fragments Attached", val );
+                Util.keyVal( jw, "Fragments Attached", val );
             }
         }
 
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
index 319944e..146381d 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
@@ -235,19 +235,19 @@
             String key = keys[i];
             if ( Constants.SERVICE_PID.equals( key ) )
             {
-                WebConsoleUtil.keyVal( jw, "Service PID", service.getProperty( key ) );
+                Util.keyVal( jw, "Service PID", service.getProperty( key ) );
             }
             else if ( Constants.SERVICE_DESCRIPTION.equals( key ) )
             {
-                WebConsoleUtil.keyVal( jw, "Service Description", service.getProperty( key ) );
+                Util.keyVal( jw, "Service Description", service.getProperty( key ) );
             }
             else if ( Constants.SERVICE_VENDOR.equals( key ) )
             {
-                WebConsoleUtil.keyVal( jw, "Service Vendor", service.getProperty( key ) );
+                Util.keyVal( jw, "Service Vendor", service.getProperty( key ) );
             }
             else if ( !Constants.OBJECTCLASS.equals( key ) && !Constants.SERVICE_ID.equals( key ) )
             {
-                WebConsoleUtil.keyVal( jw, key, service.getProperty( key ) );
+                Util.keyVal( jw, key, service.getProperty( key ) );
             }
 
         }