Changeset 5964 in josm for trunk/src


Ignore:
Timestamp:
2013-05-17T01:58:59+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #5618 - Use full list of ISO 3166 country codes from JDK for addr:country in presets with new preset attribute values_from

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r5931 r5964  
    2020import java.io.Reader;
    2121import java.io.UnsupportedEncodingException;
     22import java.lang.reflect.Method;
     23import java.lang.reflect.Modifier;
    2224import java.text.NumberFormat;
    2325import java.text.ParseException;
     
    666668        public String locale_text;
    667669        public String values;
     670        public String values_from;
    668671        public String values_context;
    669672        public String display_values;
     
    760763            char delChar = getDelChar();
    761764
    762             String[] value_array = splitEscaped(delChar, values);
     765            String[] value_array = null;
     766           
     767            if (values_from != null) {
     768                String[] class_method = values_from.split("#");
     769                if (class_method != null && class_method.length == 2) {
     770                    try {
     771                        Method method = Class.forName(class_method[0]).getMethod(class_method[1]);
     772                        // Check method is public static String[] methodName();
     773                        int mod = method.getModifiers();
     774                        if (Modifier.isPublic(mod) && Modifier.isStatic(mod)
     775                                && method.getReturnType().equals(String[].class) && method.getParameterTypes().length == 0) {
     776                            value_array = (String[]) method.invoke(null);
     777                        } else {
     778                            System.err.println(tr("Broken tagging preset \"{0}-{1}\" - Java method given in ''values_from'' is not \"{2}\"", key, text,
     779                                    "public static String[] methodName()"));
     780                        }
     781                    } catch (Exception e) {
     782                        System.err.println(tr("Broken tagging preset \"{0}-{1}\" - Java method given in ''values_from'' threw {2} ({3})", key, text,
     783                                e.getClass().getName(), e.getMessage()));
     784                    }
     785                }
     786            }
     787           
     788            if (value_array == null) {
     789                value_array = splitEscaped(delChar, values);
     790            }
    763791
    764792            final String displ = Utils.firstNonNull(locale_display_values, display_values);
Note: See TracChangeset for help on using the changeset viewer.