felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r925234 - in /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal: misc/ConfigurationRender.java servlet/OsgiManager.java
Date Fri, 19 Mar 2010 14:25:01 GMT
Author: fmeschbe
Date: Fri Mar 19 14:25:00 2010
New Revision: 925234

URL: http://svn.apache.org/viewvc?rev=925234&view=rev
Log:
FELIX-2206 Apply FELIX-2206-fmeschbe.patch turning ConfigurationRender into a special plugin,
which is provided with the ResourceBundleManager to be able to translate ConfigurationPrinter
titles (to English for now).

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.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/misc/ConfigurationRender.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java?rev=925234&r1=925233&r2=925234&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
Fri Mar 19 14:25:00 2010
@@ -32,6 +32,8 @@ import javax.servlet.http.HttpServletRes
 import org.apache.commons.io.IOUtils;
 import org.apache.felix.webconsole.*;
 import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
+import org.apache.felix.webconsole.internal.i18n.ResourceBundleManager;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
@@ -48,6 +50,9 @@ public class ConfigurationRender extends
     private static final String TITLE = "%configStatus.pluginTitle";
     private static final String[] CSS_REFS = null;
 
+    // use English as the locale for all non-display titles
+    private static final Locale DEFAULT = Locale.ENGLISH;
+
     /**
      * Formatter pattern to generate a relative path for the generation
      * of the plain text or zip file representation of the status. The file
@@ -62,6 +67,12 @@ public class ConfigurationRender extends
     private static final DateFormat DISPLAY_DATE_FORMAT = DateFormat.getDateTimeInstance(
DateFormat.LONG,
         DateFormat.LONG, Locale.US );
 
+    /**
+     * The resource bundle manager to allow for status printer title
+     * localization
+     */
+    private final ResourceBundleManager resourceBundleManager;
+
     private ServiceTracker cfgPrinterTracker;
 
     private int cfgPrinterTrackerCount;
@@ -69,9 +80,10 @@ public class ConfigurationRender extends
     private ArrayList configurationPrinters;
 
     /** Default constructor */
-    public ConfigurationRender()
+    public ConfigurationRender( final ResourceBundleManager resourceBundleManager )
     {
         super( LABEL, TITLE, CSS_REFS );
+        this.resourceBundleManager = resourceBundleManager;
     }
 
 
@@ -145,7 +157,7 @@ public class ConfigurationRender extends
                 final PrinterDesc desc = (PrinterDesc) i.next();
                 if (desc.label.equals( name ) )
                 {
-                    printConfigurationPrinter( pw, desc.printer, ConfigurationPrinter.MODE_WEB
);
+                    printConfigurationPrinter( pw, desc, ConfigurationPrinter.MODE_WEB );
                     pw.println( "</div></body></html>" );
                     return;
                 }
@@ -208,7 +220,7 @@ public class ConfigurationRender extends
         {
             final PrinterDesc desc = (PrinterDesc) i.next();
             final String label = desc.label;
-            final String title = getTitle( desc.printer );
+            final String title = desc.title;
             pw.print("<li><a href='" + pluginRoot + label + ".nfo'>" + title
+ "</a></li>" );
         }
         pw.println("</ul> <!-- end tabs on top -->");
@@ -227,7 +239,7 @@ public class ConfigurationRender extends
             final PrinterDesc desc = (PrinterDesc) cpi.next();
             if ( desc.match(mode) )
             {
-                printConfigurationPrinter( pw, desc.printer, mode );
+                printConfigurationPrinter( pw, desc, mode );
             }
         }
     }
@@ -251,8 +263,9 @@ public class ConfigurationRender extends
                 for ( int i = 0; i < refs.length; i++ )
                 {
                     ConfigurationPrinter cfgPrinter = ( ConfigurationPrinter ) cfgPrinterTracker.getService(
refs[i] );
-                    addConfigurationPrinter( cp, cfgPrinter, refs[i].getProperty( WebConsoleConstants.PLUGIN_LABEL
),
-                        refs[i].getProperty( ConfigurationPrinter.PROPERTY_MODES ) );
+                    addConfigurationPrinter( cp, cfgPrinter, refs[i].getBundle(), refs[i]
+                        .getProperty( WebConsoleConstants.PLUGIN_LABEL ), refs[i]
+                        .getProperty( ConfigurationPrinter.PROPERTY_MODES ) );
                 }
             }
             configurationPrinters = new ArrayList(cp.values());
@@ -263,12 +276,13 @@ public class ConfigurationRender extends
     }
 
 
-    private static final void addConfigurationPrinter( final SortedMap printers, final ConfigurationPrinter
cfgPrinter,
-        final Object labelProperty, final Object mode )
+    private final void addConfigurationPrinter( final SortedMap printers, final ConfigurationPrinter
cfgPrinter,
+        final Bundle provider, final Object labelProperty, final Object mode )
     {
         if ( cfgPrinter != null )
         {
-            String sortKey = getTitle( cfgPrinter );
+            final String title = getTitle( cfgPrinter.getTitle(), provider );
+            String sortKey = title;
             if ( printers.containsKey( sortKey ) )
             {
                 int idx = -1;
@@ -282,7 +296,7 @@ public class ConfigurationRender extends
                 sortKey = idxTitle;
             }
             String label = ( labelProperty instanceof String ) ? ( String ) labelProperty
: sortKey;
-            printers.put( sortKey, new PrinterDesc( cfgPrinter, label, mode ) );
+            printers.put( sortKey, new PrinterDesc( cfgPrinter, title, label, mode ) );
         }
     }
 
@@ -319,14 +333,14 @@ public class ConfigurationRender extends
     //    }
 
 
-    private static final void printConfigurationPrinter( final ConfigurationWriter pw,
-                                            final ConfigurationPrinter cp,
-                                            final String mode )
+    private final void printConfigurationPrinter( final ConfigurationWriter pw, final PrinterDesc
desc,
+        final String mode )
     {
-        pw.title( getTitle( cp ) );
+        pw.title( desc.title );
+        final ConfigurationPrinter cp = desc.printer;
         if ( cp instanceof ModeAwareConfigurationPrinter )
         {
-            ((ModeAwareConfigurationPrinter)cp).printConfiguration( pw , mode);
+            ( ( ModeAwareConfigurationPrinter ) cp ).printConfiguration( pw, mode );
         }
         else
         {
@@ -394,14 +408,15 @@ public class ConfigurationRender extends
     }
 
 
-    private static final String getTitle( final ConfigurationPrinter cp )
+    private final String getTitle( final String title, final Bundle provider )
     {
-        final String title = cp.getTitle();
-        if ( title.startsWith( "%" ) )
+        if ( !title.startsWith( "%" ) )
         {
-            return title.substring( 1 );
+            return title;
         }
-        return title;
+
+        ResourceBundle res = resourceBundleManager.getResourceBundle( provider, DEFAULT );
+        return res.getString( title.substring( 1 ) );
     }
 
     private abstract static class ConfigurationWriter extends PrintWriter
@@ -536,7 +551,7 @@ public class ConfigurationRender extends
                     final URL[] attachments = ((AttachmentProvider)desc.printer).getAttachments(mode);
                     if ( attachments != null )
                     {
-                        cf.handleAttachments( getTitle( desc.printer ), attachments );
+                        cf.handleAttachments( desc.title, attachments );
                     }
                 }
             }
@@ -546,23 +561,27 @@ public class ConfigurationRender extends
 
     private static final class PrinterDesc
     {
-        private final String[] modes;
         public final ConfigurationPrinter printer;
+        public final String title;
         public final String label;
+        private final String[] modes;
 
         private static final List CUSTOM_MODES = new ArrayList();
         static
         {
-            CUSTOM_MODES.add(ConfigurationPrinter.MODE_TXT);
-            CUSTOM_MODES.add(ConfigurationPrinter.MODE_WEB);
-            CUSTOM_MODES.add(ConfigurationPrinter.MODE_ZIP);
+            CUSTOM_MODES.add( ConfigurationPrinter.MODE_TXT );
+            CUSTOM_MODES.add( ConfigurationPrinter.MODE_WEB );
+            CUSTOM_MODES.add( ConfigurationPrinter.MODE_ZIP );
         }
 
-        public PrinterDesc(final ConfigurationPrinter printer, final String label, final
Object modes)
+
+        public PrinterDesc( final ConfigurationPrinter printer, final String title, final
String label,
+            final Object modes )
         {
             this.printer = printer;
+            this.title = title;
             this.label = label;
-            if ( modes == null || !(modes instanceof String || modes instanceof String[])
)
+            if ( modes == null || !( modes instanceof String || modes instanceof String[]
) )
             {
                 this.modes = null;
             }

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=925234&r1=925233&r2=925234&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
Fri Mar 19 14:25:00 2010
@@ -47,6 +47,7 @@ import org.apache.felix.webconsole.inter
 import org.apache.felix.webconsole.internal.core.BundlesServlet;
 import org.apache.felix.webconsole.internal.filter.FilteringResponseWrapper;
 import org.apache.felix.webconsole.internal.i18n.ResourceBundleManager;
+import org.apache.felix.webconsole.internal.misc.ConfigurationRender;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -135,7 +136,6 @@ public class OsgiManager extends Generic
             "org.apache.felix.webconsole.internal.core.ServicesServlet",
             "org.apache.felix.webconsole.internal.deppack.DepPackServlet",
             "org.apache.felix.webconsole.internal.misc.LicenseServlet",
-            "org.apache.felix.webconsole.internal.misc.ConfigurationRender",
             "org.apache.felix.webconsole.internal.misc.ShellServlet",
             "org.apache.felix.webconsole.internal.misc.SystemPropertiesPrinter",
             "org.apache.felix.webconsole.internal.misc.ThreadPrinter",
@@ -295,14 +295,20 @@ public class OsgiManager extends Generic
             }
         }
 
+        // the resource bundle manager
+        resourceBundleManager = new ResourceBundleManager( getBundleContext() );
+
+        // start the configuration render, providing the resource bundle manager
+        ConfigurationRender cr = new ConfigurationRender(resourceBundleManager);
+        cr.activate( bundleContext );
+        osgiManagerPlugins.add(cr);
+        bindServlet( cr );
+
         // start tracking external plugins after setting up our own plugins
         pluginsTracker = new PluginServiceTracker( this );
         pluginsTracker.open();
         brandingTracker = new BrandingServiceTracker(this);
         brandingTracker.open();
-
-        // the resource bundle manager
-        resourceBundleManager = new ResourceBundleManager( getBundleContext() );
     }
 
     public void service( ServletRequest req, ServletResponse res ) throws ServletException,
IOException
@@ -396,10 +402,7 @@ public class OsgiManager extends Generic
         for ( Iterator pi = osgiManagerPlugins.iterator(); pi.hasNext(); )
         {
             Object plugin = pi.next();
-            if ( plugin instanceof OsgiManagerPlugin )
-            {
-                ( ( OsgiManagerPlugin ) plugin ).deactivate();
-            }
+            ( ( OsgiManagerPlugin ) plugin ).deactivate();
         }
 
         // simply remove all operations, we should not be used anymore



Mime
View raw message