felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1220660 - in /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet: ConfigurationListener2.java ConfigurationUtil.java OsgiManager.java
Date Mon, 19 Dec 2011 09:12:14 GMT
Author: fmeschbe
Date: Mon Dec 19 09:12:13 2011
New Revision: 1220660

URL: http://svn.apache.org/viewvc?rev=1220660&view=rev
Log:
FELIX-2709 Support some configuration from bundle context properties:
  - felix.webconsole.loglevel -- AbstractWebConsolePlugin log level
  - felix.webconsole.locale -- default locale overwriting Accept-Language header

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java?rev=1220660&r1=1220659&r2=1220660&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener2.java
Mon Dec 19 09:12:13 2011
@@ -114,7 +114,7 @@ class ConfigurationListener2 extends Con
         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 @@ class ConfigurationListener2 extends Con
             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$

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java?rev=1220660&r1=1220659&r2=1220660&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationUtil.java
Mon Dec 19 09:12:13 2011
@@ -51,6 +51,35 @@ public class ConfigurationUtil
         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

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java?rev=1220660&r1=1220659&r2=1220660&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
Mon Dec 19 09:12:13 2011
@@ -118,6 +118,10 @@ public class OsgiManager extends Generic
 
     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 @@ public class OsgiManager extends Generic
     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 @@ public class OsgiManager extends Generic
         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 @@ public class OsgiManager extends Generic
             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 @@ public class OsgiManager extends Generic
     }
 
 
-    Map<String, String> getDefaultConfiguration()
+    Map<String, ?> getDefaultConfiguration()
     {
         return defaultConfiguration;
     }



Mime
View raw message