Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 91F941869A for ; Fri, 7 Aug 2015 09:54:41 +0000 (UTC) Received: (qmail 68783 invoked by uid 500); 7 Aug 2015 09:54:38 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 68741 invoked by uid 500); 7 Aug 2015 09:54:38 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 68732 invoked by uid 99); 7 Aug 2015 09:54:38 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Aug 2015 09:54:38 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 40621AC0335 for ; Fri, 7 Aug 2015 09:54:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Fri, 07 Aug 2015 09:54:38 -0000 To: commits@felix.apache.org From: vvalchev@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150807095438.40621AC0335@hades.apache.org> 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 @@ 3.1.0 provided + + org.apache.felix + org.apache.felix.inventory + 1.0.0 + provided + org.json json 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/**/ props = new Hashtable/**/(); + 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(); } + + }