Java Doc for LocalizedTextUtil.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » webwork 2.2.6 » com.opensymphony.xwork.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.opensymphony.xwork.util.LocalizedTextUtil

LocalizedTextUtil
public class LocalizedTextUtil (Code)
Provides support for localization in XWork. Resource bundles are searched in the following order:

  1. ActionClass.properties
  2. BaseClass.properties (all the way to Object.properties)
  3. Interface.properties (every interface and sub-interface)
  4. ModelDriven's model (if implements ModelDriven), for the model object repeat from 1
  5. package.properties (of the directory where class is located and every parent directory all the way to the root directory)
  6. search up the i18n message key hierarchy itself
  7. global resource properties (webwork.custom.i18n.resources) defined in webwork.properties

To clarify #5, while traversing the package hierarchy, WW will look for a file package.properties:

com/
  acme/
    package.properties
    actions/
      package.properties
      FooAction.java
      FooAction.properties

If FooAction.properties does not exist, com/acme/action/package.properties will be searched for, if not found com/acme/package.properties, if not found com/package.properties, etc.

A global resource bundle could be specified through the 'webwork.custom.i18n.resources' property in webwork.properties. The locale can be siwtched by 'webwork.locale' in the webwork.properties as well.

Struts users should be familiar with the application.properties resource bundle, where you can put all the messages in the application that are going to be translated. WebWork, though, splits the resource bundles per action or model class, and you may end up with duplicated messages in those resource bundles. A quick fix for that is to create a file called ActionSupport.properties in com/opensymphony/xwork and put it on your classpath. This will only work well if all your actions subclass ActionSupport.


author:
   Jason Carreira
author:
   Mark Woon
author:
   Rainer Hermanns
author:
   tm_jee
author:
   $Date: 2007-06-30 18:15:16 +0200 (Sat, 30 Jun 2007) $ $Id: LocalizedTextUtil.java 1536 2007-06-30 16:15:16Z tm_jee $


Inner Class :static class MessageFormatKey
Inner Class :static class GetDefaultMessageReturnArg



Method Summary
public static  voidaddDefaultResourceBundle(String resourceBundleName)
     Add's the bundle to the internal list of default bundles.
public static  voidclearDefaultResourceBundles()
     Clears the internal list of resource bundles.
public static  StringfindDefaultText(String aTextName, Locale locale)
     Returns a localized message for the specified key, aTextName.
public static  StringfindDefaultText(String aTextName, Locale locale, Object[] params)
     Returns a localized message for the specified key, aTextName, substituting variables from the array of params into the message.
public static  ResourceBundlefindResourceBundle(String aBundleName, Locale locale)
     Finds the given resorce bundle by it's name.

Will use Thread.currentThread().getContextClassLoader() as the classloader.
Parameters:
  aBundleName - the name of the bundle (usually it's FQN classname).
Parameters:
  locale - the locale.

public static  StringfindText(Class aClass, String aTextName, Locale locale)
     Calls LocalizedTextUtil.findText(Class aClass,String aTextName,Locale locale,String defaultMessage,Object[] args) with aTextName as the default message.
public static  StringfindText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)
     Finds a localized text message for the given key, aTextName.
public static  StringfindText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack)
     This method call will log a warning message (in debug level) if message is not found Finds a localized text message for the given key, aTextName.
public static  StringfindText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound)
     Finds a localized text message for the given key, aTextName.
public static  StringfindText(ResourceBundle bundle, String aTextName, Locale locale)
     Finds a localized text message for the given key, aTextName, in the specified resource bundle with aTextName as the default message.

If a message is found, it will also be interpolated.

public static  StringfindText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args)
     Finds a localized text message for the given key, aTextName, in the specified resource bundle.

If a message is found, it will also be interpolated.

public static  StringfindText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack)
     This method will log a warning (in debug level) if no message is found. Finds a localized text message for the given key, aTextName, in the specified resource bundle.

If a message is found, it will also be interpolated.

public static  StringfindText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound)
     Finds a localized text message for the given key, aTextName, in the specified resource bundle.

If a message is found, it will also be interpolated.

public static  LocalelocaleFromString(String localeStr, Locale defaultLocale)
     Builds a java.util.Locale from a String of the form en_US_foo into a Locale with language "en", country "US" and variant "foo".
public static  voidreset()
     Clears all the internal lists.
public static  voidsetReloadBundles(boolean reloadBundles)
     Should resorce bundles be reloaded.



Method Detail
addDefaultResourceBundle
public static void addDefaultResourceBundle(String resourceBundleName)(Code)
Add's the bundle to the internal list of default bundles.

If the bundle already exists in the list it will be readded.
Parameters:
  resourceBundleName - the name of the bundle to add.




clearDefaultResourceBundles
public static void clearDefaultResourceBundles()(Code)
Clears the internal list of resource bundles.



findDefaultText
public static String findDefaultText(String aTextName, Locale locale)(Code)
Returns a localized message for the specified key, aTextName. Neither the key nor the message is evaluated.
Parameters:
  aTextName - the message key
Parameters:
  locale - the locale the message should be for a localized message based on the specified key, or null if no localized message can be found for it



findDefaultText
public static String findDefaultText(String aTextName, Locale locale, Object[] params)(Code)
Returns a localized message for the specified key, aTextName, substituting variables from the array of params into the message. Neither the key nor the message is evaluated.
Parameters:
  aTextName - the message key
Parameters:
  locale - the locale the message should be for
Parameters:
  params - an array of objects to be substituted into the message text A formatted message based on the specified key, or null if no localized message can be found for it



findResourceBundle
public static ResourceBundle findResourceBundle(String aBundleName, Locale locale)(Code)
Finds the given resorce bundle by it's name.

Will use Thread.currentThread().getContextClassLoader() as the classloader.
Parameters:
  aBundleName - the name of the bundle (usually it's FQN classname).
Parameters:
  locale - the locale. the bundle, null if not found.




findText
public static String findText(Class aClass, String aTextName, Locale locale)(Code)
Calls LocalizedTextUtil.findText(Class aClass,String aTextName,Locale locale,String defaultMessage,Object[] args) with aTextName as the default message.
See Also:   LocalizedTextUtil.findText(Class aClass,String aTextName,Locale locale,String defaultMessage,Object[] args)



findText
public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)(Code)
Finds a localized text message for the given key, aTextName. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:

  1. Look for message in aClass' class hierarchy.
    1. Look for the message in a resource bundle for aClass
    2. If not found, look for the message in a resource bundle for any implemented interface
    3. If not found, traverse up the Class' hierarchy and repeat from the first sub-step
  2. If not found and aClass is a ModelDriven Action, then look for message in the model's class hierarchy (repeat sub-steps listed above).
  3. If not found, look for message in child property. This is determined by evaluating the message key as an OGNL expression. For example, if the key is user.address.state, then it will attempt to see if "user" can be resolved into an object. If so, repeat the entire process fromthe beginning with the object's class as aClass and "address.state" as the message key.
  4. If not found, look for the message in aClass' package hierarchy.
  5. If still not found, look for the message in the default resource bundles.
  6. Return defaultMessage

When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a message for that specific key cannot be found, the general form will also be looked up (i.e. user.phone[*]).

If a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such.
Parameters:
  aClass - the class whose name to use as the start point for the search
Parameters:
  aTextName - the key to find the text message for
Parameters:
  locale - the locale the message should be for
Parameters:
  defaultMessage - the message to be returned if no text message can be found in anyresource bundle the localized text, or null if none can be found and no defaultMessage is provided




findText
public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack)(Code)
This method call will log a warning message (in debug level) if message is not found Finds a localized text message for the given key, aTextName. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:

  1. Look for message in aClass' class hierarchy.
    1. Look for the message in a resource bundle for aClass
    2. If not found, look for the message in a resource bundle for any implemented interface
    3. If not found, traverse up the Class' hierarchy and repeat from the first sub-step
  2. If not found and aClass is a ModelDriven Action, then look for message in the model's class hierarchy (repeat sub-steps listed above).
  3. If not found, look for message in child property. This is determined by evaluating the message key as an OGNL expression. For example, if the key is user.address.state, then it will attempt to see if "user" can be resolved into an object. If so, repeat the entire process fromthe beginning with the object's class as aClass and "address.state" as the message key.
  4. If not found, look for the message in aClass' package hierarchy.
  5. If still not found, look for the message in the default resource bundles.
  6. Return defaultMessage

When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a message for that specific key cannot be found, the general form will also be looked up (i.e. user.phone[*]).

If a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such.

If a message is not found a WARN log will be logged.
Parameters:
  aClass - the class whose name to use as the start point for the search
Parameters:
  aTextName - the key to find the text message for
Parameters:
  locale - the locale the message should be for
Parameters:
  defaultMessage - the message to be returned if no text message can be found in anyresource bundle
Parameters:
  valueStack - the value stack to use to evaluate expressions instead of theone in the ActionContext ThreadLocal the localized text, or null if none can be found and no defaultMessage is provided




findText
public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound)(Code)
Finds a localized text message for the given key, aTextName. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:

  1. Look for message in aClass' class hierarchy.
    1. Look for the message in a resource bundle for aClass
    2. If not found, look for the message in a resource bundle for any implemented interface
    3. If not found, traverse up the Class' hierarchy and repeat from the first sub-step
  2. If not found and aClass is a ModelDriven Action, then look for message in the model's class hierarchy (repeat sub-steps listed above).
  3. If not found, look for message in child property. This is determined by evaluating the message key as an OGNL expression. For example, if the key is user.address.state, then it will attempt to see if "user" can be resolved into an object. If so, repeat the entire process fromthe beginning with the object's class as aClass and "address.state" as the message key.
  4. If not found, look for the message in aClass' package hierarchy.
  5. If still not found, look for the message in the default resource bundles.
  6. Return defaultMessage

When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a message for that specific key cannot be found, the general form will also be looked up (i.e. user.phone[*]).

If a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such.

If a message is not found a WARN log will be logged.
Parameters:
  aClass - the class whose name to use as the start point for the search
Parameters:
  aTextName - the key to find the text message for
Parameters:
  locale - the locale the message should be for
Parameters:
  defaultMessage - the message to be returned if no text message can be found in anyresource bundle
Parameters:
  valueStack - the value stack to use to evaluate expressions instead of theone in the ActionContext ThreadLocal
Parameters:
  warnIfNoMessageFound - log warning message (in debug level) if message is not found. the localized text, or null if none can be found and no defaultMessage is provided




findText
public static String findText(ResourceBundle bundle, String aTextName, Locale locale)(Code)
Finds a localized text message for the given key, aTextName, in the specified resource bundle with aTextName as the default message.

If a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such.
See Also:   LocalizedTextUtil.findText(java.util.ResourceBundle,String,java.util.Locale,String,Object[])




findText
public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args)(Code)
Finds a localized text message for the given key, aTextName, in the specified resource bundle.

If a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such.

If a message is not found a WARN log will be logged.
Parameters:
  bundle - the bundle
Parameters:
  aTextName - the key
Parameters:
  locale - the locale
Parameters:
  defaultMessage - the default message to use if no message was found in the bundle
Parameters:
  args - arguments for the message formatter.




findText
public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack)(Code)
This method will log a warning (in debug level) if no message is found. Finds a localized text message for the given key, aTextName, in the specified resource bundle.

If a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such.

If a message is not found a WARN log will be logged.
Parameters:
  bundle - the bundle
Parameters:
  aTextName - the key
Parameters:
  locale - the locale
Parameters:
  defaultMessage - the default message to use if no message was found in the bundle
Parameters:
  args - arguments for the message formatter.
Parameters:
  valueStack - the OGNL value stack.




findText
public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound)(Code)
Finds a localized text message for the given key, aTextName, in the specified resource bundle.

If a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such.

If a message is not found a WARN log will be logged.
Parameters:
  bundle - the bundle
Parameters:
  aTextName - the key
Parameters:
  locale - the locale
Parameters:
  defaultMessage - the default message to use if no message was found in the bundle
Parameters:
  args - arguments for the message formatter.
Parameters:
  valueStack - the OGNL value stack.




localeFromString
public static Locale localeFromString(String localeStr, Locale defaultLocale)(Code)
Builds a java.util.Locale from a String of the form en_US_foo into a Locale with language "en", country "US" and variant "foo". This will parse the output of java.util.Locale.toString .
Parameters:
  localeStr - The locale String to parse.
Parameters:
  defaultLocale - The locale to use if localeStr is null. requested Locale



reset
public static void reset()(Code)
Clears all the internal lists.



setReloadBundles
public static void setReloadBundles(boolean reloadBundles)(Code)
Should resorce bundles be reloaded.

In WW see webwork.i18n.reload property.
Parameters:
  reloadBundles - reload bundles?




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.