Retrieve locales used in label statements instead of only selectable locales
This commit is contained in:
parent
dc56107d4d
commit
f4f6dddb11
1 changed files with 27 additions and 23 deletions
|
@ -15,6 +15,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForPersonPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForPersonPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,12 +248,12 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
||||||
|
|
||||||
private void addFormSpecificData(EditConfigurationVTwo config,
|
private void addFormSpecificData(EditConfigurationVTwo config,
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) {
|
||||||
|
ArrayList<Literal> existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq);
|
||||||
//Get all language codes/labels in the system, and this list is sorted by language name
|
//Get all language codes/labels in the system, and this list is sorted by language name
|
||||||
List<HashMap<String, String>> locales = this.getLocales(vreq);
|
List<HashMap<String, String>> locales = this.getLocales(vreq, existingLabels);
|
||||||
//Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal
|
//Get code to label hashmap - we use this to get the language name for the language code returned in the rdf literal
|
||||||
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
||||||
//the labels already added by the user
|
//the labels already added by the user
|
||||||
ArrayList<Literal> existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq);
|
|
||||||
int numberExistingLabels = existingLabels.size();
|
int numberExistingLabels = existingLabels.size();
|
||||||
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
||||||
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq);
|
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq);
|
||||||
|
@ -466,30 +468,32 @@ public class ManageLabelsForPersonGenerator extends BaseEditConfigurationGenerat
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get locales present in list of literals
|
||||||
|
public List<HashMap<String, String>> getLocales(VitroRequest vreq,
|
||||||
|
List<Literal> existingLiterals) {
|
||||||
|
Set<Locale> locales = new HashSet<Locale>();
|
||||||
|
for(Literal literal : existingLiterals) {
|
||||||
|
String language = literal.getLanguage();
|
||||||
|
if(!StringUtils.isEmpty(language)) {
|
||||||
|
locales.add(LanguageFilteringUtils.languageToLocale(language));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (locales.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
||||||
|
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
||||||
|
for (Locale locale : locales) {
|
||||||
|
try {
|
||||||
|
list.add(buildLocaleMap(locale, currentLocale));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
log.warn("Can't show locale '" + locale + "': " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
//get locales
|
|
||||||
public List<HashMap<String, String>> getLocales(VitroRequest vreq) {
|
|
||||||
List<Locale> selectables = SelectedLocale.getSelectableLocales(vreq);
|
|
||||||
if (selectables.isEmpty()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
|
|
||||||
Locale currentLocale = SelectedLocale.getCurrentLocale(vreq);
|
|
||||||
for (Locale locale : selectables) {
|
|
||||||
try {
|
|
||||||
list.add(buildLocaleMap(locale, currentLocale));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
log.warn("Can't show the Locale selector for '" + locale
|
|
||||||
+ "': " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public HashMap<String, String> getFullCodeToLanguageNameMap(List<HashMap<String, String>> localesList) {
|
public HashMap<String, String> getFullCodeToLanguageNameMap(List<HashMap<String, String>> localesList) {
|
||||||
HashMap<String, String> codeToLanguageMap = new HashMap<String, String>();
|
HashMap<String, String> codeToLanguageMap = new HashMap<String, String>();
|
||||||
for(Map<String, String> locale: localesList) {
|
for(Map<String, String> locale: localesList) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue