You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2014/12/29 16:45:05 UTC

svn commit: r1648373 - in /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole: WebConsoleUtil.java internal/Util.java internal/core/BundlesServlet.java internal/core/ServicesServlet.java

Author: cziegeler
Date: Mon Dec 29 15:45:04 2014
New Revision: 1648373

URL: http://svn.apache.org/r1648373
Log:
FELIX-4738 : Deprecate WebConsoleUtil#keyVal

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java?rev=1648373&r1=1648372&r2=1648373&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java Mon Dec 29 15:45:04 2014
@@ -331,7 +331,7 @@ public final class WebConsoleUtil
      *
      * @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)

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java?rev=1648373&r1=1648372&r2=1648373&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java Mon Dec 29 15:45:04 2014
@@ -23,6 +23,8 @@ import java.util.Comparator;
 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 @@ public class Util
         }
         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 @@ public class Util
             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

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java?rev=1648373&r1=1648372&r2=1648373&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java Mon Dec 29 15:45:04 2014
@@ -456,7 +456,7 @@ public class BundlesServlet extends Simp
             super.doPost( req, resp );
         }
     }
-    
+
     private String getServicesRoot(HttpServletRequest request)
     {
         return ( ( String ) request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT ) ) +
@@ -800,24 +800,24 @@ public class BundlesServlet extends Simp
 
         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 @@ public class BundlesServlet extends Simp
                     }
                 }
             }
-            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 @@ public class BundlesServlet extends Simp
                 val.put( "None" );
             }
 
-            WebConsoleUtil.keyVal( jw, "Imported Packages", val );
+            Util.keyVal( jw, "Imported Packages", val );
         }
 
         if ( !usingBundles.isEmpty() )
@@ -1017,7 +1017,7 @@ public class BundlesServlet extends Simp
                 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 @@ public class BundlesServlet extends Simp
                     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 @@ public class BundlesServlet extends Simp
                     val.put( "---" );
                 }
 
-                WebConsoleUtil.keyVal( jw, "Imported Packages", val );
+                Util.keyVal( jw, "Imported Packages", val );
             }
         }
     }
@@ -1175,7 +1175,7 @@ public class BundlesServlet extends Simp
             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 @@ public class BundlesServlet extends Simp
             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 @@ public class BundlesServlet extends Simp
                 {
                     val.put( getBundleDescriptor( hostBundles[i], pluginRoot ) );
                 }
-                WebConsoleUtil.keyVal( jw, "Host Bundles", val );
+                Util.keyVal( jw, "Host Bundles", val );
             }
         }
         else
@@ -1244,7 +1244,7 @@ public class BundlesServlet extends Simp
                 {
                     val.put( getBundleDescriptor( fragmentBundles[i], pluginRoot ) );
                 }
-                WebConsoleUtil.keyVal( jw, "Fragments Attached", val );
+                Util.keyVal( jw, "Fragments Attached", val );
             }
         }
 

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java?rev=1648373&r1=1648372&r2=1648373&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java Mon Dec 29 15:45:04 2014
@@ -235,19 +235,19 @@ public class ServicesServlet extends Sim
             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 ) );
             }
 
         }