Search in sources :

Example 6 with DefaultInternationalString

use of org.apache.sis.util.iso.DefaultInternationalString in project sis by apache.

the class PT_FreeText method toCharSequence.

/**
 * Returns the content of this {@code <gco:CharacterString>} as an {@code InternationalString}.
 *
 * @return the character sequence for this {@code <gco:CharacterString>}.
 */
@Override
protected CharSequence toCharSequence() {
    // May be null.
    String defaultValue = toString();
    if (defaultValue != null && contains(defaultValue)) {
        /*
             * If the <gco:CharacterString> value is repeated in one of the
             * <lan:LocalisedCharacterString> elements, keep only the localized
             * version  (because it specifies the locale, while the unlocalized
             * string saids nothing on that matter).
             */
        defaultValue = null;
    }
    /*
         * Create the international string with all locales found in the <gml:textGroup>
         * element. If the <gml:textGroup> element is missing or empty, then we will use
         * an instance of SimpleInternationalString instead than the more heavy
         * DefaultInternationalString.
         */
    DefaultInternationalString i18n = null;
    final TextGroup[] textGroup = this.textGroup;
    if (textGroup != null) {
        for (final TextGroup group : textGroup) {
            if (group != null) {
                final LocalisedCharacterString[] localised = group.localized;
                if (localised != null) {
                    for (final LocalisedCharacterString text : localised) {
                        if (text != null) {
                            if (i18n == null) {
                                i18n = new DefaultInternationalString(defaultValue);
                            }
                            i18n.add(text.locale, text.text);
                        }
                    }
                }
            }
        }
    }
    if (i18n == null && defaultValue != null) {
        return new SimpleInternationalString(defaultValue);
    }
    return i18n;
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) InternationalString(org.opengis.util.InternationalString) GO_CharacterString(org.apache.sis.internal.jaxb.gco.GO_CharacterString)

Example 7 with DefaultInternationalString

use of org.apache.sis.util.iso.DefaultInternationalString in project sis by apache.

the class NamedIdentifierTest method createI18N.

/**
 * Creates an internationalized name with a code set to "name" localized in English, French and Japanese.
 */
private NamedIdentifier createI18N() {
    final DefaultInternationalString i18n = new DefaultInternationalString();
    i18n.add(Locale.ENGLISH, "name");
    i18n.add(Locale.FRENCH, "nom");
    i18n.add(Locale.JAPANESE, "名前");
    return new NamedIdentifier(Citations.EPSG, i18n);
}
Also used : DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString)

Aggregations

DefaultInternationalString (org.apache.sis.util.iso.DefaultInternationalString)7 Context (org.apache.sis.internal.jaxb.Context)2 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)2 Locale (java.util.Locale)1 GO_CharacterString (org.apache.sis.internal.jaxb.gco.GO_CharacterString)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 Test (org.junit.Test)1 InternationalString (org.opengis.util.InternationalString)1