Changeset 5964 in josm for trunk


Ignore:
Timestamp:
2013-05-17T01:58:59+02:00 (7 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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r5950 r5964  
    4848  text: fixed label to display
    4949  values: comma separated list of values
     50  values_from: to use instead of "values" if the list of values has to be obtained with a Java method
     51               of this form: public static String[] getValues();
     52               The value must be: "full.package.name.ClassName#methodName"
    5053  display_values: comma separated list of values to be displayed instead of the
    5154                  database values, order and number must be equal to values
     
    6770             will also be used to separate selected values in the tag.
    6871  values: delimiter-separated list of values (delimiter can be escaped with backslash)
     72  values_from: to use instead of "values" if the list of values has to be obtained with a Java method
     73               of this form: public static String[] getValues();
     74               The value must be: "full.package.name.ClassName#methodName"
    6975  rows: specify the number of rows to display (default -1)
    7076  display_values: delimiter-separated list of values to be displayed instead of the
     
    60526058                <text key="addr:city" text="City name" use_last_as_default="force" match="key" />
    60536059                <text key="addr:postcode" text="Post code" use_last_as_default="force" match="key" />
    6054                 <combo key="addr:country" text="Country code" values="AT,CH,DE,FR,GB,IT,RS,US" use_last_as_default="force" match="key" />
     6060                <combo key="addr:country" text="Country code" values_from="java.util.Locale#getISOCountries" use_last_as_default="force" match="key" />
    60556061            </optional>
    60566062        </item>
  • 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.