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

This commit is contained in:
Uwe Schindler 2016-08-27 08:38:42 +02:00
parent 7d2f42e543
commit e99d970674
2 changed files with 26 additions and 11 deletions

View File

@ -83,6 +83,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
----------------------

View File

@ -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);