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 2020/04/24 09:04:17 UTC

[felix-dev] branch master updated: FELIX-6268 : Add a link to the configuration json serializer if available

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new ab2c3ac  FELIX-6268 : Add a link to the configuration json serializer if available
ab2c3ac is described below

commit ab2c3ac3a570ba316daeb6368bab8193805f37c0
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Apr 24 11:04:03 2020 +0200

    FELIX-6268 : Add a link to the configuration json serializer if available
---
 .../internal/configuration/ConfigAdminSupport.java |  2 +-
 .../internal/configuration/ConfigManager.java      |  9 +++++++
 .../main/resources/OSGI-INF/l10n/bundle.properties |  1 +
 webconsole/src/main/resources/res/ui/config.css    |  2 +-
 webconsole/src/main/resources/res/ui/config.js     | 31 +++++++++++++++++-----
 .../src/main/resources/templates/config.html       |  3 ++-
 6 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
index da1fbd9..f676329 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigAdminSupport.java
@@ -64,7 +64,7 @@ class ConfigAdminSupport
 {
 
     private static final String PROPERTY_FACTORYCONFIG_NAMEHINT = "webconsole.configurationFactory.nameHint";
-    private static final Set CONFIG_PROPERTIES_HIDE = new HashSet();
+    private static final Set<String> CONFIG_PROPERTIES_HIDE = new HashSet<>();
     static {
         CONFIG_PROPERTIES_HIDE.add(PROPERTY_FACTORYCONFIG_NAMEHINT);
         CONFIG_PROPERTIES_HIDE.add(ConfigurationAdmin.SERVICE_BUNDLELOCATION);
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
index f932c38..c13cdf4 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -29,6 +30,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.felix.utils.json.JSONWriter;
 import org.apache.felix.webconsole.DefaultVariableResolver;
 import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.WebConsoleConstants;
 import org.apache.felix.webconsole.WebConsoleUtil;
 import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
 import org.osgi.framework.Constants;
@@ -112,6 +114,7 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
     /**
      * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
+    @Override
     protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws IOException
     {
         // needed multiple times below
@@ -207,6 +210,7 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
     /**
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
+    @Override
     protected void doGet( HttpServletRequest request, HttpServletResponse response )
             throws ServletException, IOException
     {
@@ -334,6 +338,7 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
     /**
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
+    @Override
     protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws IOException
     {
 
@@ -390,6 +395,10 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
         JSONWriter jw = new JSONWriter(json);
         jw.object();
         final ConfigAdminSupport ca = getConfigurationAdminSupport();
+        // check for osgi installer plugin
+        @SuppressWarnings("unchecked")
+        final Map<String, Object> labelMap = (Map<String, Object>) request.getAttribute(WebConsoleConstants.ATTR_LABEL_MAP);
+        jw.key("jsonsupport").value( labelMap.containsKey("osgi-installer-config-printer") ); //$NON-NLS-1$
         jw.key("status").value( ca != null ? Boolean.TRUE : Boolean.FALSE); //$NON-NLS-1$
         if ( ca != null )
         {
diff --git a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
index 6ce0351..5dd397b 100644
--- a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -191,6 +191,7 @@ config.factories.title=Factory Configurations
 config.configurations.title=Configurations
 config.create.tip=Create new factory configuration
 config.edit.tip=Edit the configuration values
+config.json.tip=Show configuration as JSON
 config.title.exists= ?\ 
 config.title.exists.tip=There is a real Configuration created. If the checkbox was missing, it would be either Managed Service or Meta-Type definition available but no configuration.
 config.title.actions=Actions
diff --git a/webconsole/src/main/resources/res/ui/config.css b/webconsole/src/main/resources/res/ui/config.css
index 3349c2c..141fa85 100644
--- a/webconsole/src/main/resources/res/ui/config.css
+++ b/webconsole/src/main/resources/res/ui/config.css
@@ -28,7 +28,7 @@ html>select { width: auto; min-width: 50em }
 	padding:0
 }
 .multiselect { display: block }
-.col_Actions { width: 7em !important }
+.col_Actions { width: 9em !important }
 .pointer { cursor: pointer }
 .subpid   { margin-left: 1em; float: left }
 tr.fpid   td   { font-style:italic }
diff --git a/webconsole/src/main/resources/res/ui/config.js b/webconsole/src/main/resources/res/ui/config.js
index 6177e14..ebe2b93 100644
--- a/webconsole/src/main/resources/res/ui/config.js
+++ b/webconsole/src/main/resources/res/ui/config.js
@@ -31,6 +31,9 @@ var factoryRow = false;
 var editor = false;
 var editorMessage = false;
 
+// json support
+var jsonSupport = false;
+
 function configure(pid, create) {
 	var uri = pluginRoot + '/' + pid;
 	// we have to add a cache killer for IE8
@@ -42,6 +45,12 @@ function configure(pid, create) {
 	$.get(postUri, null, displayConfigForm, 'json');
 }
 
+function showjson(pid) {
+    var ref =  pluginRoot;
+    ref = ref.substring(0, ref.lastIndexOf('/')) + "/osgi-installer-config-printer?format=JSON&pid=" + pid;
+	window.location = ref;
+}
+
 function displayConfigForm(obj) {
 	var parent = document.getElementById('editorTable');
 	clearChildren( parent )
@@ -560,19 +569,25 @@ function addConfig(conf) {
 	tr.find('li:eq(0)').click(function() { // edit
 		configure(conf.id);
 	});
-	tr.find('li:eq(2)').click(function() { // delete
-	    	deleteConfig(conf.id, conf.bundle_name);
-	});
 	if (conf.bundle) {
-	    	tr.find('li:eq(1)').click(function() { // unbind
-        		unbindConfig(conf.id, conf.bundle_name);
-        	}).removeClass('ui-state-disabled');
+	    tr.find('li:eq(1)').click(function() { // unbind
+        	unbindConfig(conf.id, conf.bundle_name);
+        }).removeClass('ui-state-disabled');
 	}
+    if ( conf.has_config ) {
+    	tr.find('li:eq(2)').click(function() { // delete
+    	    deleteConfig(conf.id, conf.bundle_name);
+    	}).removeClass('ui-state-disabled');
+    	if ( jsonSupport ) {
+            tr.find('li:eq(3)').click(function() { // json
+		        showjson(conf.id);
+            }).show();
+        }
+    }
 }
 
 function addFactoryConfig(conf) {
 	var tr = factoryRow.clone().appendTo(configTable).attr('fpid', conf.name);
-	//tr.find('td:eq(1)').text(conf.id); // fpid
 	tr.find('td:eq(1)').text(conf.name).click(function() { // name & edit
 		configure(conf.id, true);
 	});
@@ -680,6 +695,8 @@ $(document).ready(function() {
 	});
 	editorMessage = editor.find('p');
 
+	jsonSupport = configData.jsonsupport;
+
 	// display the configuration data
 	$(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing);
 	if (configData.status) {
diff --git a/webconsole/src/main/resources/templates/config.html b/webconsole/src/main/resources/templates/config.html
index b1d0cc4..d354f9a 100644
--- a/webconsole/src/main/resources/templates/config.html
+++ b/webconsole/src/main/resources/templates/config.html
@@ -67,7 +67,8 @@ var param = { // param
 					<ul class="icons">
 						<li class="dynhover" title="${config.edit.tip}"><span class="ui-icon ui-icon-pencil">&nbsp;</span></li>
 						<li class="ui-state-disabled dynhover" title="${config.unbind.tip}"><span class="ui-icon ui-icon-transferthick-e-w">&nbsp;</span></li>
-						<li class="dynhover" title="${delete}"><span class="ui-icon ui-icon-trash">&nbsp;</span></li>
+						<li class="ui-state-disabled dynhover" title="${delete}"><span class="ui-icon ui-icon-trash">&nbsp;</span></li>
+                        <li class="dynhover" style="display:none" title="${config.json.tip}"><span class="ui-icon ui-icon-comment">&nbsp;</span></li>
 					</ul>
 				</td>
 			</tr>