import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
prefValue = getPreferenceStore().
getString(name);
}
+ if (StringUtils.isBlank(prefValue) || (pref == null && !override)){
+ IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof String){
+ return (String)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ return pred.getDefaultValue().toString();
+ }
+ }
+ return prefValue;
+ }
+
}else if (pref != null){
if (pref.getValue() == null){
Object result = PreferencePredicate.getByKey(pref.getPredicate()).getDefaultValue();
if (getPreferenceStore().contains(dbSpecific)){
result = getPreferenceStore().getInt(dbSpecific);
}else{
- result = getPreferenceStore().
- getInt(name);
+ if (result == null){
+ IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof Integer){
+ return (Integer)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ return Integer.valueOf(pred.getDefaultValue().toString());
+ }
+ }
+ return 0;
+ }
}
}
return result;
if (getPreferenceStore().contains(dbSpecific)){
return getPreferenceStore().getBoolean(dbSpecific);
}else{
+ IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof Boolean){
+ return (Boolean)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ return Boolean.valueOf(pred.getDefaultValue().toString());
+ }
+ }
return null;
}
}else{
if (getPreferenceStore().contains(dbSpecific)){
result = getPreferenceStore().getFloat(dbSpecific);
}else{
- result = getPreferenceStore().
- getFloat(name);
+ IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+ if (pred != null){
+ if (pred.getDefaultValue() instanceof Float){
+ return (float)pred.getDefaultValue();
+ }else if (pred.getDefaultValue() != null){
+ return Float.valueOf(pred.getDefaultValue().toString());
+ }
+ }
+ return 0;
}
}
return result;
//Name Details
- getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
+ // getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.NameDetailsView.getKey()), new NameDetailsConfigurator(false).toString());
//Navigator preferences
getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.TaxonNodeOrder.getKey()), NavigatorOrderEnum.RankAndNameOrder.getKey());
getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.SearchForIdentifierAndTitleCache.getKey())), false);
getPreferenceStore().setDefault(createPreferenceString(PreferencePredicate.SearchForIdentifierAsDefault.getKey()), Boolean.valueOf(PreferencePredicate.SearchForIdentifierAsDefault.getDefaultValue().toString()));
getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.SearchForIdentifierAsDefault.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowModifierFreeText.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.ShowModifier.getKey())), false);
+ getPreferenceStore().setDefault(createPreferenceString(prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey())), false);
}
}
public static NameDetailsConfigurator getPreferredNameDetailsConfiguration( boolean local) {
- NameDetailsConfigurator config = new NameDetailsConfigurator(true);
+ NameDetailsConfigurator config = new NameDetailsConfigurator();
CdmPreferenceCache cache = CdmPreferenceCache.instance();
CdmPreference preference = null;
String value;
value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), local);
}
if (value!= null){
- String [] sections = value.split(";");
- Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
- String[] sectionValues;
- for (String sectionValue: sections){
- sectionValues = sectionValue.split(":");
- sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
- }
- config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
- config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
- config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
- config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
- config.setLSIDActivated(getValue(sectionMap, "lsid"));
- config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
- config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
- config.setRankActivated(getValue(sectionMap, "rank"));
- config.setNameCacheActivated(getValue(sectionMap, "nameCache"));
- config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
- config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
- config.setAuthorCacheActivated(getValue(sectionMap, "authorCache"));
- config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
- config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
- config.setProtologueActivated(getValue(sectionMap,"protologue"));
- config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
- config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
- config.setHybridActivated(getValue(sectionMap,"hybrid"));
- config.setNameApprobiationActivated(getValue(sectionMap, "nameApproviation"));
+ fillNameDetailsConfigurator(config, value);
+
+
}else {
return null;
}
return config;
}
- public static NameDetailsConfigurator getPreferredNameDetailsConfiguration() {
- NameDetailsConfigurator config = new NameDetailsConfigurator(true);
-
- String value;
-
- value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), false);
- if (value != null){
- String [] sections = value.split(";");
- Map<String, Boolean> sectionMap = new HashMap<String, Boolean>();
- String[] sectionValues;
- for (String sectionValue: sections){
+ public static void fillNameDetailsConfigurator(NameDetailsConfigurator config, String value) {
+ String [] sections = value.split(";");
+ Map<String, Boolean> sectionMap = new HashMap<>();
+ String[] sectionValues;
+ for (String sectionValue: sections){
+ if (sectionValue.contains(":")){
sectionValues = sectionValue.split(":");
sectionMap.put(sectionValues[0], Boolean.valueOf(sectionValues[1]));
}
+ }
+ for (Field field: config.getClass().getDeclaredFields()){
+ try {
+ config.getClass().getDeclaredField(field.getName()).set(config, getValue(sectionMap, field.getName()));
+ } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException
+ | SecurityException e) {
+ logger.debug(e.getMessage());
+ }
+ }
+ }
- config.setSimpleDetailsViewActivated(getValue(sectionMap, "simpleViewActivated"));
-
- config.setTaxonSectionActivated(getValue(sectionMap, "taxon"));
-
- config.setSecDetailsActivated(getValue(sectionMap, "taxon.SecDetails"));
- config.setSecEnabled(getValue(sectionMap, "taxon.SecEnabled"));
-
- config.setLSIDActivated(getValue(sectionMap, "lsid"));
-
- config.setNomenclaturalCodeActived(getValue(sectionMap, "nc"));
-
- config.setAppendedPhraseActivated(getValue(sectionMap, "ap"));
-
- config.setRankActivated(getValue(sectionMap, "rank"));
-
- config.setAtomisedEpithetsActivated(getValue(sectionMap, "atomisedEpithets"));
-
- config.setAuthorshipSectionActivated(getValue(sectionMap,"author"));
-
- config.setNomenclaturalReferenceSectionActivated(sectionMap.get("nomRef"));
-
- config.setNomenclaturalStatusSectionActivated(getValue(sectionMap, "nomStat"));
-
- config.setProtologueActivated(getValue(sectionMap,"protologue"));
-
- config.setTypeDesignationSectionActivated(getValue(sectionMap,"typeDes"));
+ public static NameDetailsConfigurator getPreferredNameDetailsConfiguration() {
+ NameDetailsConfigurator config = new NameDetailsConfigurator();
- config.setNameRelationsSectionActivated(getValue(sectionMap,"nameRelation"));
+ String value;
- config.setHybridActivated(getValue(sectionMap,"hybrid"));
+ value = getStringValue(PreferencePredicate.NameDetailsView.getKey(), false);
+ if (value != null){
+ fillNameDetailsConfigurator(config, value);
+ }else {
+ return null;
}
return config;
}
}
public static Abcd206ImportConfigurator getLocalAbcdImportConfigurator(boolean skipCheckOverride){
Abcd206ImportConfigurator config = Abcd206ImportConfigurator.NewInstance(null,null);
+ CdmPreference pref = CdmPreferenceCache.instance().get(PreferencePredicate.AbcdImportConfig.getKey());
+ if (pref == null || pref.isAllowOverride()){
String configString = PreferencesUtil.getStringValue(IPreferenceKeys.LAST_USED_ABCD_CONFIG);
- if (StringUtils.isBlank(configString)){
- configString = getStringValue(PreferencePredicate.AbcdImportConfig.getKey(), skipCheckOverride);
- extractAbcdConfiguratorFromPreferenceString(config, configString);
- if (config.getNomenclaturalCode() == null){
- config.setNomenclaturalCode(getPreferredNomenclaturalCode());
+ if (StringUtils.isBlank(configString)){
+ configString = getStringValue(PreferencePredicate.AbcdImportConfig.getKey(), skipCheckOverride);
+ extractAbcdConfiguratorFromPreferenceString(config, configString);
+ if (config.getNomenclaturalCode() == null){
+ config.setNomenclaturalCode(getPreferredNomenclaturalCode());
+ }
+ }else{
+ config = Abcd206ImportConfigurator.NewInstance(null, null);
+ PreferencesUtil.extractAbcdConfiguratorFromPreferenceString(config, configString);
}
}else{
- config = Abcd206ImportConfigurator.NewInstance(null, null);
- PreferencesUtil.extractAbcdConfiguratorFromPreferenceString(config, configString);
+ extractAbcdConfiguratorFromPreferenceString(config, pref.getValue());
}
return config;