|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectwicket.resource.loader.AbstractStringResourceLoader
public abstract class AbstractStringResourceLoader
This abstract string resource loader provides two helper functions to
retrieve the message associated with a key, a locale and a style. The simple
one uses the Class provided and its parent classes to find the
associated message. The more complex one uses in addition the component
provided and its parent containers.
The component based string resource loader attempts to find the resource from
a bundle that corresponds to the supplied component object or one of its
parent containers. Generally the component will be an instance of
Page, but it may also be an instance of any reusable
component that is packaged along with its own resource files. If the
component is not an instance of Page then it must be a
component that has already been added to a page.
The search order for resources is built around the containers that hold the component (if it is not a page). Consider a Page that contains a Panel that contains a Label. If we pass the Label as the component then resource loading will first look for the resource against the page, then against the panel and finally against the label.
The above search order may seem slightly odd at first, but can be explained thus: Team A writes a new component X and packages it as a reusable Wicket component along with all required resources. Team B then creates a new container component Y that holds a instance of an X. However, Team B wishes the text to be different to that which was provided with X so rather than needing to change X, they include override values in the resources for Y. Finally, Team C makes use of component Y in a page they are writing. Initially they are happy with the text for Y so they do not include any override values in the resources for the page. However, after demonstrating to the customer, the customer requests the text for Y to be different. Team C need only provide override values against their page and thus do not need to change Y.
This implementation is fully aware of both locale and style values when trying to obtain the appropriate resources.
In addition to the above search order, each key will be pre-pended with the relative path of the current component related to the component that is being searched. E.g. assume a component hierarchy like page1.form1.input1 and your are requesting a key named 'RequiredValidator'. Wicket will search the property in the following order:
page1.properties => form1.input1.RequiredValidator
page1.properties => RequiredValidator
form1.properties => input1.RequiredValidator
form1.properties => RequiredValidator
input1.properties => RequiredValidator
myApplication.properties => page1.form1.input1.RequiredValidator
myApplication.properties => RequiredValidator
In addition to the above search order, each component that is being searched for a resource also includes the resources from any parent classes that it inherits from. For example, PageA extends CommonBasePage which in turn extends WebPage. When a resource lookup is requested on PageA, the resource bundle for PageA is first checked. If the resource is not found in this bundle then the resource bundle for CommonBasePage is checked. This allows designers of base pages and components to define default sets of string resources and then developers implementing subclasses to either override or extend these in their own resource bundle.
You may enable log debug messages for this class to fully understand the search order.
| Field Summary | |
|---|---|
protected Application |
application
Wickets application object |
| Constructor Summary | |
|---|---|
AbstractStringResourceLoader(Application application)
Create and initialise the resource loader. |
|
| Method Summary | |
|---|---|
protected Properties |
getProperties(java.lang.Class clazz,
java.util.Locale locale,
java.lang.String style)
Get (or load) the properties associated with clazz, locale and style. |
protected boolean |
isStopResourceSearch(java.lang.Class clazz)
Check the supplied class to see if it is one that we shouldn't bother further searches up the class hierarchy for properties. |
java.lang.String |
loadStringResource(java.lang.Class clazz,
java.lang.String key,
java.util.Locale locale,
java.lang.String style)
Get the string resource for the given combination of class, key, locale and style. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Application application
| Constructor Detail |
|---|
public AbstractStringResourceLoader(Application application)
application - Wickets application object| Method Detail |
|---|
public java.lang.String loadStringResource(java.lang.Class clazz,
java.lang.String key,
java.util.Locale locale,
java.lang.String style)
loadStringResource in interface IStringResourceLoaderclazz - The Class to find resources to be loadedkey - The key to obtain the string forlocale - The locale identifying the resource set to select the strings
fromstyle - The (optional) style identifying the resource set to select
the strings from (see Session)
protected Properties getProperties(java.lang.Class clazz,
java.util.Locale locale,
java.lang.String style)
clazz - The class to find resources to be loadedlocale - The locale identifying the resource set to select the strings
fromstyle - The (optional) style identifying the resource set to select
the strings from (see Session)
protected boolean isStopResourceSearch(java.lang.Class clazz)
clazz - The class to check
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||