Package org.geotools.util

Examples of org.geotools.util.GrowableInternationalString


            } else
                continue;
        }
   
        if (translations.size() > 0) {
            GrowableInternationalString intString = new GrowableInternationalString(
                    text.toString()) {
   
                @Override
                public String toString() {
                    return super.toString(null);
                }
   
            };
            for (String lang : translations.keySet()) {
                intString.add("", "_" + lang, translations.get(lang));
            }
            return intString;
        } else {
            String simpleText = getFirstChildValue(root);
            return new SimpleInternationalString(simpleText  == null ? "" : simpleText);
View Full Code Here


    public static InternationalString text(String key, String resourceBundle ){
        return new ResourceInternationalString( resourceBundle, key );
    }
   
    public static InternationalString text(String key, Map<String,String> translations ){
        GrowableInternationalString text = new GrowableInternationalString();
       
        for( Entry<String, String> entry : translations.entrySet() ){
            text.add( key, entry.getKey(), entry.getValue() );
        }
        return text;
    }
View Full Code Here

        }
        return text;
    }
   
    public static InternationalString text(String key, Properties properties ){
        GrowableInternationalString text = new GrowableInternationalString();
       
        for( Entry<Object, Object> entry : properties.entrySet() ){
            text.add( key, (String) entry.getKey(), (String) entry.getValue() );
        }
        return text;
    }
View Full Code Here

         * @param element
         * @param expr
         */
        void element(String element, InternationalString intString) {
            if(intString instanceof GrowableInternationalString) {
                GrowableInternationalString growable = (GrowableInternationalString) intString;
                if(growable.getLocales().isEmpty()) {
                    element(element, intString.toString());
                } else {
                    start(element);
                    chars(intString.toString());
                    for(Locale locale : growable.getLocales()) {
                        if(locale != null) {
                            AttributesImpl atts = new AttributesImpl();
                            atts.addAttribute("", "lang", "lang", "", locale.toString());                       
                            element("Localized", growable.toString(locale),atts );
                        }
                    }
                    end(element);
                }
            } else {
View Full Code Here

    }
   
    @Test
    public void testLocalizedTitle() throws Exception {
        RuleImpl rule = new RuleImpl();
        GrowableInternationalString intString = new GrowableInternationalString("title")
        {

            @Override
            public String toString() {
                return super.toString(null);
            }
           
        };
        intString.add(Locale.ITALIAN, "titolo");
        intString.add(Locale.FRENCH, "titre");
        intString.add(Locale.CANADA_FRENCH, "titre");
        rule.getDescription().setTitle(intString);
        String xml = transformer.transform(rule);
        assertTrue(xml.contains("<sld:Title>title"));
        assertTrue(xml.contains("<sld:Localized lang=\""+Locale.ITALIAN.toString()+"\">titolo</sld:Localized>"));
        assertTrue(xml.contains("<sld:Localized lang=\""+Locale.FRENCH.toString()+"\">titre</sld:Localized>"));
View Full Code Here

        assertTrue(xml.contains("<sld:Localized lang=\""+Locale.CANADA_FRENCH.toString()+"\">titre</sld:Localized>"));
    }
   
    public void testLocalizedAbstract() throws Exception {
        RuleImpl rule = new RuleImpl();
        GrowableInternationalString intString = new GrowableInternationalString("title");
        intString.add(Locale.ITALIAN, "titolo");
        intString.add(Locale.FRENCH, "titre");
        intString.add(Locale.CANADA_FRENCH, "titre");
        rule.getDescription().setAbstract(intString);
        String xml = transformer.transform(rule);
        assertTrue(xml.contains("<sld:Abstract>title"));
        assertTrue(xml.contains("<sld:Localized lang=\""+Locale.ITALIAN.toString()+"\">titolo</sld:Localized>"));
        assertTrue(xml.contains("<sld:Localized lang=\""+Locale.FRENCH.toString()+"\">titre</sld:Localized>"));
View Full Code Here

    // exampleSimpleInternationalStirng end
}

private void exampleGrowableInternationalString() {
    // exampleGrowableInternationalString start
    GrowableInternationalString greeting = new GrowableInternationalString();
   
    // Make use of Locale when adding translations
    greeting.add(Locale.ENGLISH, "Hello World");
    greeting.add(Locale.FRENCH, "Bonjour tout le monde");
    greeting.add("fr", "greeting", "");
   
    System.out.println(greeting); // will output best match to current Locale
    System.out.println(greeting.toString(Locale.CANADA_FRENCH)); // should output best match
   
    // You can also use strings to avoid creating Locale objects right away
    // The method references a "key" which is handy when processing property files
    greeting.add("key_en", "key", "Hello World");
    greeting.add("key_fr", "key", "Bonjour tot le monde");
   
    // You can also quickly create an GrowableInternationalString and add to it later
    GrowableInternationalString cheerfulGreeting = new GrowableInternationalString("G'Day");
    cheerfulGreeting.add(Locale.UK, "Welcome");
    cheerfulGreeting.add(Locale.US, "Hello");
    // exampleGrowableInternationalString end
}
View Full Code Here

        ensureNonNull("properties", properties);
        Object name        = null;
        Object alias       = null;
        Object identifiers = null;
        Object remarks     = null;
        GrowableInternationalString       growable = null;
        GrowableInternationalString[] subGrowables = 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 object. Hopefully, most users will fill a map only with usefull entries.
         */
NEXT_KEY: for (final Map.Entry<String,?> entry : properties.entrySet()) {
            String    key   = entry.getKey().trim().toLowerCase();
            Object    value = entry.getValue();
            /*
             * Note: String.hashCode() is part of J2SE specification,
             *       so it should not change across implementations.
             */
            switch (key.hashCode()) {
                // Fix case for common keywords. They are not used
                // by this class, but are used by some subclasses.
                case -1528693765: if (key.equalsIgnoreCase("anchorPoint"))                 key="anchorPoint";                 break;
                case -1805658881: if (key.equalsIgnoreCase("bursaWolf"))                   key="bursaWolf";                   break;
                case   109688209: if (key.equalsIgnoreCase("operationVersion"))            key="operationVersion";            break;
                case  1479434472: if (key.equalsIgnoreCase("coordinateOperationAccuracy")) key="coordinateOperationAccuracy"; break;
                case  1126917133: if (key.equalsIgnoreCase("positionalAccuracy"))          key="positionalAccuracy";          break;
                case  1127093059: if (key.equalsIgnoreCase("realizationEpoch"))            key="realizationEpoch";            break;
                case  1790520781: if (key.equalsIgnoreCase("domainOfValidity"))            key="domainOfValidity";            break;
                case -1109785975: if (key.equalsIgnoreCase("validArea"))                   key="validArea";                   break;

                // -------------------------------------
                // "name": String or ReferenceIdentifier
                // -------------------------------------
                case 3373707: {
                    if (key.equals(NAME_KEY)) {
                        if (value instanceof String) {
                            name = new NamedIdentifier(properties, false);
                            assert value.equals(((Identifier) name).getCode()) : name;
                        } else {
                            // Should be an instance of ReferenceIdentifier, but we don't check
                            // here. The type will be checked at the end of this method, which
                            // will thrown an exception with detailed message in case of mismatch.
                            name = value;
                        }
                        continue NEXT_KEY;
                    }
                    break;
                }
                // -------------------------------------------------------
                // "alias": String, String[], GenericName or GenericName[]
                // -------------------------------------------------------
                case 92902992: {
                    if (key.equals(ALIAS_KEY)) {
                        alias = NameFactory.toArray(value);
                        continue NEXT_KEY;
                    }
                    break;
                }
                // -----------------------------------------------------------
                // "identifiers": ReferenceIdentifier or ReferenceIdentifier[]
                // -----------------------------------------------------------
                case 1368189162: {
                    if (key.equals(IDENTIFIERS_KEY)) {
                        if (value != null) {
                            if (value instanceof ReferenceIdentifier) {
                                identifiers = new ReferenceIdentifier[] {
                                    (ReferenceIdentifier) value
                                };
                            } else {
                                identifiers = value;
                            }
                        }
                        continue NEXT_KEY;
                    }
                    break;
                }
                // ----------------------------------------
                // "remarks": String or InternationalString
                // ----------------------------------------
                case 1091415283: {
                    if (key.equals(REMARKS_KEY)) {
                        if (value instanceof InternationalString) {
                            remarks = value;
                            continue NEXT_KEY;
                        }
                    }
                    break;
                }
            }
            /*
             * Search for additional locales for remarks (e.g. "remarks_fr").
             * 'growable.add(...)' will add the value only if the key starts
             * with the "remarks" prefix.
             */
            if (value instanceof String) {
                if (growable == null) {
                    if (remarks instanceof GrowableInternationalString) {
                        growable = (GrowableInternationalString) remarks;
                    } else {
                        growable = new GrowableInternationalString();
                    }
                }
                if (growable.add(REMARKS_KEY, key, value.toString())) {
                    continue NEXT_KEY;
                }
            }
            /*
             * Search for user-specified localizable properties.
             */
            if (subProperties == null) {
                continue NEXT_KEY;
            }
            if (localizables != null) {
                for (int i=0; i<localizables.length; i++) {
                    final String prefix = localizables[i];
                    if (key.equals(prefix)) {
                        if (value instanceof InternationalString) {
                            // Stores the value in 'subProperties' after the loop.
                            break;
                        }
                    }
                    if (value instanceof String) {
                        if (subGrowables == null) {
                            subGrowables = new GrowableInternationalString[localizables.length];
                        }
                        if (subGrowables[i] == null) {
                            final Object previous = subProperties.get(prefix);
                            if (previous instanceof GrowableInternationalString) {
                                subGrowables[i] = (GrowableInternationalString) previous;
                            } else {
                                subGrowables[i] = new GrowableInternationalString();
                            }
                        }
                        if (subGrowables[i].add(prefix, key, value.toString())) {
                            continue NEXT_KEY;
                        }
                    }
                }
            }
            subProperties.put(key, 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 discart the later with a warning.
         */
        if (growable!=null && !growable.getLocales().isEmpty()) {
            if (remarks == null) {
                remarks = growable;
            } else if (!growable.isSubsetOf(remarks)) {
                final Logger logger = Logging.getLogger(AbstractIdentifiedObject.class);
                final LogRecord record = Loggings.format(Level.WARNING, LoggingKeys.LOCALES_DISCARTED);
                record.setLoggerName(logger.getName());
                logger.log(record);
            }
        }
        /*
         * Get the localized user-defined properties.
         */
        if (subProperties!=null && subGrowables!=null) {
            for (int i=0; i<subGrowables.length; i++) {
                growable = subGrowables[i];
                if (growable!=null && !growable.getLocales().isEmpty()) {
                    final String prefix = localizables[i];
                    final Object current = subProperties.get(prefix);
                    if (current == null) {
                        subProperties.put(prefix, growable);
                    } else if (!growable.isSubsetOf(current)) {
                        final Logger logger = Logging.getLogger(AbstractIdentifiedObject.class);
                        final LogRecord record = Loggings.format(Level.WARNING, LoggingKeys.LOCALES_DISCARTED);
                        record.setLoggerName(logger.getName());
                        logger.log(record);
                    }
View Full Code Here

     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
            throws Exception {
        Map<String, Object> map = (Map<String, Object>) value;
        GrowableInternationalString intString = new GrowableInternationalString(map
                .get(null).toString()) {
   
            @Override
            public String toString() {
                return super.toString(null);
            }
        };
        for (String key : map.keySet()) {
            if (key != null && key.equalsIgnoreCase("localized")) {
                Iterable translations = (Iterable) map.get(key);
                for (Object obj : translations) {
                    Map<String, String> translation = (Map<String, String>) obj;
                    intString.add("", "_" + translation.get("lang"),
                            translation.get(null));
                }
            }
        }
        return intString;
View Full Code Here

        Object code      = null;
        Object codespace = null;
        Object version   = null;
        Object authority = null;
        Object remarks   = null;
        GrowableInternationalString growable = 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 only with usefull entries.
         */
        String key   = null;
        Object value = null;
        for (final Map.Entry<String,?> entry : properties.entrySet()) {
            key   = entry.getKey().trim().toLowerCase();
            value = entry.getValue();
            /*
             * Note: String.hashCode() is part of J2SE specification,
             *       so it should not change across implementations.
             */
            switch (key.hashCode()) {
                case 3373707: {
                    if (!standalone && key.equals("name")) {
                        code = value;
                        continue;
                    }
                    break;
                }
                case 3059181: {
                    if (key.equals(CODE_KEY)) {
                        code = value;
                        continue;
                    }
                    break;
                }
                case -1108676807: {
                    if (key.equals(CODESPACE_KEY)) {
                        codespace = value;
                        continue;
                    }
                    break;

                }
                case 351608024: {
                    if (key.equals(VERSION_KEY)) {
                        version = value;
                        continue;
                    }
                    break;
                }
                case 1475610435: {
                    if (key.equals(AUTHORITY_KEY)) {
                        if (value instanceof String) {
                            value = Citations.fromName(value.toString());
                        }
                        authority = value;
                        continue;
                    }
                    break;
                }
                case 1091415283: {
                    if (standalone && key.equals(REMARKS_KEY)) {
                        if (value instanceof InternationalString) {
                            remarks = value;
                            continue;
                        }
                    }
                    break;
                }
            }
            /*
             * Search for additional locales (e.g. "remarks_fr").
             */
            if (standalone && value instanceof String) {
                if (growable == null) {
                    if (remarks instanceof GrowableInternationalString) {
                        growable = (GrowableInternationalString) remarks;
                    } else {
                        growable = new GrowableInternationalString();
                    }
                }
                growable.add(REMARKS_KEY, key, value.toString());
            }
        }
        /*
         * 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 discart the later with a warning.
         */
        if (growable!=null && !growable.getLocales().isEmpty()) {
            if (remarks == null) {
                remarks = growable;
            } else {
                final Logger logger = Logging.getLogger(NamedIdentifier.class);
                final LogRecord record = Loggings.format(Level.WARNING, LoggingKeys.LOCALES_DISCARTED);
View Full Code Here

TOP

Related Classes of org.geotools.util.GrowableInternationalString

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.