You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by vv...@apache.org on 2010/08/11 09:25:44 UTC
svn commit: r984311 - in /felix/trunk/webconsole/src/main:
java/org/apache/felix/webconsole/
java/org/apache/felix/webconsole/internal/servlet/ resources/res/flags/
resources/res/lib/ resources/res/ui/
Author: vvalchev
Date: Wed Aug 11 07:25:43 2010
New Revision: 984311
URL: http://svn.apache.org/viewvc?rev=984311&view=rev
Log:
Fixed FELIX-2277 /Allow the user to select display language/
https://issues.apache.org/jira/browse/FELIX-2277
Added:
felix/trunk/webconsole/src/main/resources/res/flags/
felix/trunk/webconsole/src/main/resources/res/flags/bg.gif (with props)
felix/trunk/webconsole/src/main/resources/res/flags/de.gif (with props)
felix/trunk/webconsole/src/main/resources/res/flags/en.gif (with props)
Modified:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
felix/trunk/webconsole/src/main/resources/res/lib/support.js
felix/trunk/webconsole/src/main/resources/res/ui/webconsole.css
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=984311&r1=984310&r2=984311&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 Wed Aug 11 07:25:43 2010
@@ -614,9 +614,37 @@ public abstract class AbstractWebConsole
pw.println("<div id='technav' class='ui-widget ui-widget-header'>");
for ( Iterator li = map.values().iterator(); li.hasNext(); )
{
+ pw.print(' ');
pw.println( li.next() );
}
pw.println( "</div>" );
+
+ }
+
+ // render lang-box
+ Map langMap = (Map) request.getAttribute(WebConsoleConstants.ATTR_LANG_MAP);
+ if (null != langMap && !langMap.isEmpty())
+ {
+ pw.println("<div id='langSelect'>"); //$NON-NLS-1$
+ pw.println(" <span class='ui-icon ui-icon-comment'> </span>"); //$NON-NLS-1$
+ pw.println(" <span class='flags ui-helper-hidden'>"); //$NON-NLS-1$
+ for (Iterator li = langMap.keySet().iterator(); li.hasNext();)
+ {
+ // <img src="us.gif" alt="en" title="English"/>
+ final Object l = li.next();
+ pw.print(" <img src='"); //$NON-NLS-1$
+ pw.print(appRoot);
+ pw.print("/res/flags/"); //$NON-NLS-1$
+ pw.print(l);
+ pw.print(".gif' alt='"); //$NON-NLS-1$
+ pw.print(l);
+ pw.print("' title='"); //$NON-NLS-1$
+ pw.print(langMap.get(l));
+ pw.println("'/>"); //$NON-NLS-1$
+ }
+
+ pw.println(" </span>"); //$NON-NLS-1$
+ pw.println("</div>"); //$NON-NLS-1$
}
}
@@ -709,7 +737,7 @@ public abstract class AbstractWebConsole
* Note: This method is intended to be used internally by the Web Console
* to update the log level according to the Web Console configuration.
*
- * @param logLevel the maximum allowed log level. If message is logged with
+ * @param logLevel the maximum allowed log level. If message is logged with
* lower level it will not be forwarded to the logger.
*/
public static final void setLogLevel( int logLevel )
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java?rev=984311&r1=984310&r2=984311&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java Wed Aug 11 07:25:43 2010
@@ -18,6 +18,8 @@
*/
package org.apache.felix.webconsole;
+import java.util.Locale;
+
/**
* WebConsoleConstants provides some common constants that are used by plugin
* developers.
@@ -129,4 +131,24 @@ public interface WebConsoleConstants
* @since 3.0
*/
static final String ATTR_CONSOLE_VARIABLE_RESOLVER = "felix.webconsole.variable.resolver";
+
+ /**
+ * The name of the request attribute holding the language {@link Map}
+ * for the request (value is "felix.webconsole.langMap").
+ *
+ * This map contains the web console supported languages, which are automatically detected.
+ * The keys of the map are the language codes, like "en", "en_US" .. and so-on.
+ * The value for each key is the locale user-friendly name - exactly the same as
+ * returned by {@link Locale#getDisplayLanguage()}.
+ *
+ * The automatic detection of languages is very simple. It relies on having a
+ * 'res/flags/[lang].gif' file in the bundle. So translators should not only provide
+ * localized l10n/bundle.properties but also a flag image.
+ *
+ * The image should be obtained from http://famfamfam.com/lab/icons/flags/ and eventually
+ * renamed to the correct locale.
+ *
+ * @since 3.1.2
+ */
+ public static final String ATTR_LANG_MAP = "felix.webconsole.langMap"; //$NON-NLS-1$
}
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=984311&r1=984310&r2=984311&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 Wed Aug 11 07:25:43 2010
@@ -18,11 +18,13 @@ package org.apache.felix.webconsole.inte
import java.io.IOException;
+import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
@@ -40,6 +42,7 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.io.FilenameUtils;
import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.BrandingPlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
@@ -50,6 +53,7 @@ import org.apache.felix.webconsole.inter
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.Constants;
import org.osgi.framework.Filter;
@@ -407,6 +411,7 @@ public class OsgiManager extends Generic
final Map labelMap = holder.getLocalizedLabelMap( resourceBundleManager, locale );
// the official request attributes
+ request.setAttribute( WebConsoleConstants.ATTR_LANG_MAP, getLangMap() );
request.setAttribute( WebConsoleConstants.ATTR_LABEL_MAP, labelMap );
request.setAttribute( WebConsoleConstants.ATTR_APP_ROOT, request.getContextPath() + request.getServletPath() );
request.setAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT, request.getContextPath() + request.getServletPath()
@@ -945,6 +950,32 @@ public class OsgiManager extends Generic
}
return stringConfig;
}
+
+ private Map langMap;
+
+ private final Map getLangMap()
+ {
+ if (null != langMap) return langMap;
+ final Map map = new HashMap();
+ final Bundle bundle = bundleContext.getBundle();
+ final Enumeration e = bundle.findEntries("res/flags", null, false);
+ while (e != null && e.hasMoreElements())
+ {
+ final URL img = (URL) e.nextElement();
+ final String name = FilenameUtils.getBaseName(img.getFile());
+ try
+ {
+ final String locale = new Locale(name).getDisplayLanguage();
+ map.put(name, null != locale ? locale : name);
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ /* ignore invalid locale? */
+ }
+ }
+ return langMap = map;
+ }
static class SecurityProvider implements WebConsoleSecurityProvider {
Added: felix/trunk/webconsole/src/main/resources/res/flags/bg.gif
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/flags/bg.gif?rev=984311&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/trunk/webconsole/src/main/resources/res/flags/bg.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: felix/trunk/webconsole/src/main/resources/res/flags/de.gif
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/flags/de.gif?rev=984311&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/trunk/webconsole/src/main/resources/res/flags/de.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: felix/trunk/webconsole/src/main/resources/res/flags/en.gif
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/flags/en.gif?rev=984311&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/trunk/webconsole/src/main/resources/res/flags/en.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: felix/trunk/webconsole/src/main/resources/res/lib/support.js
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/lib/support.js?rev=984311&r1=984310&r2=984311&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/lib/support.js (original)
+++ felix/trunk/webconsole/src/main/resources/res/lib/support.js Wed Aug 11 07:25:43 2010
@@ -252,3 +252,15 @@ function Xdialog(text) {
}
return element;
}
+
+// language selection element
+var langSelect = false;
+$(document).ready(function() {
+ langSelect = $('#langSelect').hover(
+ function() { $(this).find('.flags').show('blind') },
+ function() { $(this).find('.flags').hide('blind') });
+ langSelect.find('.flags img').click(function() {
+ $.cookies.set('felix.webconsole.locale', $(this).attr('alt'));
+ location.reload();
+ });
+});
Modified: felix/trunk/webconsole/src/main/resources/res/ui/webconsole.css
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/resources/res/ui/webconsole.css?rev=984311&r1=984310&r2=984311&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/resources/res/ui/webconsole.css (original)
+++ felix/trunk/webconsole/src/main/resources/res/ui/webconsole.css Wed Aug 11 07:25:43 2010
@@ -170,3 +170,6 @@ ul.icons li {
float: left;
list-style: none
}
+/* language selection element */
+#langSelect { position: absolute; top: 5px; right: 5px }
+#langSelect img { display: block; padding: 2px 0 }