use of org.n52.janmayen.i18n.MultilingualString in project arctic-sea by 52North.
the class JsonSettingsDao method decodeMultilingualString.
protected MultilingualString decodeMultilingualString(JsonNode json) {
MultilingualString mls = new MultilingualString();
json.fields().forEachRemaining(e -> {
Locale locale = LocaleHelper.decode(e.getKey());
mls.addLocalization(locale, e.getValue().asText());
});
return mls;
}
use of org.n52.janmayen.i18n.MultilingualString in project arctic-sea by 52North.
the class SettingValueFactory method decodeMultiLingualStringValue.
static MultilingualString decodeMultiLingualStringValue(String stringValue) {
MultilingualString ms = new MultilingualString();
if (!nullOrEmpty(stringValue)) {
JsonNode json = Json.loadString(stringValue);
Iterator<String> it = json.fieldNames();
while (it.hasNext()) {
String lang = it.next();
String value = json.path(lang).asText();
ms.addLocalization(LocaleHelper.decode(lang), value);
}
}
return ms;
}
use of org.n52.janmayen.i18n.MultilingualString in project arctic-sea by 52North.
the class SettingValueFactoryTest method testMultilingualStringParsing.
@Test
public void testMultilingualStringParsing() {
String s = "{\"de\":\"Hallo\",\"en\":\"Hello\"}";
MultilingualString ms = SettingValueFactory.decodeMultiLingualStringValue(s);
errors.checkThat(ms, is(notNullValue()));
errors.checkThat(ms.getLocalization(Locale.ENGLISH), is(Optional.of(new LocalizedString(Locale.ENGLISH, "Hello"))));
errors.checkThat(ms.getLocalization(Locale.GERMAN), is(Optional.of(new LocalizedString(Locale.GERMAN, "Hallo"))));
}
use of org.n52.janmayen.i18n.MultilingualString in project arctic-sea by 52North.
the class I18NSerializer method decode.
public MultilingualString decode(String string) {
MultilingualString mls = new MultilingualString();
for (String s : string.split(TUPLE_SEPERATOR)) {
String[] kvp = s.split(TOKEN_SEPERATOR);
mls.addLocalization(LocaleHelper.decode(kvp[0]), decodeText(kvp[1]));
}
return mls;
}
use of org.n52.janmayen.i18n.MultilingualString in project arctic-sea by 52North.
the class OwsServiceIdentificationFactory method setAbstract.
@Setting(OwsServiceIdentificationFactorySettings.ABSTRACT)
public void setAbstract(Object description) throws ConfigurationError {
Validation.notNull("Service Identification Abstract", description);
if (description instanceof MultilingualString) {
this.abstrakt = (MultilingualString) description;
} else if (description instanceof String) {
this.abstrakt = createFromString(description);
} else {
throw new ConfigurationError(String.format("%s is not supported as abstract!", description.getClass().getName()));
}
setRecreate();
}
Aggregations