Changeset 26980 in osm
- Timestamp:
- 2011-10-29T03:32:59+02:00 (13 years ago)
- 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 19 19 <tag2link> 20 20 21 <!-- Global --> 21 <!-- Global --> 22 22 23 23 <source name="Common"> … … 54 54 </source> 55 55 56 <!-- Only for France --> 56 <!-- Only for France --> 57 57 58 58 <source name="SANDRE" country-code="FR"> 59 59 <rule> 60 <condition k="ref: sandre" v="[A-Z0-9-]{8}" />60 <condition k="ref:(FR:)?sandre" v="[A-Z0-9-]{8}" /> 61 61 <link name="View %name% sheet of river" href="http://services.sandre.eaufrance.fr/Courdo/Fiche/client/fiche_courdo.php?CdSandre=%v%" /> 62 62 </rule> … … 66 66 <rule> 67 67 <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"/> 69 69 <link name="View %name% municipality sheet" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/fichecommunale.asp?codedep=%ref.v.1%&codecom=%ref.v.2%" /> 70 70 </rule> 71 71 <rule> 72 72 <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"/> 74 74 <link name="View %name% map of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_comcan.asp?codecan=%ref.v%" /> 75 75 <link name="View %name% list of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/comcan.asp?codedep={ref.v.1}&codecan=%ref.v.2%" /> … … 77 77 <rule> 78 78 <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"/> 80 80 <link name="View %name% map of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_canarr.asp?codearr=%ref.v%" /> 81 81 <link name="View %name% list of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/canarr.asp?codedep=%ref.v.1%&codearr=%ref.v.2%" /> … … 83 83 <rule> 84 84 <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"/> 86 86 <link name="View %name% map of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_arrdep.asp?codedep=%ref.v%" /> 87 87 <link name="View %name% list of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/arrdep.asp?codedep=%ref.v%" /> … … 89 89 <rule> 90 90 <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"/> 92 92 <link name="View %name% map of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_depreg.asp?codereg=%ref.v%" /> 93 93 <link name="View %name% list of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/depreg.asp?codereg=%ref.v%" /> … … 103 103 <source name="CEF" country-code="FR"> 104 104 <rule> 105 <condition k="ref: CEF" v="[A-Z0-9_]{8}" />105 <condition k="ref:(FR:)?CEF" v="[A-Z0-9_]{8}" /> 106 106 <link name="View %name% sheet of church" href="http://www.messesinfo.catholique.fr/public/fiche.php?valcode=%v%" /> 107 107 </rule> … … 110 110 <source name="MHS" country-code="FR"> 111 111 <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}" /> 113 113 <link name="View Mérimée sheet of monument" href="http://www.culture.gouv.fr/public/mistral/mersri_fr?ACTION=CHERCHER&FIELD_1=REF&VALUE_1=%v%" /> 114 114 </rule> 115 115 <rule> 116 <condition k="ref: INSEE" v="\p{Digit}{5}" />116 <condition k="ref:(FR:)?INSEE" v="\p{Digit}{5}" /> 117 117 <link name="View Mérimée list for this municipality" href="http://www.culture.gouv.fr/public/mistral/merimee_fr?ACTION=CHERCHER&FIELD_1=cmer1&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&action=fichepdf&source=carte&sit_no=%ref.v.1%" /> 130 <!-- <link name="View %name% sheet of geodesic site" href="http://geodesie.ign.fr/fiches/index.php?module=e&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&action=fichepdf&source=carte&sit_no=%ref.v.1%" /> 118 141 </rule> 119 142 </source> -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPlugin.java
r26964 r26980 29 29 * @author Don-vip 30 30 * History: 31 * 0.3a 29-Oct-2011 Add Country-code prefix, IGN support + not-yet-tested POST requests support 31 32 * 0.2d 24-Oct-2011 Icon for Mail action 32 33 * 0.2c 24-Oct-2011 Another MHS rule -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java
r26956 r26980 20 20 import java.util.ArrayList; 21 21 import java.util.Collection; 22 import java.util.Iterator; 22 23 import java.util.Locale; 24 import java.util.Map; 23 25 import java.util.regex.Matcher; 24 26 import java.util.regex.Pattern; … … 28 30 import org.openstreetmap.josm.data.osm.Tag; 29 31 import org.openstreetmap.josm.plugins.tag2link.data.Link; 32 import org.openstreetmap.josm.plugins.tag2link.data.LinkPost; 30 33 import org.openstreetmap.josm.plugins.tag2link.data.Rule; 31 34 import org.openstreetmap.josm.plugins.tag2link.data.Rule.EvalResult; … … 56 59 } 57 60 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 58 142 private static Collection<Link> processEval(EvalResult eval, Rule rule, Source source) { 59 143 Collection<Link> result = new ArrayList<Link>(); 60 144 if (eval.matches()) { 61 145 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 } 122 159 } 123 160 } -
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/>. 1 16 package org.openstreetmap.josm.plugins.tag2link.action; 2 17 … … 4 19 5 20 import java.awt.event.ActionEvent; 21 import java.io.FileOutputStream; 22 import java.io.IOException; 23 import java.io.InputStream; 24 import java.io.OutputStreamWriter; 25 import java.net.HttpURLConnection; 26 import java.net.MalformedURLException; 27 import java.net.URL; 6 28 7 29 import org.openstreetmap.josm.actions.JosmAction; 8 30 import org.openstreetmap.josm.plugins.tag2link.Tag2LinkConstants; 9 31 import org.openstreetmap.josm.plugins.tag2link.data.Link; 32 import org.openstreetmap.josm.plugins.tag2link.data.LinkPost; 10 33 import org.openstreetmap.josm.tools.OpenBrowser; 11 34 … … 13 36 public class OpenLinkAction extends JosmAction implements Tag2LinkConstants { 14 37 15 private String url;38 private Link link; 16 39 17 40 public OpenLinkAction(Link link) { 18 41 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; 20 43 } 21 44 22 45 @Override 23 46 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 } 26 92 } 27 93 } -
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/>. 1 16 package org.openstreetmap.josm.plugins.tag2link.action; 2 17 -
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/>. 1 16 package org.openstreetmap.josm.plugins.tag2link.data; 2 17 … … 7 22 public Pattern valPattern; 8 23 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 } 9 35 } -
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/>. 1 16 package org.openstreetmap.josm.plugins.tag2link.data; 2 17 3 public class Link {18 public class Link implements Cloneable { 4 19 public String name; 5 20 public String url; … … 11 26 12 27 public Link(Link link) { 13 this( link.name, link.url);28 this(new String(link.name), new String(link.url)); 14 29 } 15 30 16 pr ivateboolean containsParams(String s) {31 protected final boolean containsParams(String s) { 17 32 return s.matches("[^{}]*{[^{}]*}[^{}]*"); 18 33 } 19 34 20 public boolean nameContainsParams() {35 public final boolean nameContainsParams() { 21 36 return containsParams(name); 22 37 } 23 38 24 public boolean urlContainsParams() {39 public final boolean urlContainsParams() { 25 40 return containsParams(url); 26 41 } … … 29 44 return nameContainsParams() || urlContainsParams(); 30 45 } 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 } 31 62 } -
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/>. 1 16 package org.openstreetmap.josm.plugins.tag2link.data; 2 17 … … 39 54 } 40 55 } 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 } 41 66 } 42 67 43 68 public static class EvalResult { 69 private final int conditionsNumber; 70 public EvalResult(int conditionsNumber) { 71 this.conditionsNumber = conditionsNumber; 72 } 44 73 public final Collection<MatchingTag> matchingTags = new ArrayList<MatchingTag>(); 45 74 public boolean matches() { 46 return !matchingTags.isEmpty();75 return conditionsNumber > 0 && matchingTags.size() >= conditionsNumber; 47 76 } 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 } 48 85 } 49 86 50 87 public EvalResult evaluates(Map<String, String> tags) { 51 EvalResult result = new EvalResult( );88 EvalResult result = new EvalResult(conditions.size()); 52 89 for (Condition c : conditions) { 53 90 for (String key : tags.keySet()) { … … 73 110 } 74 111 return result; 75 76 112 } 77 113 … … 85 121 return evaluates(map); 86 122 } 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 } 87 131 } -
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/>. 1 16 package org.openstreetmap.josm.plugins.tag2link.data; 2 17 … … 11 26 this.name = name; 12 27 } 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 } 13 36 } -
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/>. 1 16 package org.openstreetmap.josm.plugins.tag2link.io; 2 17 … … 8 23 import java.util.ArrayList; 9 24 import java.util.Collection; 25 import java.util.HashMap; 10 26 import java.util.List; 27 import java.util.Map; 11 28 import java.util.regex.Pattern; 12 29 … … 21 38 import org.openstreetmap.josm.plugins.tag2link.data.Condition; 22 39 import org.openstreetmap.josm.plugins.tag2link.data.Link; 40 import org.openstreetmap.josm.plugins.tag2link.data.LinkPost; 23 41 import org.openstreetmap.josm.plugins.tag2link.data.Rule; 24 42 import org.openstreetmap.josm.plugins.tag2link.data.Source; … … 174 192 175 193 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 } 181 228 return link; 182 229 }
Note:
See TracChangeset
for help on using the changeset viewer.