Author: tmortagne
Date: 2007-10-10 11:46:23 +0200 (Wed, 10 Oct 2007)
New Revision: 5340
Added:
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/plugin/
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/plugin/XWikiPluginMessageTool.java
Log:
XAAM-17: Add XWikiPluginMessageTool that extends XWikiMessageTool. His goal is
to first search in the context if a message key string exist and if not use the
"default" one in the ResourceBundle defined by the plugin.
Added:
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/plugin/XWikiPluginMessageTool.java
===================================================================
---
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/plugin/XWikiPluginMessageTool.java
(rev 0)
+++
xwiki-platform/xwiki-plugins/trunk/application-manager/src/main/java/com/xpn/xwiki/plugin/applicationmanager/core/plugin/XWikiPluginMessageTool.java
2007-10-10 09:46:23 UTC (rev 5340)
@@ -0,0 +1,90 @@
+package com.xpn.xwiki.plugin.applicationmanager.core.plugin;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.web.XWikiMessageTool;
+
+/**
+ * Plugin internationalization service based [EMAIL PROTECTED]
XWikiMessageTool}.
+ *
+ * @version $Id: $
+ */
+public class XWikiPluginMessageTool extends XWikiMessageTool
+{
+ /**
+ * @param bundle the default Resource Bundle to fall back to if no
document bundle is found when
+ * trying to get a key
+ * @param context the [EMAIL PROTECTED] com.xpn.xwiki.XWikiContext}
object, used to get access to XWiki
+ * primitives for loading documents
+ */
+ public XWikiPluginMessageTool(ResourceBundle bundle, XWikiContext context)
+ {
+ super(bundle, context);
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ * <p>
+ * Start calling <code>context</code>'s [EMAIL PROTECTED]
XWikiMessageTool#get(String)} then if nothing is found
+ * use plugin's [EMAIL PROTECTED] ResourceBundle}.
+ *
+ * @see com.xpn.xwiki.web.XWikiMessageTool#getTranslation(java.lang.String)
+ */
+ protected String getTranslation(String key)
+ {
+ String translation = this.context.getMessageTool().get(key);
+
+ if (translation == key) {
+ try {
+ translation = this.bundle.getString(key);
+ } catch (Exception e) {
+ translation = null;
+ }
+ }
+
+ return translation;
+ }
+
+ /**
+ * Find a translation and then replace any parameters found in the
translation by the passed
+ * params parameters. The format is the one used by [EMAIL PROTECTED]
java.text.MessageFormat}.
+ *
+ * @param key the key of the string to find
+ * @param params the array of parameters to use for replacing "{N}"
elements in the string. See
+ * [EMAIL PROTECTED] java.text.MessageFormat} for the full
syntax
+ * @return the translated string with parameters resolved
+ * @see com.xpn.xwiki.web.XWikiMessageTool#get(String, List)
+ */
+ public String get(String key, String[] params)
+ {
+ List paramList = new ArrayList(params.length);
+
+ for (int i = 0; i < params.length; ++i) {
+ paramList.add(params[i]);
+ }
+
+ return get(key, paramList);
+ }
+
+ /**
+ * Find a translation and then replace any parameters found in the
translation by the passed
+ * param parameter. The format is the one used by [EMAIL PROTECTED]
java.text.MessageFormat}.
+ *
+ * @param key the key of the string to find
+ * @param params the parameter to use for replacing "{0}" element in the
string. See
+ * [EMAIL PROTECTED] java.text.MessageFormat} for the full
syntax
+ * @return the translated string with parameters resolved
+ * @see com.xpn.xwiki.web.XWikiMessageTool#get(String, List)
+ */
+ public String get(String key, String param)
+ {
+ List paramList = new ArrayList(1);
+
+ paramList.add(param);
+
+ return get(key, paramList);
+ }
+}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications