Changeset 26956 in osm for applications/editors


Ignore:
Timestamp:
2011-10-24T01:20:34+02:00 (13 years ago)
Author:
donvip
Message:

tag2link 0.2b: UNESCO WHC rule working

Location:
applications/editors/josm/plugins/tag2link
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/tag2link/resources/tag2link_sources.xml

    r26936 r26956  
    4949    <source name="WHC">
    5050        <rule>
    51             <condition k="ref:whc" v="\p{Digit}+" />
     51            <condition k="ref:whc" v="[0-9-]+" />
    5252            <link name="View UNESCO sheet" href="http://whc.unesco.org/%lang(en,fr):en%/list/%v%" />
    5353        </rule>
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPlugin.java

    r26936 r26956  
    2828 * Main class of tag2link plugin.
    2929 * @author Don-vip
    30  * @version 0.2a
    3130 * History:
     31 * 0.2b 24-Oct-2011 UNESCO WHC rule working
    3232 * 0.2a 23-Oct-2011 add Mail support + initial work on UNESCO WHC
    3333 * 0.1c 23-Oct-2011 add MHS rule (French heritage)
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java

    r26936 r26956  
    2020import java.util.ArrayList;
    2121import java.util.Collection;
     22import java.util.Locale;
    2223import java.util.regex.Matcher;
    2324import java.util.regex.Pattern;
    2425
     26import org.openstreetmap.josm.Main;
    2527import org.openstreetmap.josm.data.osm.IPrimitive;
    2628import org.openstreetmap.josm.data.osm.Tag;
     
    6365                                while (m.find()) {
    6466                                        String arg = m.group(1);
     67                                       
     68                                        // Search for a standard value
    6569                                        String val = findValue(arg, eval.matchingTags);
     70                                       
     71                                        // No standard value found: test lang() function
     72                                        if (val == null) {
     73                                                Matcher lm = Pattern.compile(".*lang(?:\\((\\p{Lower}{2,})(?:,(\\p{Lower}{2,}))*\\))?.*").matcher(arg);
     74                                                if (lm.matches()) {
     75                                                        String josmLang = Main.pref.get("language");
     76                                                        String jvmLang = (josmLang.isEmpty() ? Locale.getDefault().getLanguage() : josmLang).split("_")[0];
     77                                                        if (lm.groupCount() == 0) {
     78                                                                val = jvmLang;
     79                                                        } else {
     80                                                                for (int i = 1; i<=lm.groupCount() && val == null; i++) {
     81                                                                        if (jvmLang.equals(lm.group(i))) {
     82                                                                                val = jvmLang;
     83                                                                        }
     84                                                                }
     85                                                        }
     86                                                }
     87                                        }
     88                                       
     89                                        // Find a default value if set after ":"
    6690                                        if (val == null && arg.contains(":")) {
    6791                                                String[] vars = arg.split(":");
     
    7498                                                }
    7599                                        }
    76                                         if (val == null) {
    77                                                 Matcher lm = Pattern.compile("lang(?:\\(\\p{Lower}{2,}(?:,\\p{Lower}{2,})*\\))?(?::(\\p{Lower}{2,}))?").matcher(arg);
    78                                                 if (lm.matches()) {
    79                                                         if (lm.groupCount() == 0) {
    80                                                                 // TODO: get JOSM current language
    81                                                         } else {
    82                                                                 // TODO: parse next groups
    83                                                         }
    84                                                 }
    85                                         }
     100                                       
     101                                        // Has a value been found ?
    86102                                        if (val != null) {
    87103                                                try {
     
    95111                                                        }
    96112                                                        // Finally replace parameter
    97                                                         copy.url = copy.url.replaceFirst(m.group(), val);
     113                                                        copy.url = copy.url.replaceFirst(Pattern.quote(m.group()), val);
    98114                                                } catch (UnsupportedEncodingException e) {
    99115                                                        e.printStackTrace();
Note: See TracChangeset for help on using the changeset viewer.