public class ResourceBundleContentProvider extends Object implements IContentProvider
Adapts a ResourceBundle
to an IContentProvider
.
Emulates behaviour of f:loadBundle tag, generating "???key???" for the value of a missing resources.
Used internally by BaseFacesPreferencesBean.getPortletResources()
and BaseApplicationBean.getApplicationResources()
.
ResourceBundle rb = new ListResourceBundle { protected Object[][] getContents() { return new Object[][]{ {"company.name", "webMethods"}, } }; IContentProvider provider = new ResourceBundleContentProvider(rb); String contactName = provider.getValue("company.name"); // returns "webMethods"
Modifier and Type | Field and Description |
---|---|
protected ResourceBundle |
m_bundle |
Constructor and Description |
---|
ResourceBundleContentProvider()
Default constructor.
|
ResourceBundleContentProvider(ResourceBundle bundle)
Initializes provider with the given resource bundle.
|
Modifier and Type | Method and Description |
---|---|
Object[] |
getPropertyKeys()
Returns keys in the resource bundle
|
ResourceBundle |
getResourceBundle()
Returns wrapped resource bundle
|
Class<?> |
getType(Object propertyKey)
Returns java type of the given property
|
Object |
getValue(Object propertyKey)
Returns the value from the resource bundle for the given key
|
Object |
getValue(Object propertyKey,
Object[] args)
Returns the value from the resource bundle for the given key
|
boolean |
hasProperty(Object propertyKey)
Always return
true . |
void |
setResourceBundle(ResourceBundle bundle)
Sets resource bundle to wrap
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toString
protected ResourceBundle m_bundle
public ResourceBundleContentProvider()
setResourceBundle(ResourceBundle)
must be called before use.public ResourceBundleContentProvider(ResourceBundle bundle)
bundle
- resource bundlepublic Object getValue(Object propertyKey) throws ELException, PropertyNotFoundException
getValue
in interface IContentProvider
propertyKey
- the key to lookup the value in the resource bundlePropertyNotFoundException
- if property is not supportedELException
public Object getValue(Object propertyKey, Object[] args) throws ELException, PropertyNotFoundException
propertyKey
- the key to lookup the value in the resource bundleargs
- the object array contains string substitution valuesELException
PropertyNotFoundException
public Class<?> getType(Object propertyKey) throws PropertyNotFoundException
IContentProvider
getType
in interface IContentProvider
propertyKey
- the property key of type String
or Integer
Class
PropertyNotFoundException
- if property is not supportedpublic Object[] getPropertyKeys()
getPropertyKeys
in interface IContentProvider
public boolean hasProperty(Object propertyKey)
true
.hasProperty
in interface IContentProvider
propertyKey
- property key of type String
or Integer
true
if property is supportedpublic ResourceBundle getResourceBundle()
public void setResourceBundle(ResourceBundle bundle)
bundle
- resource bundle, must not be null