Skip to content
Permalink
Browse files
FELIX-6341 ConfigAdmin - deleting a configuration logs a string that (#…
…54)

should be translated
  • Loading branch information
enapps-enorman committed Oct 4, 2020
1 parent 0e0729d commit 0da01009233b2bbc15d2d0b6f63dce4b04b4b0ac
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
@@ -23,8 +23,12 @@
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 SimpleWebConsolePlugin( String label, String title, String category, Stri
}


/* (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()
*/
@@ -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;
}


@@ -25,11 +25,14 @@
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 Filter answer(InvocationOnMock invocation) throws Throwable {
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;
}
}

0 comments on commit 0da0100

Please sign in to comment.