Author: mickw
Date: 2006-05-09 11:38:20 +0200 (Tue, 09 May 2006)
New Revision: 2877

Modified:
   
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
   
trunk/src/java/no/schibstedsok/front/searchportal/filters/SiteLocatorFilter.java
   trunk/src/java/no/schibstedsok/front/searchportal/view/i18n/TextMessages.java
Log:
use the site's default locale instead of the JVM/machine 's default locale.


Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
      2006-05-09 08:54:27 UTC (rev 2876)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SiteConfiguration.java
      2006-05-09 09:38:20 UTC (rev 2877)
@@ -41,13 +41,12 @@
 
     private SiteConfiguration(final Context cxt) {
 
-        LOG.debug("Configuration()");
-
+        INSTANCES_LOCK.writeLock().lock();
+        LOG.trace("Configuration(cxt)");
         context = cxt;
 
         propertyLoader = 
context.newPropertiesLoader(SearchConstants.CONFIGURATION_FILE, properties);
-
-        INSTANCES_LOCK.writeLock().lock();
+        
         INSTANCES.put(context.getSite(), this);
         INSTANCES_LOCK.writeLock().unlock();
     }
@@ -59,7 +58,15 @@
         }
         return properties;
     }
+    
+    public String getProperty(final String key) {
 
+        if(properties.size() == 0){
+            propertyLoader.abut();
+        }
+        return properties.getProperty(key);
+    }
+
     /** Find the correct instance handling this Site.
      * We need to use a Context instead of the Site directly so we can handle 
different styles of loading resources.
      **/

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/filters/SiteLocatorFilter.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/filters/SiteLocatorFilter.java
    2006-05-09 08:54:27 UTC (rev 2876)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/filters/SiteLocatorFilter.java
    2006-05-09 09:38:20 UTC (rev 2877)
@@ -240,10 +240,10 @@
         // Just because many norwegians have their computers installed in 
english mode
         //  we can't presume they want their webpages in english.
         //  Therefore we must always initially replace english locales with 
norwegian.
-        final Locale requestLocale = servletRequest.getLocale();
-        final Locale locale = "en".equals(requestLocale.getLanguage())
-                ? Locale.getDefault()
-                : requestLocale;
+        final Locale locale = servletRequest.getLocale();
+//        final Locale locale = "en".equals(requestLocale.getLanguage())
+//                ? Locale.getDefault()
+//                : requestLocale;
 
         LOG.trace(DEBUG_REQUESTED_VHOST + vhost);
 

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/view/i18n/TextMessages.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/view/i18n/TextMessages.java   
    2006-05-09 08:54:27 UTC (rev 2876)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/view/i18n/TextMessages.java   
    2006-05-09 09:38:20 UTC (rev 2877)
@@ -6,6 +6,9 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import no.schibstedsok.common.ioc.ContextWrapper;
+import no.schibstedsok.front.searchportal.configuration.SiteConfiguration;
 import 
no.schibstedsok.front.searchportal.configuration.loader.PropertiesLoader;
 import 
no.schibstedsok.front.searchportal.configuration.loader.PropertiesContext;
 import 
no.schibstedsok.front.searchportal.configuration.loader.UrlResourceLoader;
@@ -32,12 +35,11 @@
     private static final String MESSAGE_RESOURCE = "messages";
 
     /**
-     * No need to synchronise this. Worse that can happen is multiple 
identical INSTANCES are created at the same
-     * time. But only one will persist in the map.
-     *  There might be a reason to synchronise to avoid the multiple calls to 
the search-front-config context to obtain
-     * the resources to improve the performance. But I doubt this would gain 
much, if anything at all.
      */
     private static final Map<Site,TextMessages> INSTANCES = new 
HashMap<Site,TextMessages>();
+    private static final ReentrantReadWriteLock INSTANCES_LOCK = new 
ReentrantReadWriteLock();
+    
+    private static final String SITE_LOCALE_DEFAULT = "site.locale.default";
 
     private static final String DEBUG_LOADING_WITH_LOCALE = "Looking for 
"+MESSAGE_RESOURCE+"_";
     private static final String INFO_USING_DEFAULT_LOCALE = " is falling back 
to the default locale ";
@@ -47,7 +49,10 @@
     public static TextMessages valueOf(final Context cxt) {
 
         final Site site = cxt.getSite();
+        INSTANCES_LOCK.readLock().lock();
         TextMessages instance = INSTANCES.get(site);
+        INSTANCES_LOCK.readLock().unlock();
+        
         if (instance == null) {
             instance = new TextMessages(cxt);
         }
@@ -78,16 +83,39 @@
 
     private TextMessages(final Context cxt) {
 
+        LOG.trace("TextMessages(cxt)");
+        INSTANCES_LOCK.writeLock().lock();
         context = cxt;
 
         // import browser-applicable text messages
         loadKeys(cxt.getSite().getLocale());
 
-        // import servers-default text messages [does not override existing 
values]
-        LOG.info(cxt.getSite()+INFO_USING_DEFAULT_LOCALE+Locale.getDefault());
-        loadKeys(Locale.getDefault());
+        // import messages from site's preferred locale [will not override 
already loaded messages]
+        final String[] prefLocale = 
SiteConfiguration.valueOf(ContextWrapper.wrap(SiteConfiguration.Context.class, 
cxt))
+                .getProperty(SITE_LOCALE_DEFAULT).split("_");
+        
+        
+        switch(prefLocale.length){
+            case 1:
+                LOG.info(cxt.getSite()+INFO_USING_DEFAULT_LOCALE 
+                        + prefLocale[0]);
+                loadKeys(new Locale(prefLocale[0]));
+                break;
+            case 2:
+                LOG.info(cxt.getSite()+INFO_USING_DEFAULT_LOCALE 
+                        + prefLocale[0] + '_' + prefLocale[1]);
+                loadKeys(new Locale(prefLocale[0],prefLocale[1]));
+                break;
+            case 3:
+                LOG.info(cxt.getSite()+INFO_USING_DEFAULT_LOCALE + 
prefLocale[0] 
+                        + '_' + prefLocale[1] + '_' + prefLocale[2]);
+                loadKeys(new 
Locale(prefLocale[0],prefLocale[1],prefLocale[2]));
+                break;
+        }
 
+        
         INSTANCES.put(cxt.getSite(),this);
+        INSTANCES_LOCK.writeLock().unlock();
     }
 
     private void loadKeys(final Locale l) {

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to