Search in sources :

Example 1 with MultilingualString

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;
}
Also used : Locale(java.util.Locale) MultilingualString(org.n52.janmayen.i18n.MultilingualString)

Example 2 with MultilingualString

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;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString)

Example 3 with MultilingualString

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"))));
}
Also used : MultilingualString(org.n52.janmayen.i18n.MultilingualString) LocalizedString(org.n52.janmayen.i18n.LocalizedString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) LocalizedString(org.n52.janmayen.i18n.LocalizedString) Test(org.junit.Test)

Example 4 with MultilingualString

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;
}
Also used : MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) LocalizedString(org.n52.janmayen.i18n.LocalizedString)

Example 5 with MultilingualString

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();
}
Also used : ConfigurationError(org.n52.faroe.ConfigurationError) MultilingualString(org.n52.janmayen.i18n.MultilingualString) MultilingualString(org.n52.janmayen.i18n.MultilingualString) Setting(org.n52.faroe.annotation.Setting)

Aggregations

MultilingualString (org.n52.janmayen.i18n.MultilingualString)10 LocalizedString (org.n52.janmayen.i18n.LocalizedString)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Locale (java.util.Locale)2 ConfigurationError (org.n52.faroe.ConfigurationError)2 Setting (org.n52.faroe.annotation.Setting)2 URI (java.net.URI)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Entry (java.util.Map.Entry)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 OwsCode (org.n52.shetland.ogc.ows.OwsCode)1 OwsKeyword (org.n52.shetland.ogc.ows.OwsKeyword)1 OwsLanguageString (org.n52.shetland.ogc.ows.OwsLanguageString)1 OwsServiceIdentification (org.n52.shetland.ogc.ows.OwsServiceIdentification)1