FELIX-2709 Support some configuration from bundle context properties:
- felix.webconsole.loglevel -- AbstractWebConsolePlugin log level
- felix.webconsole.locale -- default locale overwriting Accept-Language header
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1220660 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java
index 2c74992..60d5bb9 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java
@@ -114,7 +114,7 @@
ObjectClassDefinition xocd = null;
final Locale localeObj = Util.parseLocaleString(locale);
final ResourceBundle rb = osgiManager.resourceBundleManager.getResourceBundle(osgiManager.getBundleContext().getBundle(), localeObj);
- final Map<String, String> defaultConfig = osgiManager.getDefaultConfiguration();
+ final Map<String, ?> defaultConfig = osgiManager.getDefaultConfiguration();
// simple configuration properties
final ArrayList<AttributeDefinition> adList = new ArrayList<AttributeDefinition>();
@@ -132,7 +132,9 @@
getString(rb, "metadata.loglevel.name", OsgiManager.PROP_LOG_LEVEL), //$NON-NLS-1$
getString(rb, "metadata.loglevel.description", OsgiManager.PROP_LOG_LEVEL), //$NON-NLS-1$
AttributeDefinition.INTEGER, // type
- new String[] { String.valueOf( OsgiManager.DEFAULT_LOG_LEVEL ) }, // default values
+ new String[]
+ { String.valueOf( ConfigurationUtil.getProperty( defaultConfig, OsgiManager.PROP_LOG_LEVEL,
+ OsgiManager.DEFAULT_LOG_LEVEL ) ) }, // default values
0, // cardinality
new String[] { // option labels
getString(rb, "log.level.debug", "Debug"), //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java
index edf6567..e50e215 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java
@@ -51,6 +51,35 @@
return ( value == null ) ? def : value;
}
+ /**
+ * Returns the named property from the framework. If the property does
+ * not exist, the default value <code>def</code> is returned.
+ *
+ * @param context The BundleContext providing framework properties
+ * @param name The name of the property to return
+ * @param def The default value if the named property does not exist
+ * @return The value of the named property as a string or <code>def</code>
+ * if the property does not exist
+ */
+ public static final int getProperty(BundleContext context, String name, int def)
+ {
+ String value = context.getProperty( name);
+ if (value != null)
+ {
+ try
+ {
+ return Integer.parseInt(value.toString());
+ }
+ catch (NumberFormatException nfe)
+ {
+ // don't care
+ }
+ }
+
+ // not a number, not convertible, not set, use default
+ return def;
+ }
+
/**
* Returns the named property from the configuration. If the property does
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index ef4fdeb..ef01403 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -118,6 +118,10 @@
private static final String FRAMEWORK_PROP_PASSWORD = "felix.webconsole.password"; //$NON-NLS-1$
+ private static final String FRAMEWORK_PROP_LOG_LEVEL = "felix.webconsole.loglevel"; //$NON-NLS-1$
+
+ private static final String FRAMEWORK_PROP_LOCALE = "felix.webconsole.locale"; //$NON-NLS-1$
+
static final String PROP_MANAGER_ROOT = "manager.root"; //$NON-NLS-1$
static final String PROP_DEFAULT_RENDER = "default.render"; //$NON-NLS-1$
@@ -200,7 +204,7 @@
private boolean httpResourcesRegistered;
// default configuration from framework properties
- private HashMap<String, String> defaultConfiguration;
+ private HashMap<String, Object> defaultConfiguration;
// configuration from Configuration Admin
private HashMap<String, ?> configuration;
@@ -293,7 +297,7 @@
securityProviderTracker.open();
// load the default configuration from the framework
- this.defaultConfiguration = new HashMap<String, String>();
+ this.defaultConfiguration = new HashMap<String, Object>();
this.defaultConfiguration.put( PROP_MANAGER_ROOT,
ConfigurationUtil.getProperty( bundleContext, FRAMEWORK_PROP_MANAGER_ROOT, DEFAULT_MANAGER_ROOT ) );
this.defaultConfiguration.put( PROP_REALM,
@@ -302,6 +306,10 @@
ConfigurationUtil.getProperty( bundleContext, FRAMEWORK_PROP_USER_NAME, DEFAULT_USER_NAME ) );
this.defaultConfiguration.put( PROP_PASSWORD,
ConfigurationUtil.getProperty( bundleContext, FRAMEWORK_PROP_PASSWORD, DEFAULT_PASSWORD ) );
+ this.defaultConfiguration.put( PROP_LOG_LEVEL,
+ ConfigurationUtil.getProperty( bundleContext, FRAMEWORK_PROP_LOG_LEVEL, DEFAULT_LOG_LEVEL) );
+ this.defaultConfiguration.put( PROP_LOCALE,
+ ConfigurationUtil.getProperty( bundleContext, FRAMEWORK_PROP_LOCALE, null ) );
// configure and start listening for configuration
updateConfiguration(null);
@@ -806,7 +814,7 @@
}
- Map<String, String> getDefaultConfiguration()
+ Map<String, ?> getDefaultConfiguration()
{
return defaultConfiguration;
}