lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject lucene-solr:branch_6x: SOLR-9430: Fix locale lookup in DIH <propertyWriter/> to use BCP47 language tags to be consistent with other places in Solr. Language names still work for backwards compatibility
Date Sat, 27 Aug 2016 06:39:58 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 97b62160e -> 545ce3871


SOLR-9430: Fix locale lookup in DIH <propertyWriter/> to use BCP47 language tags to
be consistent with other places in Solr. Language names still work for backwards compatibility


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/545ce387
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/545ce387
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/545ce387

Branch: refs/heads/branch_6x
Commit: 545ce387143bec3f598c1f2465afaa9aae12607d
Parents: 97b6216
Author: Uwe Schindler <uschindler@apache.org>
Authored: Sat Aug 27 08:38:42 2016 +0200
Committer: Uwe Schindler <uschindler@apache.org>
Committed: Sat Aug 27 08:39:42 2016 +0200

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  4 +++
 .../dataimport/SimplePropertiesWriter.java      | 33 +++++++++++++-------
 2 files changed, 26 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/545ce387/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0bb23a2..7f0e49b 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -47,6 +47,10 @@ Bug Fixes
 
 * SOLR-9439: Shard split clean up logic for older failed splits is faulty. (shalin)
 
+* SOLR-9430: Fix locale lookup in DIH <propertyWriter/> to use BCP47 language tags
+  to be consistent with other places in Solr. Language names still work for backwards
+  compatibility. (Uwe Schindler, Boris Steiner)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/545ce387/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java
b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java
index 92527bb..1ee18ef 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java
@@ -30,11 +30,13 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.IllformedLocaleException;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 
 import org.apache.lucene.util.IOUtils;
+import org.apache.solr.common.util.SuppressForbidden;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.core.SolrResourceLoader;
 import org.slf4j.Logger;
@@ -90,16 +92,7 @@ public class SimplePropertiesWriter extends DIHProperties {
     }
     findDirectory(dataImporter, params);
     if(params.get(LOCALE) != null) {
-      String localeStr = params.get(LOCALE);
-      for (Locale l : Locale.getAvailableLocales()) {
-        if(localeStr.equals(l.getDisplayName(Locale.ROOT))) {
-          locale = l;
-          break;
-        }
-      }
-      if(locale==null) {
-        throw new DataImportHandlerException(SEVERE, "Unsupported locale for PropertWriter:
" + localeStr);
-      }
+      locale = getLocale(params.get(LOCALE));
     } else {
       locale = Locale.ROOT;
     }    
@@ -108,7 +101,25 @@ public class SimplePropertiesWriter extends DIHProperties {
     } else {
       dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);
     }    
-  }  
+  }
+  
+  @SuppressForbidden(reason = "Usage of outdated locale parsing with Locale#toString() because
of backwards compatibility")
+  private Locale getLocale(String name) {
+    if (name == null) {
+      return Locale.ROOT;
+    }
+    for (final Locale l : Locale.getAvailableLocales()) {
+      if(name.equals(l.toString()) || name.equals(l.getDisplayName(Locale.ROOT))) {
+        return locale;
+      }
+    }
+    try {
+      return new Locale.Builder().setLanguageTag(name).build();
+    } catch (IllformedLocaleException ex) {
+      throw new DataImportHandlerException(SEVERE, "Unsupported locale for PropertyWriter:
" + name);
+    }
+  }
+  
   protected void findDirectory(DataImporter dataImporter, Map<String, String> params)
{
     if(params.get(DIRECTORY) != null) {
       configDir = params.get(DIRECTORY);


Mime
View raw message