001    package com.khubla.pragmatach.framework.i8n;
002    
003    import java.util.Date;
004    import java.util.Set;
005    
006    import com.khubla.pragmatach.framework.api.I8NProvider;
007    import com.khubla.pragmatach.framework.api.PragmatachException;
008    
009    /**
010     * @author tome
011     */
012    public class I8NResolver {
013       /**
014        * providers
015        */
016       private final Set<I8NProvider> i8nProviders;
017    
018       /**
019        * ctor
020        */
021       public I8NResolver(Set<I8NProvider> i8nProviders) {
022          this.i8nProviders = i8nProviders;
023       }
024    
025       /**
026        * get localized date
027        */
028       public String date(String locale, Date date) throws PragmatachException {
029          if (null != i8nProviders) {
030             for (final I8NProvider iI8NProvider : i8nProviders) {
031                final String d = iI8NProvider.getDate(locale, date);
032                if (null != d) {
033                   return d;
034                }
035             }
036          }
037          return null;
038       }
039    
040       /**
041        * search for i8N string across providers
042        */
043       public String text(String locale, String name) throws PragmatachException {
044          if (null != i8nProviders) {
045             for (final I8NProvider iI8NProvider : i8nProviders) {
046                final String r = iI8NProvider.getString(locale, name);
047                if (null != r) {
048                   return r;
049                }
050             }
051          }
052          return null;
053       }
054    }