Changeset 26918 in osm


Ignore:
Timestamp:
2011-10-21T21:29:51+02:00 (13 years ago)
Author:
donvip
Message:

tag2link: works for website, url, SANDRE

Location:
applications/editors/josm/plugins/tag2link
Files:
1 added
7 edited
1 moved

Legend:

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

    r26917 r26918  
    2424       <rule>
    2525           <condition k="website" />
    26            <link name="View website" href="{v}" />
     26           <link name="View website" href="%v%" />
    2727       </rule>
    2828       <rule>
    2929           <condition k="url" />
    30            <link name="View URL" href="{v}" />
     30           <link name="View URL" href="%v%" />
    3131       </rule>
    3232    </source>
     
    3535           <rule>
    3636               <condition k="wikipedia(?::([\p{Lower}]{2,}))?" />
    37            <link name="View {name} article" href="http://{k.1:en}.wikipedia.org/wiki/{v}" />
     37           <link name="View %name% article" href="http://%k.1:en%.wikipedia.org/wiki/%v%" />
    3838           </rule>
    3939        </source>
     
    4444       <rule>
    4545           <condition k="ref:sandre" v="[A-Z0-9-]{8}" />
    46            <link name="View {name} sheet of river" href="http://services.sandre.eaufrance.fr/Courdo/Fiche/client/fiche_courdo.php?CdSandre={v}" />
     46           <link name="View %name% sheet of river" href="http://services.sandre.eaufrance.fr/Courdo/Fiche/client/fiche_courdo.php?CdSandre=%v%" />
    4747       </rule>
    4848    </source>
     
    5252           <condition k="admin_level" v="8"/>
    5353           <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{3})" id="ref"/>
    54            <link name="View {name} municipality sheet" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/fichecommunale.asp?codedep={ref.v.1}&amp;codecom={ref.v.2}" />
     54           <link name="View %name% municipality sheet" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/fichecommunale.asp?codedep=%ref.v.1%&amp;codecom=%ref.v.2%" />
    5555       </rule>
    5656       <rule>
    5757           <condition k="political_division" v="FR:canton"/>
    5858           <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{2})" id="ref"/>
    59            <link name="View {name} map of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_comcan.asp?codecan={ref.v}" />
    60            <link name="View {name} list of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/comcan.asp?codedep={ref.v.1}&amp;codecan={ref.v.2}" />
     59           <link name="View %name% map of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_comcan.asp?codecan=%ref.v%" />
     60           <link name="View %name% list of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/comcan.asp?codedep={ref.v.1}&amp;codecan=%ref.v.2%" />
    6161       </rule>
    6262       <rule>
    6363           <condition k="admin_level" v="7"/>
    6464           <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{1})" id="ref"/>
    65            <link name="View {name} map of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_canarr.asp?codearr={ref.v}" />
    66            <link name="View {name} list of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/canarr.asp?codedep={ref.v.1}&amp;codearr={ref.v.2}" />
     65           <link name="View %name% map of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_canarr.asp?codearr=%ref.v%" />
     66           <link name="View %name% list of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/canarr.asp?codedep=%ref.v.1%&amp;codearr=%ref.v.2%" />
    6767       </rule>
    6868       <rule>
    6969           <condition k="admin_level" v="6"/>
    7070           <condition k="ref:INSEE" v="\p{Digit}{2}" id="ref"/>
    71            <link name="View {name} map of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_arrdep.asp?codedep={ref.v}" />
    72            <link name="View {name} list of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/arrdep.asp?codedep={ref.v}" />
     71           <link name="View %name% map of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_arrdep.asp?codedep=%ref.v%" />
     72           <link name="View %name% list of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/arrdep.asp?codedep=%ref.v%" />
    7373       </rule>
    7474       <rule>
    7575           <condition k="admin_level" v="4"/>
    7676           <condition k="ref:INSEE" v="\p{Digit}{2}" id="ref"/>
    77            <link name="View {name} map of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_depreg.asp?codereg={ref.v}" />
    78            <link name="View {name} list of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/depreg.asp?codereg={ref.v}" />
     77           <link name="View %name% map of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_depreg.asp?codereg=%ref.v%" />
     78           <link name="View %name% list of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/depreg.asp?codereg=%ref.v%" />
    7979       </rule>
    8080       <rule>
    8181           <condition k="admin_level" v="2"/>
    8282           <condition k="name" v="France*"/>
    83            <link name="View {name} map of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_regions.asp" />
    84            <link name="View {name} list of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/region.asp" />
     83           <link name="View %name% map of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_regions.asp" />
     84           <link name="View %name% list of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/region.asp" />
    8585       </rule>
    8686    </source>
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java

    r26917 r26918  
    1818import java.util.ArrayList;
    1919import java.util.Collection;
    20 import java.util.HashSet;
    21 import java.util.Set;
    2220
    2321import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    4846                EvalResult eval = rule.evaluates(p);
    4947                if (eval.matches()) {
    50                     Set<String> links = new HashSet<String>();
    51                     for (MatchingTag tag : eval.matchingTags) {
    52                        
     48                    for (Link link : rule.links) {
     49                        Link copy = new Link(link);
     50                        copy.name = copy.name.replaceAll("%name%", source.name);
     51                        MatchingTag firstTag = eval.matchingTags.iterator().next();
     52                        copy.url = copy.url.replaceAll("%k%", firstTag.key)
     53                                                   .replaceAll("%v%", firstTag.value);
     54                        result.add(copy);
    5355                    }
    5456                }
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java

    r26917 r26918  
    1010import org.openstreetmap.josm.tools.OpenBrowser;
    1111
     12@SuppressWarnings("serial")
    1213public class OpenLinkAction extends JosmAction implements Tag2LinkConstants {
    1314
     
    1516   
    1617    public OpenLinkAction(Link link) {
    17         super(tr(link.name), ICON_16, tr("Launch browser with information about the selected object"), null, true);
     18        super(tr(link.name), ICON_24, tr("Launch browser with information about the selected object"), null, true);
    1819        this.url = link.url;
    1920    }
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Link.java

    r26917 r26918  
    44    public String name;
    55    public String url;
     6   
     7    public Link(String name, String url) {
     8        this.name = name;
     9        this.url = url;
     10    }
     11   
     12    public Link(Link link) {
     13        this(link.name, link.url);
     14    }
     15   
    616    private boolean containsParams(String s) {
    717        return s.matches("[^{}]*{[^{}]*}[^{}]*");
    818    }
     19   
    920    public boolean nameContainsParams() {
    1021        return containsParams(name);
    1122    }
     23   
    1224    public boolean urlContainsParams() {
    1325        return containsParams(url);
    1426    }
     27   
    1528    public boolean containsParams() {
    1629        return nameContainsParams() || urlContainsParams();
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java

    r26917 r26918  
    1717        public String value;
    1818        public final Map<String, String> params = new HashMap<String, String>();
     19        public MatchingTag(String key, String value) {
     20                this.key = key;
     21                this.value = value;
     22        }
     23        public void addParams(Matcher m, String prefix) {
     24                for (int i = 1; i<=m.groupCount(); i++) {
     25                        this.params.put(prefix+i, m.group(i));
     26                }
     27        }
    1928    }
    2029   
     
    3140        for (Condition c : conditions) {
    3241            for (String key : tags.keySet()) {
    33                 Matcher m = c.keyPattern.matcher(key);
    34                 if (m.matches()) {
    35                    
     42                Matcher keyMatcher = c.keyPattern.matcher(key);
     43                if (keyMatcher.matches()) {
     44                        String idPrefix = c.id == null ? "" : c.id+".";
     45                        MatchingTag tag = new MatchingTag(key, tags.get(key));
     46                        tag.addParams(keyMatcher, idPrefix+"k.");
     47                        boolean matchingTag = true;
     48                        if (c.valPattern != null) {
     49                                Matcher valMatcher = c.valPattern.matcher(tag.value);
     50                                if (valMatcher.matches()) {
     51                                        tag.addParams(valMatcher, idPrefix+"v.");
     52                                } else {
     53                                        matchingTag = false;
     54                                }
     55                        }
     56                        if (matchingTag) {
     57                                result.matchingTags.add(tag);
     58                        }
    3659                }
    3760            }
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Source.java

    r26917 r26918  
    55
    66public class Source {
    7     public String name;
     7    public final String name;
    88    public final Collection<Rule> rules = new ArrayList<Rule>();
     9
     10    public Source(String name) {
     11                this.name = name;
     12        }
    913}
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java

    r26917 r26918  
    126126
    127127    private Source parseSource() throws XMLStreamException {
    128         Source source = new Source();
     128        Source source = new Source(parser.getAttributeValue(null, "name"));
    129129        while (parser.hasNext()) {
    130130            int event = parser.next();
     
    174174
    175175    private Link parseLink() throws XMLStreamException {
    176         Link link = new Link();
    177         link.name = parser.getAttributeValue(null, "name");
    178         link.url  = parser.getAttributeValue(null, "href");
     176        Link link = new Link(
     177                parser.getAttributeValue(null, "name"),
     178                parser.getAttributeValue(null, "href")
     179        );
    179180        jumpToEnd();
    180181        return link;
Note: See TracChangeset for help on using the changeset viewer.