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/10/04 10:17:06 UTC

[felix-dev] branch master updated: FELIX-6341 ConfigAdmin - deleting a configuration logs a string that (#54)

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 0da0100  FELIX-6341 ConfigAdmin - deleting a configuration logs a string that (#54)
0da0100 is described below

commit 0da01009233b2bbc15d2d0b6f63dce4b04b4b0ac
Author: Eric Norman <en...@apache.org>
AuthorDate: Sun Oct 4 03:16:59 2020 -0700

    FELIX-6341 ConfigAdmin - deleting a configuration logs a string that (#54)
    
    should be translated
---
 .../felix/webconsole/SimpleWebConsolePlugin.java   | 41 ++++++++++++++++++++++
 .../i18n/ConsolePropertyResourceBundle.java        |  8 ++++-
 .../internal/servlet/OsgiManagerTest.java          | 14 ++++++++
 3 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/SimpleWebConsolePlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/SimpleWebConsolePlugin.java
index fff1718..e48ab45 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/SimpleWebConsolePlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/SimpleWebConsolePlugin.java
@@ -23,8 +23,12 @@ import java.net.URL;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.Map;
+import java.util.ResourceBundle;
 
+import org.apache.felix.webconsole.i18n.LocalizationHelper;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.util.tracker.ServiceTracker;
@@ -60,6 +64,8 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
     // used to obtain services. Structure is: service name -> ServiceTracker
     private final Map services = new HashMap();
 
+    // localized title as servlet name
+    private String servletName;
 
     /**
      * Creates new Simple Web Console Plugin with the default category
@@ -109,6 +115,41 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
     }
 
 
+    /* (non-Javadoc)
+     * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#activate(org.osgi.framework.BundleContext)
+     */
+    @Override
+    public void activate(BundleContext bundleContext) {
+        super.activate(bundleContext);
+
+        // FELIX-6341 - dig out the localized title for use in log messages
+        Bundle bundle = bundleContext.getBundle();
+        if (bundle != null) {
+            LocalizationHelper localization = new LocalizationHelper( bundle );
+            ResourceBundle rb = localization.getResourceBundle(Locale.getDefault());
+            if (rb != null) {
+                if ( this.title != null && this.title.startsWith( "%" ) ) { //$NON-NLS-1$
+                    String key = this.title.substring(1);
+                    if (rb.containsKey(key)) {
+                        this.servletName = rb.getString(key);
+                    }
+                }
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getServletName()
+     */
+    @Override
+    public String getServletName() {
+        // use the localized title if we have one
+        if (servletName != null) {
+            return servletName;
+        }
+        return super.getServletName();
+    }
+
     /**
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getLabel()
      */
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java
index f70b07e..7ed707e 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java
@@ -62,7 +62,13 @@ class ConsolePropertyResourceBundle extends ResourceBundle
 
     public Enumeration getKeys()
     {
-        return new CombinedEnumeration( props.keys(), parent.getKeys() );
+        Enumeration keysEnum = null;
+        if (parent == null) {
+            keysEnum = props.keys();
+        } else {
+            keysEnum = new CombinedEnumeration( props.keys(), parent.getKeys() );
+        }
+        return keysEnum;
     }
 
 
diff --git a/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java b/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java
index c051cb5..49f6af7 100644
--- a/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java
+++ b/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java
@@ -25,11 +25,14 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
 import java.lang.reflect.Field;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Dictionary;
+import java.util.Enumeration;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Set;
 
@@ -400,6 +403,17 @@ public class OsgiManagerTest {
                 return FrameworkUtil.createFilter(fs);
             }
         });
+        // FELIX-6341 - mock the getHeaders to avoid a NPE during ResourceBundleCache#getResourceBundleEntries
+        final Dictionary<String, String> headers = new Hashtable<>();
+        Mockito.when(bundle.getHeaders()).thenReturn(headers);
+        // FELIX-6341 - mock bundle#findEntries so ResourceBundleCache#getResourceBundleEntries will function
+        URL rbUrl = getClass().getResource("/OSGI-INF/l10n/bundle.properties");
+        Mockito.when(bundle.findEntries("OSGI-INF/l10n", "bundle*.properties", false)).thenAnswer(new Answer<Enumeration<URL>>() {
+			@Override
+			public Enumeration<URL> answer(InvocationOnMock invocation) throws Throwable {
+				return Collections.enumeration(Collections.singleton(rbUrl));
+			}
+        });
         return bc;
     }
 }