Changeset 26980 in osm


Ignore:
Timestamp:
2011-10-29T03:32:59+02:00 (13 years ago)
Author:
donvip
Message:

Tag2link 0.3a

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

Legend:

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

    r26963 r26980  
    1919<tag2link>
    2020
    21     <!-- Global -->
     21    <!-- Global --> 
    2222
    2323    <source name="Common">
     
    5454    </source>
    5555   
    56     <!-- Only for France -->
     56    <!-- Only for France --> 
    5757   
    5858    <source name="SANDRE" country-code="FR">
    5959        <rule>
    60             <condition k="ref:sandre" v="[A-Z0-9-]{8}" />
     60            <condition k="ref:(FR:)?sandre" v="[A-Z0-9-]{8}" />
    6161            <link name="View %name% sheet of river" href="http://services.sandre.eaufrance.fr/Courdo/Fiche/client/fiche_courdo.php?CdSandre=%v%" />
    6262        </rule>
     
    6666        <rule>
    6767            <condition k="admin_level" v="8"/>
    68             <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{3})" id="ref"/>
     68            <condition k="ref:(FR:)?INSEE" v="(\p{Digit}{2})(\p{Digit}{3})" id="ref"/>
    6969            <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%" />
    7070        </rule>
    7171        <rule>
    7272            <condition k="political_division" v="FR:canton"/>
    73             <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{2})" id="ref"/>
     73            <condition k="ref:(FR:)?INSEE" v="(\p{Digit}{2})(\p{Digit}{2})" id="ref"/>
    7474            <link name="View %name% map of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_comcan.asp?codecan=%ref.v%" />
    7575            <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%" />
     
    7777        <rule>
    7878            <condition k="admin_level" v="7"/>
    79             <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{1})" id="ref"/>
     79            <condition k="ref:(FR:)?INSEE" v="(\p{Digit}{2})(\p{Digit}{1})" id="ref"/>
    8080            <link name="View %name% map of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_canarr.asp?codearr=%ref.v%" />
    8181            <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%" />
     
    8383        <rule>
    8484            <condition k="admin_level" v="6"/>
    85             <condition k="ref:INSEE" v="\p{Digit}{2}" id="ref"/>
     85            <condition k="ref:(FR:)?INSEE" v="\p{Digit}{2}" id="ref"/>
    8686            <link name="View %name% map of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_arrdep.asp?codedep=%ref.v%" />
    8787            <link name="View %name% list of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/arrdep.asp?codedep=%ref.v%" />
     
    8989        <rule>
    9090            <condition k="admin_level" v="4"/>
    91             <condition k="ref:INSEE" v="\p{Digit}{2}" id="ref"/>
     91            <condition k="ref:(FR:)?INSEE" v="\p{Digit}{2}" id="ref"/>
    9292            <link name="View %name% map of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_depreg.asp?codereg=%ref.v%" />
    9393            <link name="View %name% list of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/depreg.asp?codereg=%ref.v%" />
     
    103103    <source name="CEF" country-code="FR">
    104104        <rule>
    105             <condition k="ref:CEF" v="[A-Z0-9_]{8}" />
     105            <condition k="ref:(FR:)?CEF" v="[A-Z0-9_]{8}" />
    106106            <link name="View %name% sheet of church" href="http://www.messesinfo.catholique.fr/public/fiche.php?valcode=%v%" />
    107107        </rule>
     
    110110    <source name="MHS" country-code="FR">
    111111        <rule>
    112             <condition k="ref:mhs" v="\p{Upper}{2}\p{Digit}{8}" />
     112            <condition k="ref:(FR:)?mhs" v="\p{Upper}{2}\p{Digit}{8}" />
    113113            <link name="View Mérimée sheet of monument" href="http://www.culture.gouv.fr/public/mistral/mersri_fr?ACTION=CHERCHER&amp;FIELD_1=REF&amp;VALUE_1=%v%" />
    114114        </rule>
    115115        <rule>
    116             <condition k="ref:INSEE" v="\p{Digit}{5}" />
     116            <condition k="ref:(FR:)?INSEE" v="\p{Digit}{5}" />
    117117            <link name="View Mérimée list for this municipality" href="http://www.culture.gouv.fr/public/mistral/merimee_fr?ACTION=CHERCHER&amp;FIELD_1=cmer1&amp;VALUE_1=%v%" />
     118        </rule>
     119    </source>
     120
     121    <source name="IGN" country-code="FR">
     122                <!--
     123                http://geodesie.ign.fr/fiches/index.php?module=e&action=fichepdf&source=carte&sit_no=4509302&geo_cid=0&lambda=1.90024744&phi=48.03041621
     124                 -->
     125        <rule>
     126            <condition k="man_made" v="survey_point" />
     127            <condition k="source" v="©IGN .*" />
     128            <condition k="ref" v="(\p{Digit}{7}) - ." id="ref" />
     129            <link name="View %name% sheet of geodesic site" href="http://geodesie.ign.fr/fiches/index.php?module=e&amp;action=fichepdf&amp;source=carte&amp;sit_no=%ref.v.1%" />
     130            <!-- <link name="View %name% sheet of geodesic site" href="http://geodesie.ign.fr/fiches/index.php?module=e&amp;action=visugeod" method="POST" >
     131                <param  name="h_panier"  value="pdf" />
     132                <param  name="%ref.v.1%" value="on" />
     133                <header name="Content-type" value="application/x-www-form-urlencoded" />
     134            </link>-->
     135        </rule>
     136        <rule>
     137            <condition k="site" v="geodesic" />
     138            <condition k="source" v="©IGN .*" />
     139            <condition k="ref" v="\p{Digit}{7}" id="ref" />
     140            <link name="View %name% sheet of geodesic site" href="http://geodesie.ign.fr/fiches/index.php?module=e&amp;action=fichepdf&amp;source=carte&amp;sit_no=%ref.v.1%" />
    118141        </rule>
    119142    </source>
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPlugin.java

    r26964 r26980  
    2929 * @author Don-vip
    3030 * History:
     31 * 0.3a 29-Oct-2011 Add Country-code prefix, IGN support + not-yet-tested POST requests support
    3132 * 0.2d 24-Oct-2011 Icon for Mail action
    3233 * 0.2c 24-Oct-2011 Another MHS rule
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java

    r26956 r26980  
    2020import java.util.ArrayList;
    2121import java.util.Collection;
     22import java.util.Iterator;
    2223import java.util.Locale;
     24import java.util.Map;
    2325import java.util.regex.Matcher;
    2426import java.util.regex.Pattern;
     
    2830import org.openstreetmap.josm.data.osm.Tag;
    2931import org.openstreetmap.josm.plugins.tag2link.data.Link;
     32import org.openstreetmap.josm.plugins.tag2link.data.LinkPost;
    3033import org.openstreetmap.josm.plugins.tag2link.data.Rule;
    3134import org.openstreetmap.josm.plugins.tag2link.data.Rule.EvalResult;
     
    5659    }
    5760   
     61    private static String replaceParams(String s, EvalResult eval) {
     62        String result = s;
     63                Matcher m = Pattern.compile("%([^%]*)%").matcher(s);
     64                while (m.find()) {
     65                        String arg = m.group(1);
     66                       
     67                        // Search for a standard value
     68                        String val = findValue(arg, eval.matchingTags);
     69                       
     70                        // No standard value found: test lang() function
     71                        if (val == null) {
     72                                Matcher lm = Pattern.compile(".*lang(?:\\((\\p{Lower}{2,})(?:,(\\p{Lower}{2,}))*\\))?.*").matcher(arg);
     73                                if (lm.matches()) {
     74                                        String josmLang = Main.pref.get("language");
     75                                        String jvmLang = (josmLang.isEmpty() ? Locale.getDefault().getLanguage() : josmLang).split("_")[0];
     76                                        if (lm.groupCount() == 0) {
     77                                                val = jvmLang;
     78                                        } else {
     79                                                for (int i = 1; i<=lm.groupCount() && val == null; i++) {
     80                                                        if (jvmLang.equals(lm.group(i))) {
     81                                                                val = jvmLang;
     82                                                        }
     83                                                }
     84                                        }
     85                                }
     86                        }
     87                       
     88                        // Find a default value if set after ":"
     89                        if (val == null && arg.contains(":")) {
     90                                String[] vars = arg.split(":");
     91                                for (int i = 0; val == null && i < vars.length-1; i++) {
     92                                        val = findValue(vars[i], eval.matchingTags);
     93                                }
     94                                if (val == null) {
     95                                        // Default value
     96                                        val = vars[vars.length-1];
     97                                }
     98                        }
     99                       
     100                        // Has a value been found ?
     101                        if (val != null) {
     102                                try {
     103                                        // Special hack for Wikipedia that prevents spaces being replaced by "+" characters, but by "_"
     104                                        if (s.contains("wikipedia.")) {
     105                                                val = val.replaceAll(" ", "_");
     106                                        }
     107                                        // Encode param to be included in the URL, except if it is the URL itself !
     108                                        if (!m.group().equals(s)) {
     109                                                val = URLEncoder.encode(val, UTF8_ENCODING);
     110                                        }
     111                                        // Finally replace parameter
     112                                        result = result.replaceFirst(Pattern.quote(m.group()), val);
     113                                } catch (UnsupportedEncodingException e) {
     114                                        e.printStackTrace();
     115                                }
     116                        } else {
     117                                System.err.println("Invalid argument: "+arg);
     118                        }
     119                }
     120        return result;
     121    }
     122   
     123    private static void replaceMapParams(Map<String, String> map, EvalResult eval) {
     124                for (Iterator<String> it = map.keySet().iterator(); it.hasNext(); ) {
     125                        String key = it.next();
     126                        String value = map.get(key);
     127                        String key2 = replaceParams(key, eval);
     128                        String value2 = replaceParams(value, eval);
     129                        if (key.equals(key2) && value.equals(value2)) {
     130                                // Nothing to do
     131                        } else if (key.equals(key2)) {
     132                                // Update value
     133                                map.put(key, value2);
     134                        } else {
     135                                // Update key, and maybe value
     136                                map.remove(key);
     137                                map.put(key2, value2);
     138                        }
     139                }
     140    }
     141   
    58142    private static Collection<Link> processEval(EvalResult eval, Rule rule, Source source) {
    59143        Collection<Link> result = new ArrayList<Link>();
    60144        if (eval.matches()) {
    61145            for (Link link : rule.links) {
    62                 Link copy = new Link(link);
    63                 copy.name = copy.name.replaceAll("%name%", source.name);
    64                                 Matcher m = Pattern.compile("%([^%]*)%").matcher(copy.url);
    65                                 while (m.find()) {
    66                                         String arg = m.group(1);
    67                                        
    68                                         // Search for a standard value
    69                                         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 ":"
    90                                         if (val == null && arg.contains(":")) {
    91                                                 String[] vars = arg.split(":");
    92                                                 for (int i = 0; val == null && i < vars.length-1; i++) {
    93                                                         val = findValue(vars[i], eval.matchingTags);
    94                                                 }
    95                                                 if (val == null) {
    96                                                         // Default value
    97                                                         val = vars[vars.length-1];
    98                                                 }
    99                                         }
    100                                        
    101                                         // Has a value been found ?
    102                                         if (val != null) {
    103                                                 try {
    104                                                         // Special hack for Wikipedia that prevents spaces being replaced by "+" characters, but by "_"
    105                                                         if (copy.url.contains("wikipedia.")) {
    106                                                                 val = val.replaceAll(" ", "_");
    107                                                         }
    108                                                         // Encode param to be included in the URL, except if it is the URL itself !
    109                                                         if (!m.group().equals(copy.url)) {
    110                                                                 val = URLEncoder.encode(val, UTF8_ENCODING);
    111                                                         }
    112                                                         // Finally replace parameter
    113                                                         copy.url = copy.url.replaceFirst(Pattern.quote(m.group()), val);
    114                                                 } catch (UnsupportedEncodingException e) {
    115                                                         e.printStackTrace();
    116                                                 }
    117                                         } else {
    118                                                 System.err.println("Invalid argument: "+arg);
    119                                         }
    120                                 }
    121                 result.add(copy);
     146                        try {
     147                                        Link copy = (Link) link.clone();
     148                        copy.name = copy.name.replaceAll("%name%", source.name);
     149                        copy.url = replaceParams(copy.url, eval);
     150                        if (copy instanceof LinkPost) {
     151                                LinkPost lp = (LinkPost) copy;
     152                                replaceMapParams(lp.headers, eval);
     153                                replaceMapParams(lp.params, eval);
     154                        }
     155                        result.add(copy);
     156                        } catch (CloneNotSupportedException e) {
     157                                System.err.println(e);
     158                        }
    122159            }
    123160        }
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java

    r26964 r26980  
     1//    JOSM tag2link plugin.
     2//    Copyright (C) 2011 Don-vip & FrViPofm
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.tag2link.action;
    217
     
    419
    520import java.awt.event.ActionEvent;
     21import java.io.FileOutputStream;
     22import java.io.IOException;
     23import java.io.InputStream;
     24import java.io.OutputStreamWriter;
     25import java.net.HttpURLConnection;
     26import java.net.MalformedURLException;
     27import java.net.URL;
    628
    729import org.openstreetmap.josm.actions.JosmAction;
    830import org.openstreetmap.josm.plugins.tag2link.Tag2LinkConstants;
    931import org.openstreetmap.josm.plugins.tag2link.data.Link;
     32import org.openstreetmap.josm.plugins.tag2link.data.LinkPost;
    1033import org.openstreetmap.josm.tools.OpenBrowser;
    1134
     
    1336public class OpenLinkAction extends JosmAction implements Tag2LinkConstants {
    1437
    15     private String url;
     38    private Link link;
    1639   
    1740    public OpenLinkAction(Link link) {
    1841        super(tr(link.name), ICON_24, tr("Launch browser with information about the selected object"), null, false);
    19         this.url = link.url;
     42        this.link = link;
    2043    }
    2144
    2245    @Override
    2346    public void actionPerformed(ActionEvent e) {
    24         System.out.println("Opening "+url);
    25         OpenBrowser.displayUrl(url);
     47        if (link instanceof LinkPost) {
     48                try {
     49                        LinkPost lp = (LinkPost) link;
     50                        System.out.println("Sending POST request to "+lp.url);
     51                        HttpURLConnection conn = (HttpURLConnection) new URL(lp.url).openConnection();
     52                                conn.setDoOutput(true);
     53                                conn.setRequestMethod("POST");
     54                                for (String header : lp.headers.keySet()) {
     55                                        conn.setRequestProperty(header, lp.headers.get(header));
     56                                }
     57                                String data = "";
     58                                for (String param : lp.params.keySet()) {
     59                                        if (!data.isEmpty()) {
     60                                                data += "&";
     61                                        }
     62                                        data += param+"="+lp.params.get(param);
     63                                }
     64                                OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());
     65                                osw.write(data);
     66                                osw.flush();
     67                                osw.close();
     68                               
     69                                String filename = "output.pdf";// FIXME: should work for PDF files only (not even tested)
     70                                FileOutputStream fos = new FileOutputStream(filename);
     71                                InputStream is = conn.getInputStream();
     72                                byte[] buffer = new byte[2048];
     73                                int n = -1;
     74                                while ((n = is.read(buffer)) > -1) {
     75                                        fos.write(buffer, 0, n);
     76                                }
     77                                is.close();
     78                                fos.close();
     79                               
     80                        System.out.println("Opening "+filename);
     81                        OpenBrowser.displayUrl("file://"+filename);
     82                               
     83                        } catch (MalformedURLException ex) {
     84                                ex.printStackTrace();
     85                        } catch (IOException ex) {
     86                                ex.printStackTrace();
     87                        }
     88        } else {
     89                System.out.println("Opening "+link.url);
     90                OpenBrowser.displayUrl(link.url);
     91        }
    2692    }
    2793}
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenMailAction.java

    r26964 r26980  
     1//    JOSM tag2link plugin.
     2//    Copyright (C) 2011 Don-vip & FrViPofm
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.tag2link.action;
    217
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Condition.java

    r26917 r26980  
     1//    JOSM tag2link plugin.
     2//    Copyright (C) 2011 Don-vip & FrViPofm
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.tag2link.data;
    217
     
    722    public Pattern valPattern;
    823    public String id;
     24   
     25        /* (non-Javadoc)
     26         * @see java.lang.Object#toString()
     27         */
     28        @Override
     29        public String toString() {
     30                return "Condition ["
     31                                + (keyPattern != null ? "k=" + keyPattern + ", " : "")
     32                                + (valPattern != null ? "v=" + valPattern + ", " : "")
     33                                + (id != null ? "id=" + id : "") + "]";
     34        }
    935}
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Link.java

    r26918 r26980  
     1//    JOSM tag2link plugin.
     2//    Copyright (C) 2011 Don-vip & FrViPofm
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.tag2link.data;
    217
    3 public class Link {
     18public class Link implements Cloneable {
    419    public String name;
    520    public String url;
     
    1126   
    1227    public Link(Link link) {
    13         this(link.name, link.url);
     28        this(new String(link.name), new String(link.url));
    1429    }
    1530   
    16     private boolean containsParams(String s) {
     31    protected final boolean containsParams(String s) {
    1732        return s.matches("[^{}]*{[^{}]*}[^{}]*");
    1833    }
    1934   
    20     public boolean nameContainsParams() {
     35    public final boolean nameContainsParams() {
    2136        return containsParams(name);
    2237    }
    2338   
    24     public boolean urlContainsParams() {
     39    public final boolean urlContainsParams() {
    2540        return containsParams(url);
    2641    }
     
    2944        return nameContainsParams() || urlContainsParams();
    3045    }
     46
     47        /* (non-Javadoc)
     48         * @see java.lang.Object#toString()
     49         */
     50        @Override
     51        public String toString() {
     52                return "Link [name=" + name + ", url=" + url + "]";
     53        }
     54
     55        /* (non-Javadoc)
     56         * @see java.lang.Object#clone()
     57         */
     58        @Override
     59        public Link clone() throws CloneNotSupportedException {
     60                return new Link(this);
     61        }
    3162}
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java

    r26922 r26980  
     1//    JOSM tag2link plugin.
     2//    Copyright (C) 2011 Don-vip & FrViPofm
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.tag2link.data;
    217
     
    3954                }
    4055        }
     56                /* (non-Javadoc)
     57                 * @see java.lang.Object#toString()
     58                 */
     59                @Override
     60                public String toString() {
     61                        return "MatchingTag [" + (key != null ? "key=" + key + ", " : "")
     62                                        + (value != null ? "value=" + value + ", " : "")
     63                                        + (params != null ? "params=" + params + ", " : "")
     64                                        + (prefix != null ? "prefix=" + prefix : "") + "]";
     65                }
    4166    }
    4267   
    4368    public static class EvalResult {
     69        private final int conditionsNumber;
     70        public EvalResult(int conditionsNumber) {
     71                this.conditionsNumber = conditionsNumber;
     72        }
    4473        public final Collection<MatchingTag> matchingTags = new ArrayList<MatchingTag>();
    4574        public boolean matches() {
    46             return !matchingTags.isEmpty();
     75            return conditionsNumber > 0 && matchingTags.size() >= conditionsNumber;
    4776        }
     77                /* (non-Javadoc)
     78                 * @see java.lang.Object#toString()
     79                 */
     80                @Override
     81                public String toString() {
     82                        return "EvalResult [conditionsNumber=" + conditionsNumber
     83                                        + ", matchingTags=" + matchingTags + "]";
     84                }
    4885    }
    4986   
    5087    public EvalResult evaluates(Map<String, String> tags) {
    51         EvalResult result = new EvalResult();
     88        EvalResult result = new EvalResult(conditions.size());
    5289        for (Condition c : conditions) {
    5390            for (String key : tags.keySet()) {
     
    73110        }
    74111        return result;
    75 
    76112    }
    77113   
     
    85121                return evaluates(map);
    86122        }
     123
     124        /* (non-Javadoc)
     125         * @see java.lang.Object#toString()
     126         */
     127        @Override
     128        public String toString() {
     129                return "Rule [conditions=" + conditions + ", links=" + links + "]";
     130        }
    87131}
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Source.java

    r26918 r26980  
     1//    JOSM tag2link plugin.
     2//    Copyright (C) 2011 Don-vip & FrViPofm
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.tag2link.data;
    217
     
    1126                this.name = name;
    1227        }
     28
     29        /* (non-Javadoc)
     30         * @see java.lang.Object#toString()
     31         */
     32        @Override
     33        public String toString() {
     34                return "Source [name=" + name + ", rules=" + rules + "]";
     35        }
    1336}
  • applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java

    r26921 r26980  
     1//    JOSM tag2link plugin.
     2//    Copyright (C) 2011 Don-vip & FrViPofm
     3//
     4//    This program is free software: you can redistribute it and/or modify
     5//    it under the terms of the GNU General Public License as published by
     6//    the Free Software Foundation, either version 3 of the License, or
     7//    (at your option) any later version.
     8//
     9//    This program is distributed in the hope that it will be useful,
     10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12//    GNU General Public License for more details.
     13//
     14//    You should have received a copy of the GNU General Public License
     15//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    116package org.openstreetmap.josm.plugins.tag2link.io;
    217
     
    823import java.util.ArrayList;
    924import java.util.Collection;
     25import java.util.HashMap;
    1026import java.util.List;
     27import java.util.Map;
    1128import java.util.regex.Pattern;
    1229
     
    2138import org.openstreetmap.josm.plugins.tag2link.data.Condition;
    2239import org.openstreetmap.josm.plugins.tag2link.data.Link;
     40import org.openstreetmap.josm.plugins.tag2link.data.LinkPost;
    2341import org.openstreetmap.josm.plugins.tag2link.data.Rule;
    2442import org.openstreetmap.josm.plugins.tag2link.data.Source;
     
    174192
    175193    private Link parseLink() throws XMLStreamException {
    176         Link link = new Link(
    177                 parser.getAttributeValue(null, "name"),
    178                 parser.getAttributeValue(null, "href")
    179         );
    180         jumpToEnd();
     194        Link link = null;
     195        String name = parser.getAttributeValue(null, "name");
     196        String href = parser.getAttributeValue(null, "href");
     197       
     198        if ("POST".equals(parser.getAttributeValue(null, "method"))) {
     199                Map<String, String> headers = null;
     200                Map<String, String> params = null;
     201                while (parser.hasNext()) {
     202                int event = parser.next();
     203                if (event == XMLStreamConstants.START_ELEMENT) {
     204                    if (parser.getLocalName().equals("header")) {
     205                        if (headers == null) {
     206                                headers = new HashMap<String, String>();
     207                        }
     208                        headers.put(parser.getAttributeValue(null, "name"), parser.getAttributeValue(null, "value"));
     209                    } else if (parser.getLocalName().equals("param")) {
     210                        if (params == null) {
     211                                params = new HashMap<String, String>();
     212                        }
     213                        params.put(parser.getAttributeValue(null, "name"), parser.getAttributeValue(null, "value"));
     214                    } else {
     215                        parseUnknown();
     216                    }
     217                } else if (event == XMLStreamConstants.END_ELEMENT) {
     218                    if (parser.getLocalName().equals("link")) {
     219                        break;
     220                    }
     221                }
     222            }
     223                link = new LinkPost(name, href, headers, params);
     224        } else {
     225                link = new Link(name, href);
     226                jumpToEnd();
     227        }
    181228        return link;
    182229    }
Note: See TracChangeset for help on using the changeset viewer.