You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2016/09/12 09:33:42 UTC
[05/15] lucene-solr:branch_6_2: SOLR-9430: Fix locale lookup in DIH
to use BCP47 language tags to be consistent with other
places in Solr. Language names still work for backwards compatibility
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
(cherry picked from commit 545ce38)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/ebff9d6b
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/ebff9d6b
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/ebff9d6b
Branch: refs/heads/branch_6_2
Commit: ebff9d6b8553897acde758ee4943508e64ffd5fe
Parents: 348b3e8
Author: Uwe Schindler <us...@apache.org>
Authored: Sat Aug 27 12:08:42 2016 +0530
Committer: Shalin Shekhar Mangar <sh...@apache.org>
Committed: Mon Sep 12 10:03:14 2016 +0530
----------------------------------------------------------------------
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/ebff9d6b/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index d5024b8..26441a0 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -32,6 +32,10 @@ Bug Fixes
* SOLR-9439: Shard split clean up logic for older failed splits is faulty. The delete shard API
has also been made more resilient against failures resulting from non-existent cores. (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)
================== 6.2.0 ==================
Versions of Major Components
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ebff9d6b/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);