LocaleContext.java

  1. package fr.sii.ogham.core.template.context;

  2. import java.util.Locale;
  3. import java.util.Map;

  4. import fr.sii.ogham.core.exception.template.ContextException;

  5. /**
  6.  * A context that also provides {@link Locale} information for
  7.  * internationalization. It allows to explicitly specify the language.
  8.  *
  9.  * @author AurĂ©lien Baudet
  10.  *
  11.  */
  12. public class LocaleContext implements Context {
  13.     /**
  14.      * The context that contains the variables
  15.      */
  16.     private final Context delegate;
  17.    
  18.     /**
  19.      * The locale to use
  20.      */
  21.     private final Locale locale;

  22.     public LocaleContext(Context delegate, Locale locale) {
  23.         super();
  24.         this.delegate = delegate;
  25.         this.locale = locale;
  26.     }

  27.     public LocaleContext(Object bean, Locale locale) {
  28.         this(new BeanContext(bean), locale);
  29.     }

  30.     @Override
  31.     public Map<String, Object> getVariables() throws ContextException {
  32.         return delegate.getVariables();
  33.     }

  34.     public Locale getLocale() {
  35.         return locale;
  36.     }

  37.     public Context getDelegate() {
  38.         return delegate;
  39.     }
  40. }