Package org.apache.sis.util.iso

Examples of org.apache.sis.util.iso.DefaultInternationalString


     * Those types shall be handled in a special way.
     */
    @Test
    @DependsOnMethod("testTreeTableFormat")
    public void testLocalizedFormat() {
        final DefaultInternationalString i18n = new DefaultInternationalString();
        i18n.add(Locale.ENGLISH,  "An English sentence");
        i18n.add(Locale.FRENCH,   "Une phrase en français");
        i18n.add(Locale.JAPANESE, "日本語の言葉");

        final DefaultTreeTable table  = new DefaultTreeTable(NAME, VALUE);
        final TreeTable.Node   root   = table.getRoot();
        root.setValue(NAME, "Root");

View Full Code Here


        Object code      = null;
        Object codeSpace = null;
        Object version   = null;
        Object authority = null;
        Object remarks   = null;
        DefaultInternationalString localized = null;
        /*
         * Iterate through each map entry. This have two purposes:
         *
         *   1) Ignore case (a call to properties.get("foo") can't do that)
         *   2) Find localized remarks.
         *
         * This algorithm is sub-optimal if the map contains a lot of entries of no interest to
         * this identifier. Hopefully, most users will fill a map with only useful entries.
         */
        for (final Map.Entry<String,?> entry : properties.entrySet()) {
            String key   = entry.getKey().trim().toLowerCase();
            Object value = entry.getValue();
            /*switch (key)*/ { // This is a "string in switch" on the JDK7 branch.
                if (key.equals(CODE_KEY)) {
                    code = value;
                    continue;
                }
                else if (key.equals(CODESPACE_KEY)) {
                    codeSpace = value;
                    continue;
                }
                else if (key.equals(VERSION_KEY)) {
                    version = value;
                    continue;
                }
                else if (key.equals(AUTHORITY_KEY)) {
                    if (value instanceof String) {
                        value = Citations.fromName((String) value);
                    }
                    authority = value;
                    continue;
                }
                else if (key.equals(REMARKS_KEY)) {
                    if (value instanceof String) {
                        value = new SimpleInternationalString((String) value);
                    }
                    remarks = value;
                    continue;
                }
            }
            /*
             * Search for additional locales (e.g. "remarks_fr").
             */
            final Locale locale = Locales.parseSuffix(REMARKS_KEY, key);
            if (locale != null) {
                if (localized == null) {
                    localized = new DefaultInternationalString();
                }
                localized.add(locale, (String) value);
            }
        }
        /*
         * Get the localized remarks, if it was not yet set. If a user specified remarks
         * both as InternationalString and as String for some locales (which is a weird
         * usage...), then current implementation discards the later with a warning.
         */
        if (localized != null) {
            if (remarks == null) {
                remarks = localized;
            } else if (remarks instanceof SimpleInternationalString) {
                localized.add(Locale.ROOT, remarks.toString());
                remarks = localized;
            } else {
                Logging.log(ImmutableIdentifier.class, "<init>",
                    Messages.getResources(null).getLogRecord(Level.WARNING, Messages.Keys.LocalesDiscarded));
            }
View Full Code Here

    /**
     * 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(EPSG, i18n);
    }
View Full Code Here

     *         or {@code null} otherwise.
     */
    @SuppressWarnings("fallthrough")
    public static PT_FreeText create(final Context context, final InternationalString text) {
        if (text instanceof DefaultInternationalString) {
            final DefaultInternationalString df = (DefaultInternationalString) text;
            final Set<Locale> locales = df.getLocales();
            final TextGroup[] textGroup = new TextGroup[locales.size()];
            int n = 0;
            for (final Locale locale : locales) {
                if (locale != null && !locale.equals(Locale.ROOT)) {
                    textGroup[n++] = new TextGroup(locale, text.toString(locale));
                }
            }
            if (n != 0) {
                /*
                 * Invoke toString(Locale) instead than toString() even if the locale is null,
                 * since the desired fallback is typically Locale.ROOT instead than the system
                 * default. It is usually safer to avoid null value, but in this particular case
                 * the implementation (DefaultInternationalString) is known to support null.
                 */
                return new PT_FreeText(df.toString(context != null ? context.getLocale() : null),
                        ArraysExt.resize(textGroup, n));
            }
        }
        return null;
    }
View Full Code Here

         * 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);
                            }
                        }
                    }
                }
            }
View Full Code Here

public final strictfp class FreeTextMarshallingTest extends XMLTestCase {
    /**
     * Returns the expected string.
     */
    private static DefaultInternationalString getExpectedI18N() {
        final DefaultInternationalString i18n = new DefaultInternationalString();
        i18n.add(Locale.ENGLISH, "OpenSource Project");
        i18n.add(Locale.FRENCH,  "Projet OpenSource");
        i18n.add(Locale.ITALIAN, "Progetto OpenSource");
        return i18n;
    }
View Full Code Here

     * having loalization in different languages.
     */
    @Test
    @DependsOnMethod("testToUnlocalizedString")
    public void testToLocalizedString() {
        final DefaultInternationalString i18n = new DefaultInternationalString();
        i18n.add(Locale.ENGLISH,  "A word");
        i18n.add(Locale.FRENCH,   "Un mot");
        i18n.add(Locale.JAPANESE, "言葉");
        Context.push(Locale.JAPANESE);
        try {
            assertEquals("言葉", StringAdapter.toString(i18n));
            Context.push(Locale.FRENCH);
            try {
View Full Code Here

     * Implementation of {@link #testLocalizedFormat()}, to be executed only after the default locale
     * has been forced to English. The later is necessary as long as the GeoAPI elements tested below
     * do not have translations in all tested languages.
     */
    private static void testLocalizedFormatInEnglishEnvironment() {
        final DefaultInternationalString i18n = new DefaultInternationalString();
        i18n.add(Locale.ENGLISH,  "An English sentence");
        i18n.add(Locale.FRENCH,   "Une phrase en français");
        i18n.add(Locale.JAPANESE, "日本語の言葉");

        final DefaultTreeTable table  = new DefaultTreeTable(NAME, VALUE);
        final TreeTable.Node   root   = table.getRoot();
        root.setValue(NAME, "Root");

View Full Code Here

TOP

Related Classes of org.apache.sis.util.iso.DefaultInternationalString

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.