You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2010/03/13 16:04:25 UTC

svn commit: r922579 - in /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole: AbstractWebConsolePlugin.java internal/misc/ConfigurationRender.java internal/servlet/OsgiManager.java

Author: fmeschbe
Date: Sat Mar 13 15:04:24 2010
New Revision: 922579

URL: http://svn.apache.org/viewvc?rev=922579&view=rev
Log:
FELIX-2158 Apply my FELIX-2158-2.patch

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
    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/AbstractWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java?rev=922579&r1=922578&r2=922579&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java Sat Mar 13 15:04:24 2010
@@ -538,11 +538,18 @@ public abstract class AbstractWebConsole
 
         final String appRoot = ( String ) request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT );
 
+        // support localization of the plugin title
+        String title = getTitle();
+        if ( title.startsWith( "%" ) )
+        {
+            title = "${" + title.substring( 1 ) + "}";
+        }
+
         String header = MessageFormat.format( getHeader(), new Object[]
-            { brandingPlugin.getBrandName(), getTitle(), appRoot, getLabel(),
-                toUrl( brandingPlugin.getFavIcon(), appRoot ), toUrl( brandingPlugin.getMainStyleSheet(), appRoot ),
-                brandingPlugin.getProductURL(), brandingPlugin.getProductName(),
-                toUrl( brandingPlugin.getProductImage(), appRoot ), getCssLinks( appRoot ) } );
+            { brandingPlugin.getBrandName(), title, appRoot, getLabel(), toUrl( brandingPlugin.getFavIcon(), appRoot ),
+                toUrl( brandingPlugin.getMainStyleSheet(), appRoot ), brandingPlugin.getProductURL(),
+                brandingPlugin.getProductName(), toUrl( brandingPlugin.getProductImage(), appRoot ),
+                getCssLinks( appRoot ) } );
         pw.println( header );
 
         return pw;

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=922579&r1=922578&r2=922579&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 Sat Mar 13 15:04:24 2010
@@ -208,7 +208,7 @@ public class ConfigurationRender extends
         {
             final PrinterDesc desc = (PrinterDesc) i.next();
             final String label = desc.label;
-            final String title = desc.printer.getTitle();
+            final String title = getTitle( desc.printer );
             pw.print("<li><a href='" + pluginRoot + label + ".nfo'>" + title + "</a></li>" );
         }
         pw.println("</ul> <!-- end tabs on top -->");
@@ -273,7 +273,7 @@ public class ConfigurationRender extends
     {
         if ( cfgPrinter != null )
         {
-            String sortKey = cfgPrinter.getTitle();
+            String sortKey = getTitle( cfgPrinter );
             if ( printers.containsKey( sortKey ) )
             {
                 int idx = -1;
@@ -328,7 +328,7 @@ public class ConfigurationRender extends
                                             final ConfigurationPrinter cp,
                                             final String mode )
     {
-        pw.title(  cp.getTitle() );
+        pw.title( getTitle( cp ) );
         if ( cp instanceof ModeAwareConfigurationPrinter )
         {
             ((ModeAwareConfigurationPrinter)cp).printConfiguration( pw , mode);
@@ -398,6 +398,17 @@ public class ConfigurationRender extends
         }
     }
 
+
+    private static final String getTitle( final ConfigurationPrinter cp )
+    {
+        final String title = cp.getTitle();
+        if ( title.startsWith( "%" ) )
+        {
+            return title.substring( 1 );
+        }
+        return title;
+    }
+
     private static class SystemPropertiesPrinter implements ConfigurationPrinter
     {
 
@@ -648,7 +659,7 @@ public class ConfigurationRender extends
                     final URL[] attachments = ((AttachmentProvider)desc.printer).getAttachments(mode);
                     if ( attachments != null )
                     {
-                        cf.handleAttachments(desc.printer.getTitle(), attachments);
+                        cf.handleAttachments( getTitle( desc.printer ), attachments );
                     }
                 }
             }

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=922579&r1=922578&r2=922579&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 Sat Mar 13 15:04:24 2010
@@ -155,10 +155,6 @@ public class OsgiManager extends Generic
     // AbstractWebConsolePlugin instances
     private Map plugins = new HashMap();
 
-    // map of labels to plugin titles: indexed by plugin label (String, values
-    // are plugin titles
-    private Map labelMap = new HashMap();
-
     private AbstractWebConsolePlugin defaultPlugin;
 
     private String defaultRenderName;
@@ -339,6 +335,8 @@ public class OsgiManager extends Generic
 
         if ( plugin != null )
         {
+            final Map labelMap = getLocalizedLabelMap( request.getLocale() );
+
             // the official request attributes
             req.setAttribute( WebConsoleConstants.ATTR_LABEL_MAP, labelMap );
             req.setAttribute( WebConsoleConstants.ATTR_APP_ROOT, request.getContextPath() + request.getServletPath() );
@@ -397,7 +395,6 @@ public class OsgiManager extends Generic
 
         // simply remove all operations, we should not be used anymore
         this.plugins.clear();
-        this.labelMap.clear();
     }
 
 
@@ -710,7 +707,6 @@ public class OsgiManager extends Generic
         {
             plugin.init( getServletConfig() );
             plugins.put( label, plugin );
-            labelMap.put( label, title );
 
             if ( this.defaultPlugin == null )
             {
@@ -734,8 +730,6 @@ public class OsgiManager extends Generic
         AbstractWebConsolePlugin plugin = ( AbstractWebConsolePlugin ) plugins.remove( label );
         if ( plugin != null )
         {
-            labelMap.remove( label );
-
             if ( this.defaultPlugin == plugin )
             {
                 if ( this.plugins.isEmpty() )
@@ -915,4 +909,44 @@ public class OsgiManager extends Generic
         }
         return stringConfig;
     }
+
+
+    /**
+     * Builds the map of labels to plugin titles to be stored as the
+     * <code>felix.webconsole.labelMap</code> request attribute. This map
+     * optionally localizes the plugin title using the providing bundle's
+     * resource bundle if the first character of the title is a percent
+     * sign (%). Titles not prefixed with a percent sign are added to the
+     * map unmodified.
+     *
+     * @param locale The locale to which the titles are to be localized
+     *
+     * @return The localized map of labels to titles
+     */
+    private final Map getLocalizedLabelMap( final Locale locale )
+    {
+        final Map map = new HashMap();
+        for ( Iterator pi = plugins.values().iterator(); pi.hasNext(); )
+        {
+            final AbstractWebConsolePlugin plugin = ( AbstractWebConsolePlugin ) pi.next();
+            final String label = plugin.getLabel();
+            String title = plugin.getTitle();
+            if ( title.startsWith( "%" ) )
+            {
+                try
+                {
+                    final ResourceBundle resourceBundle = resourceBundleManager.getResourceBundle( plugin.getBundle(),
+                        locale );
+                    title = resourceBundle.getString( title.substring( 1 ) );
+                }
+                catch ( Throwable e )
+                {
+                    /* ignore missing resource - use default title */
+                }
+            }
+            map.put( label, title );
+        }
+
+        return map;
+    }
 }