org.apache.sling.i18n.impl
Class JcrResourceBundleProvider

java.lang.Object
  extended by org.apache.sling.i18n.impl.JcrResourceBundleProvider
All Implemented Interfaces:
javax.jcr.observation.EventListener, ResourceBundleProvider

@Service(value=ResourceBundleProvider.class)
public class JcrResourceBundleProvider
extends Object
implements ResourceBundleProvider, javax.jcr.observation.EventListener

The JcrResourceBundleProvider implements the ResourceBundleProvider interface creating ResourceBundle instances from resources stored in the repository.


Field Summary
 
Fields inherited from interface org.apache.sling.i18n.ResourceBundleProvider
BUNDLE_REQ_ATTR
 
Constructor Summary
JcrResourceBundleProvider()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext context)
          Activates and configures this component with the repository access details and the default locale to use
protected  void bindResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory)
          Binds a new ResourceResolverFactory.
protected  void deactivate()
           
 Locale getDefaultLocale()
          Returns the configured default Locale which is used as a fallback for getResourceBundle(Locale) and also as the basis for any messages requested from resource bundles.
 ResourceBundle getResourceBundle(Locale locale)
          Returns the ResourceBundle for the given locale.
 ResourceBundle getResourceBundle(String baseName, Locale locale)
          Returns a ResourceBundle for the given locale.
 void onEvent(javax.jcr.observation.EventIterator events)
          Called whenever something is changed inside of jcr:language or sling:Message nodes.
protected  void unbindResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory)
          Unbinds the ResourceResolverFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JcrResourceBundleProvider

public JcrResourceBundleProvider()
Method Detail

getDefaultLocale

public Locale getDefaultLocale()
Returns the configured default Locale which is used as a fallback for getResourceBundle(Locale) and also as the basis for any messages requested from resource bundles.

Specified by:
getDefaultLocale in interface ResourceBundleProvider

getResourceBundle

public ResourceBundle getResourceBundle(Locale locale)
Returns the ResourceBundle for the given locale.

Specified by:
getResourceBundle in interface ResourceBundleProvider
Parameters:
locale - The Locale for which to return the resource bundle. If this is null the configured default locale is assumed.
Returns:
The ResourceBundle for the given locale.
Throws:
MissingResourceException - If the ResourceResolver is not available to access the resources.

getResourceBundle

public ResourceBundle getResourceBundle(String baseName,
                                        Locale locale)
Description copied from interface: ResourceBundleProvider
Returns a ResourceBundle for the given locale.

Specified by:
getResourceBundle in interface ResourceBundleProvider
Parameters:
baseName - The base name for the resource bundle. If this is null, the same resource bundle will be returned as when calling the ResourceBundleProvider.getResourceBundle(Locale) method.
locale - The Locale for which to return the resource bundle. If this is null the default locale as returned by ResourceBundleProvider.getDefaultLocale() is assumed.
Returns:
The ResourceBundle for the given locale

onEvent

public void onEvent(javax.jcr.observation.EventIterator events)
Called whenever something is changed inside of jcr:language or sling:Message nodes. We just removed all cached resource bundles in this case to force reloading them.

This is much simpler than analyzing the events and trying to be clever about which exact resource bundles to remove from the cache and at the same time care for any resource bundle dependencies.

Specified by:
onEvent in interface javax.jcr.observation.EventListener
Parameters:
events - The actual JCR events are ignored by this implementation.

activate

protected void activate(org.osgi.service.component.ComponentContext context)
Activates and configures this component with the repository access details and the default locale to use


deactivate

protected void deactivate()

bindResourceResolverFactory

protected void bindResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory)
Binds a new ResourceResolverFactory. If we are already bound to another factory, we release that latter one first.


unbindResourceResolverFactory

protected void unbindResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory)
Unbinds the ResourceResolverFactory. If we are bound to this factory, we release it.



Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.