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).
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@925234 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
index 01fbd90..c47d033 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
@@ -32,6 +32,8 @@
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 @@
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 @@
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 @@
private ArrayList configurationPrinters;
/** Default constructor */
- public ConfigurationRender()
+ public ConfigurationRender( final ResourceBundleManager resourceBundleManager )
{
super( LABEL, TITLE, CSS_REFS );
+ this.resourceBundleManager = resourceBundleManager;
}
@@ -145,7 +157,7 @@
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 @@
{
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 @@
final PrinterDesc desc = (PrinterDesc) cpi.next();
if ( desc.match(mode) )
{
- printConfigurationPrinter( pw, desc.printer, mode );
+ printConfigurationPrinter( pw, desc, mode );
}
}
}
@@ -251,8 +263,9 @@
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 @@
}
- 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 @@
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 @@
// }
- 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 @@
}
- 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 @@
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 @@
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;
}
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 63c9bf9..294ac6b 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
@@ -47,6 +47,7 @@
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 @@
"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 @@
}
}
+ // 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 @@
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