com.xpn.xwiki.web
Class XWikiMessageTool

java.lang.Object
  extended by com.xpn.xwiki.web.XWikiMessageTool

Deprecated. since 4.3M2 use LocalizationManager component instead

@Deprecated
public class XWikiMessageTool
extends Object

Internationalization service based on key/property values. The key is the id of the message being looked for and the returned value is the message in the language requested. There are 3 sources where properties are looked for (in the specified order):

  1. If there's a "documentBundles" property in the XWiki Preferences page then the XWiki documents listed there (separated by commas) are considered the source for properties
  2. If there's a "xwiki.documentBundles" property in the XWiki configuration file (xwiki.cfg) then the XWiki documents listed there (separated by commas) are considered for source for properties
  3. The Resource Bundle passed in the constructor
If the property is not found in any of these 3 sources then the key is returned in place of the value. In addition the property values are cached for better performance but if one of the XWiki documents containing the properties is modified, its content is cached again next time a key is asked.

Version:
$Id: 3c574ac610b5bab2ebfac11e3dadc886869ab6fa $

Field Summary
protected  ResourceBundle bundle
          Deprecated. The default Resource Bundle to fall back to if no document bundle is found when trying to get a key.
protected  XWikiContext context
          Deprecated. 
 
Constructor Summary
XWikiMessageTool(ContextualLocalizationManager localization)
          Deprecated.  
XWikiMessageTool(ResourceBundle bundle, XWikiContext context)
          Deprecated.  
 
Method Summary
 String get(String key)
          Deprecated.  
 String get(String key, List<?> params)
          Deprecated. Find a translation and then replace any parameters found in the translation by the passed params parameters.
 String get(String key, Object... params)
          Deprecated. Find a translation and then replace any parameters found in the translation by the passed parameters.
 XWikiDocument getDocumentBundle(String documentName)
          Deprecated. Helper method to help get a translated version of a document.
protected  List<String> getDocumentBundleNames()
          Deprecated.  
 Properties getDocumentBundleProperties(XWikiDocument docBundle)
          Deprecated.  
 List<XWikiDocument> getDocumentBundles()
          Deprecated.  
 List<XWikiDocument> getDocumentBundles(String documentName, String defaultLanguage)
          Deprecated. Helper method to help get a translated version of a document.
protected  String getTranslation(String key)
          Deprecated. Looks for a translation in the list of internationalization document bundles.
protected  XWikiContext getXWikiContext()
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bundle

protected ResourceBundle bundle
Deprecated. 
The default Resource Bundle to fall back to if no document bundle is found when trying to get a key.


context

@Deprecated
protected XWikiContext context
Deprecated. 
The XWikiContext object, used to get access to XWiki primitives for loading documents.

Constructor Detail

XWikiMessageTool

public XWikiMessageTool(ContextualLocalizationManager localization)
Deprecated. 
Parameters:
localization - the localization manager
componentManager - used to get the proper renderer
context - the XWiki context

XWikiMessageTool

public XWikiMessageTool(ResourceBundle bundle,
                        XWikiContext context)
Deprecated. 
Parameters:
bundle - the default Resource Bundle to fall back to if no document bundle is found when trying to get a key
context - the XWikiContext object, used to get access to XWiki primitives for loading documents
Method Detail

getXWikiContext

protected XWikiContext getXWikiContext()
Deprecated. 

get

public String get(String key)
Deprecated. 
Parameters:
key - the key identifying the message to look for
Returns:
the message in the defined language. The message should be a simple string without any parameters. If you need to pass parameters see get(String, java.util.List)
See Also:
for more details on the algorithm used to find the message

get

public String get(String key,
                  List<?> params)
Deprecated. 
Find a translation and then replace any parameters found in the translation by the passed params parameters. The format is the one used by MessageFormat.

Note: The reason we're using a List instead of an Object array is because we haven't found how to easily create an Array in Velocity whereas a List is easily created. For example: $msg.get("key", ["1", "2", "3"]) .

Parameters:
key - the key of the string to find
params - the list of parameters to use for replacing "{N}" elements in the string. See MessageFormat for the full syntax
Returns:
the translated string with parameters resolved

get

public String get(String key,
                  Object... params)
Deprecated. 
Find a translation and then replace any parameters found in the translation by the passed parameters. The format is the one used by MessageFormat.

Parameters:
key - the key of the string to find
params - the list of parameters to use for replacing "{N}" elements in the string. See MessageFormat for the full syntax
Returns:
the translated string with parameters resolved

getDocumentBundleNames

protected List<String> getDocumentBundleNames()
Deprecated. 
Returns:
the list of internationalization document bundle names as a list of XWiki page names ("Space.Document") or an empty list if no such documents have been found
See Also:
for more details on the algorithm used to find the document bundles

getDocumentBundles

public List<XWikiDocument> getDocumentBundles()
Deprecated. 
Returns:
the internationalization document bundles (a list of )
See Also:
for more details on the algorithm used to find the document bundles

getDocumentBundle

public XWikiDocument getDocumentBundle(String documentName)
Deprecated. 
Helper method to help get a translated version of a document. It handles any exception raised to make it easy to use.

Parameters:
documentName - the document's name (eg Space.Document)
Returns:
the document object corresponding to the passed document's name. A translated version of the document for the current Locale is looked for.

getDocumentBundles

public List<XWikiDocument> getDocumentBundles(String documentName,
                                              String defaultLanguage)
Deprecated. 
Helper method to help get a translated version of a document. It handles any exception raised to make it easy to use.

Parameters:
documentName - the document's name (eg Space.Document)
defaultLanguage - default language
Returns:
the document object corresponding to the passed document's name. A translated version of the document for the current Locale is looked for.

getDocumentBundleProperties

public Properties getDocumentBundleProperties(XWikiDocument docBundle)
Deprecated. 
Parameters:
docBundle - the document bundle.
Returns:
properties of the document bundle.

getTranslation

protected String getTranslation(String key)
Deprecated. 
Looks for a translation in the list of internationalization document bundles. It first checks if the translation can be found in the cache.

Parameters:
key - the key identifying the translation
Returns:
the translation or null if not found or if the passed key is null


Copyright © 2004-2013 XWiki. All Rights Reserved.