You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by vv...@apache.org on 2015/08/07 11:54:38 UTC
svn commit: r1694640 - in /felix/trunk/webconsole-plugins/upnp: pom.xml
src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/Activator.java
src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ConfigurationPrinterImpl.java
Author: vvalchev
Date: Fri Aug 7 09:54:37 2015
New Revision: 1694640
URL: http://svn.apache.org/r1694640
Log:
Fixed FELIX-4997 : UPnP plugin should use Inventory instead of deprecated ConfigurationPrinter
https://issues.apache.org/jira/browse/FELIX-4997
Modified:
felix/trunk/webconsole-plugins/upnp/pom.xml
felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/Activator.java
felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ConfigurationPrinterImpl.java
Modified: felix/trunk/webconsole-plugins/upnp/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/upnp/pom.xml?rev=1694640&r1=1694639&r2=1694640&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/upnp/pom.xml (original)
+++ felix/trunk/webconsole-plugins/upnp/pom.xml Fri Aug 7 09:54:37 2015
@@ -126,6 +126,12 @@
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.inventory</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
Modified: felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/Activator.java?rev=1694640&r1=1694639&r2=1694640&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/Activator.java (original)
+++ felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/Activator.java Fri Aug 7 09:54:37 2015
@@ -16,7 +16,11 @@
*/
package org.apache.felix.webconsole.plugins.upnp.internal;
-import org.apache.felix.webconsole.ConfigurationPrinter;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -78,8 +82,16 @@ public class Activator implements Bundle
if (plugin == null)
{
this.plugin = plugin = new WebConsolePlugin(tracker).register(context);
- printerRegistration = context.registerService(ConfigurationPrinter.SERVICE,
- new ConfigurationPrinterImpl(tracker), null);
+
+ // register configuration printer
+ final Dictionary/*<String, Object>*/ props = new Hashtable/*<String, Object>*/();
+ props.put(InventoryPrinter.NAME, "upnp"); //$NON-NLS-1$
+ props.put(InventoryPrinter.TITLE, "UPnP Devices"); //$NON-NLS-1$
+ props.put(InventoryPrinter.FORMAT,
+ new String[] { Format.TEXT.toString(), Format.JSON.toString() });
+
+ printerRegistration = context.registerService(InventoryPrinter.SERVICE,
+ new ConfigurationPrinterImpl(tracker), props);
}
return context.getService(reference);
Modified: felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ConfigurationPrinterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ConfigurationPrinterImpl.java?rev=1694640&r1=1694639&r2=1694640&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ConfigurationPrinterImpl.java (original)
+++ felix/trunk/webconsole-plugins/upnp/src/main/java/org/apache/felix/webconsole/plugins/upnp/internal/ConfigurationPrinterImpl.java Fri Aug 7 09:54:37 2015
@@ -21,8 +21,12 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.TreeMap;
-import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
import org.apache.felix.webconsole.WebConsoleUtil;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.upnp.UPnPAction;
@@ -35,7 +39,7 @@ import org.osgi.util.tracker.ServiceTrac
* Prints the available UPnP devices
*
*/
-class ConfigurationPrinterImpl implements ConfigurationPrinter, Constants
+class ConfigurationPrinterImpl implements InventoryPrinter, Constants
{
private final ServiceTracker tracker;
@@ -46,18 +50,12 @@ class ConfigurationPrinterImpl implement
}
/**
- * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+ * @see org.apache.felix.inventory.InventoryPrinter
+ * #print(java.io.PrintWriter, org.apache.felix.inventory.Format, boolean)
*/
- public String getTitle()
+ public void print(PrintWriter pw, Format format, boolean isZip)
{
- return "UPnP Devices"; //$NON-NLS-1$
- }
- /**
- * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
- */
- public void printConfiguration(PrintWriter pw)
- {
TreeMap componentMap = new TreeMap();
ServiceReference[] refs = tracker.getServiceReferences();
@@ -67,9 +65,50 @@ class ConfigurationPrinterImpl implement
if (null != ref.getProperty(UPnPDevice.UDN)) // make sure device is valid
{
// order components by friendly name
- componentMap.put(nameOf(ref).toString() + ref.getProperty(SERVICE_ID), ref);
+ componentMap.put(nameOf(ref).toString() + ref.getProperty(SERVICE_ID),
+ ref);
+ }
+ }
+
+ if (Format.JSON.equals(format))
+ {
+ try
+ {
+ printJSON(componentMap, pw);
+ }
+ catch (JSONException e)
+ {
+ printText(componentMap, pw);
}
}
+ else
+ {
+ printText(componentMap, pw);
+ }
+ }
+
+ private void printJSON(TreeMap componentMap, PrintWriter pw) throws JSONException
+ {
+ final JSONObject ret = new JSONObject();
+ final JSONArray jDevices = new JSONArray();
+ ret.put("devices", jDevices); //$NON-NLS-1$
+
+ // render components
+ for (Iterator ci = componentMap.values().iterator(); ci.hasNext();)
+ {
+ final ServiceReference ref = (ServiceReference) ci.next();
+ final UPnPDevice device = (UPnPDevice) tracker.getService(ref);
+ if (device != null)
+ {
+ jDevices.put(Serializer.deviceToJSON(ref, device));
+ }
+ }
+
+ ret.write(pw);
+ }
+
+ private void printText(TreeMap componentMap, PrintWriter pw)
+ {
if (componentMap.isEmpty())
{
@@ -201,4 +240,6 @@ class ConfigurationPrinterImpl implement
pw.println();
}
+
+
}