Changeset 28547 in osm for applications
- Timestamp:
- 2012-08-15T14:01:54+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/tag2link
- Files:
-
- 1 added
- 19 edited
-
. (modified) (1 prop)
-
.settings (added)
-
src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkConstants.java (modified) (2 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPlugin.java (modified) (4 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPreferenceSetting.java (modified) (2 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java (modified) (6 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java (modified) (4 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/action/OpenMailAction.java (modified) (3 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/data/Condition.java (modified) (2 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/data/Link.java (modified) (3 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/data/LinkPost.java (modified) (2 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java (modified) (4 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/data/Source.java (modified) (2 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java (modified) (5 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractIPrimitivePopupListener.java (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractPopupListener.java (modified) (2 diffs)
-
src/org/openstreetmap/josm/plugins/tag2link/listeners/MembershipPopupListener.java (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/tag2link/listeners/PropertyPopupListener.java (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/tag2link/listeners/RelationPopupListener.java (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/tag2link/listeners/SelectionPopupListener.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tag2link
- Property svn:ignore
-
old new 1 1 build 2 .settings3 2 .classpath 4 3 .project
-
- Property svn:ignore
-
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkConstants.java
r26964 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 23 23 public interface Tag2LinkConstants { 24 24 25 /** 26 * XML Schema 27 */ 28 public static final String XML_LOCATION = "/resources/tag2link_sources.xml"; 29 30 /** 31 * File encoding. 32 */ 33 public static final String UTF8_ENCODING = "UTF-8"; 34 35 /** 36 * Plugin icons. 37 */ 38 public static String ICON_16 = "tag2linkv2_16x16.png"; 39 public static String ICON_24 = "tag2linkv2_24x24.png"; 25 /** 26 * XML Schema 27 */ 28 public static final String XML_LOCATION = "/resources/tag2link_sources.xml"; 29 30 /** 31 * File encoding. 32 */ 33 public static final String UTF8_ENCODING = "UTF-8"; 34 35 /** 36 * Plugin icon, 16x16 pixels. 37 */ 38 public static String ICON_16 = "tag2linkv2_16x16.png"; 39 40 /** 41 * Plugin icon, 24x24 pixels. 42 */ 43 public static String ICON_24 = "tag2linkv2_24x24.png"; 44 45 /** 46 * Plugin icon, 48x48 pixels. 47 */ 40 48 public static String ICON_48 = "tag2linkv2_48x48.png"; 41 49 50 /** 51 * Mail icon, 24x24 pixels. 52 */ 42 53 public static String MAIL_ICON_24 = "tag2mailv3_24x24.png"; 43 54 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPlugin.java
r27857 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 17 17 18 18 import org.openstreetmap.josm.gui.MapFrame; 19 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;20 19 import org.openstreetmap.josm.plugins.Plugin; 21 20 import org.openstreetmap.josm.plugins.PluginInformation; … … 29 28 * @author Don-vip 30 29 * History: 30 * 0.3d 15-Aug-2012 Add ref:(FR:)?FINESS and osm.fr link for ref:(FR:)?INSEE (josm#7961) 31 31 * 0.3c 22-Dec-2011 Add contact namespace for website 32 32 * 0.3b 29-Oct-2011 Add UAI support … … 44 44 // private Tag2LinkPreferenceSetting preferenceSetting; TODO 45 45 46 /**47 * Initializes the plugin.48 * @param info49 */50 public Tag2LinkPlugin(PluginInformation info) {51 super(info);52 // this.preferenceSetting = new Tag2LinkPreferenceSetting();53 Tag2LinkRuleChecker.init();54 }46 /** 47 * Initializes the plugin. 48 * @param info The plugin info provided by JOSM 49 */ 50 public Tag2LinkPlugin(PluginInformation info) { 51 super(info); 52 // this.preferenceSetting = new Tag2LinkPreferenceSetting(); 53 Tag2LinkRuleChecker.init(); 54 } 55 55 56 56 /* (non-Javadoc) -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPreferenceSetting.java
r27857 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 21 21 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 22 22 23 /** 24 * Preferences of tag2link plugin. Currently not implemented. 25 * @author Don-vip 26 * 27 */ 23 28 public class Tag2LinkPreferenceSetting extends DefaultTabPreferenceSetting implements Tag2LinkConstants { 24 29 30 /** 31 * Constructs a new {@code Tag2LinkPreferenceSetting}. 32 */ 25 33 public Tag2LinkPreferenceSetting() { 26 34 super(ICON_48, tr("Tag2Link Preferences"), tr("Tag2Link Preferences")); -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 37 37 import org.openstreetmap.josm.plugins.tag2link.io.SourcesReader; 38 38 39 /** 40 * Class matching rules against a specified OSM primitive in order to get its relevant links. 41 * @author Don-vip 42 * 43 */ 39 44 public class Tag2LinkRuleChecker implements Tag2LinkConstants { 40 45 … … 42 47 43 48 private static boolean initialized = false; 44 49 50 /** 51 * Initializes the matching rules mechanism. 52 */ 45 53 public static void init() { 46 54 if (!initialized) { … … 51 59 52 60 private static String findValue(String arg, Collection<MatchingTag> matchingTags) { 53 for (MatchingTag tag : matchingTags) {54 if (tag.params.containsKey(arg)) {55 return tag.params.get(arg);56 }57 }58 return null;61 for (MatchingTag tag : matchingTags) { 62 if (tag.params.containsKey(arg)) { 63 return tag.params.get(arg); 64 } 65 } 66 return null; 59 67 } 60 68 61 69 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 value68 String val = findValue(arg, eval.matchingTags);69 70 // No standard value found: test lang() function71 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 value96 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 parameter112 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;70 String result = s; 71 Matcher m = Pattern.compile("%([^%]*)%").matcher(s); 72 while (m.find()) { 73 String arg = m.group(1); 74 75 // Search for a standard value 76 String val = findValue(arg, eval.matchingTags); 77 78 // No standard value found: test lang() function 79 if (val == null) { 80 Matcher lm = Pattern.compile(".*lang(?:\\((\\p{Lower}{2,})(?:,(\\p{Lower}{2,}))*\\))?.*").matcher(arg); 81 if (lm.matches()) { 82 String josmLang = Main.pref.get("language"); 83 String jvmLang = (josmLang.isEmpty() ? Locale.getDefault().getLanguage() : josmLang).split("_")[0]; 84 if (lm.groupCount() == 0) { 85 val = jvmLang; 86 } else { 87 for (int i = 1; i<=lm.groupCount() && val == null; i++) { 88 if (jvmLang.equals(lm.group(i))) { 89 val = jvmLang; 90 } 91 } 92 } 93 } 94 } 95 96 // Find a default value if set after ":" 97 if (val == null && arg.contains(":")) { 98 String[] vars = arg.split(":"); 99 for (int i = 0; val == null && i < vars.length-1; i++) { 100 val = findValue(vars[i], eval.matchingTags); 101 } 102 if (val == null) { 103 // Default value 104 val = vars[vars.length-1]; 105 } 106 } 107 108 // Has a value been found ? 109 if (val != null) { 110 try { 111 // Special hack for Wikipedia that prevents spaces being replaced by "+" characters, but by "_" 112 if (s.contains("wikipedia.")) { 113 val = val.replaceAll(" ", "_"); 114 } 115 // Encode param to be included in the URL, except if it is the URL itself ! 116 if (!m.group().equals(s)) { 117 val = URLEncoder.encode(val, UTF8_ENCODING); 118 } 119 // Finally replace parameter 120 result = result.replaceFirst(Pattern.quote(m.group()), val); 121 } catch (UnsupportedEncodingException e) { 122 e.printStackTrace(); 123 } 124 } else { 125 System.err.println("Invalid argument: "+arg); 126 } 127 } 128 return result; 121 129 } 122 130 123 131 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 do131 } else if (key.equals(key2)) {132 // Update value133 map.put(key, value2);134 } else {135 // Update key, and maybe value136 map.remove(key);137 map.put(key2, value2);138 }139 }132 for (Iterator<String> it = map.keySet().iterator(); it.hasNext(); ) { 133 String key = it.next(); 134 String value = map.get(key); 135 String key2 = replaceParams(key, eval); 136 String value2 = replaceParams(value, eval); 137 if (key.equals(key2) && value.equals(value2)) { 138 // Nothing to do 139 } else if (key.equals(key2)) { 140 // Update value 141 map.put(key, value2); 142 } else { 143 // Update key, and maybe value 144 map.remove(key); 145 map.put(key2, value2); 146 } 147 } 140 148 } 141 149 142 150 private static Collection<Link> processEval(EvalResult eval, Rule rule, Source source) { 143 Collection<Link> result = new ArrayList<Link>();151 Collection<Link> result = new ArrayList<Link>(); 144 152 if (eval.matches()) { 145 153 for (Link link : rule.links) { 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 } 159 } 160 } 161 return result; 162 } 163 154 try { 155 Link copy = (Link) link.clone(); 156 copy.name = copy.name.replaceAll("%name%", source.name); 157 copy.url = replaceParams(copy.url, eval); 158 if (copy instanceof LinkPost) { 159 LinkPost lp = (LinkPost) copy; 160 replaceMapParams(lp.headers, eval); 161 replaceMapParams(lp.params, eval); 162 } 163 result.add(copy); 164 } catch (CloneNotSupportedException e) { 165 System.err.println(e); 166 } 167 } 168 } 169 return result; 170 } 171 172 /** 173 * Replies the links relevant to the given OSM primitive. 174 * @param p The OSM primitive 175 * @return the links relevant to the {@code p}. 176 */ 164 177 public static Collection<Link> getLinks(IPrimitive p) { 165 178 Collection<Link> result = new ArrayList<Link>(); … … 172 185 } 173 186 174 public static Collection<Link> getLinks(Tag tag) { 175 Collection<Link> result = new ArrayList<Link>(); 187 /** 188 * Replies the links relevant to the given OSM tag. 189 * @param tag The OSM tag 190 * @return the links relevant to the {@code tag}. 191 */ 192 public static Collection<Link> getLinks(Tag tag) { 193 Collection<Link> result = new ArrayList<Link>(); 176 194 for (Source source : sources) { 177 195 for (Rule rule : source.rules) { … … 179 197 } 180 198 } 181 return result;182 }199 return result; 200 } 183 201 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java
r28546 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 33 33 import org.openstreetmap.josm.tools.OpenBrowser; 34 34 35 /** 36 * Action allowing to open a general link. 37 * @author Don-vip 38 * 39 */ 35 40 @SuppressWarnings("serial") 36 41 public class OpenLinkAction extends JosmAction implements Tag2LinkConstants { … … 38 43 private Link link; 39 44 45 /** 46 * Constructs a new {@code OpenLinkAction}. 47 * @param link The link to open 48 */ 40 49 public OpenLinkAction(Link link) { 41 50 super(tr(link.name), ICON_24, tr("Launch browser with information about the selected object"), null, false); … … 45 54 @Override 46 55 public void actionPerformed(ActionEvent e) { 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 String result = OpenBrowser.displayUrl("file://"+filename);82 if (result != null) {83 System.err.println(result);84 }85 86 } catch (MalformedURLException ex) {87 ex.printStackTrace();88 } catch (IOException ex) {89 ex.printStackTrace();90 }91 } else {92 System.out.println("Opening "+link.url);93 String result = OpenBrowser.displayUrl(link.url);94 if (result != null) {95 System.err.println(result);96 }97 }56 if (link instanceof LinkPost) { 57 try { 58 LinkPost lp = (LinkPost) link; 59 System.out.println("Sending POST request to "+lp.url); 60 HttpURLConnection conn = (HttpURLConnection) new URL(lp.url).openConnection(); 61 conn.setDoOutput(true); 62 conn.setRequestMethod("POST"); 63 for (String header : lp.headers.keySet()) { 64 conn.setRequestProperty(header, lp.headers.get(header)); 65 } 66 String data = ""; 67 for (String param : lp.params.keySet()) { 68 if (!data.isEmpty()) { 69 data += "&"; 70 } 71 data += param+"="+lp.params.get(param); 72 } 73 OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream()); 74 osw.write(data); 75 osw.flush(); 76 osw.close(); 77 78 String filename = "output.pdf";// FIXME: should work for PDF files only (not even tested) 79 FileOutputStream fos = new FileOutputStream(filename); 80 InputStream is = conn.getInputStream(); 81 byte[] buffer = new byte[2048]; 82 int n = -1; 83 while ((n = is.read(buffer)) > -1) { 84 fos.write(buffer, 0, n); 85 } 86 is.close(); 87 fos.close(); 88 89 System.out.println("Opening "+filename); 90 String result = OpenBrowser.displayUrl("file://"+filename); 91 if (result != null) { 92 System.err.println(result); 93 } 94 95 } catch (MalformedURLException ex) { 96 ex.printStackTrace(); 97 } catch (IOException ex) { 98 ex.printStackTrace(); 99 } 100 } else { 101 System.out.println("Opening "+link.url); 102 String result = OpenBrowser.displayUrl(link.url); 103 if (result != null) { 104 System.err.println(result); 105 } 106 } 98 107 } 99 108 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenMailAction.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 26 26 import org.openstreetmap.josm.plugins.tag2link.data.Link; 27 27 28 /** 29 * Action allowing to open a mailto:// link. 30 * @author Don-vip 31 * 32 */ 28 33 @SuppressWarnings("serial") 29 34 public class OpenMailAction extends JosmAction implements Tag2LinkConstants { 30 35 31 36 private String url; 32 37 38 /** 39 * Constructs a new {@code OpenMailAction}. 40 * @param link The link to open 41 */ 33 42 public OpenMailAction(Link link) { 34 43 super(tr(link.name), MAIL_ICON_24, tr("Launch your default software for sending an email to the selected contact address"), null, false); … … 38 47 @Override 39 48 public void actionPerformed(ActionEvent e) { 40 if (Desktop.isDesktopSupported()) {41 try {42 System.out.println("Sending "+url);43 Desktop.getDesktop().mail(new URI(url));44 } catch (Exception ex) {45 ex.printStackTrace();46 }47 }49 if (Desktop.isDesktopSupported()) { 50 try { 51 System.out.println("Sending "+url); 52 Desktop.getDesktop().mail(new URI(url)); 53 } catch (Exception ex) { 54 ex.printStackTrace(); 55 } 56 } 48 57 } 49 58 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Condition.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 18 18 import java.util.regex.Pattern; 19 19 20 /** 21 * A condition allowing to match a rule against an OSM primitive or tag. 22 * @author Don-vip 23 * 24 */ 20 25 public class Condition { 26 27 /** 28 * The pattern used against tag key. May be null. 29 */ 21 30 public Pattern keyPattern; 31 32 /** 33 * The pattern used against tag value. May be null. 34 */ 22 35 public Pattern valPattern; 36 37 /** 38 * The condition id. May be null. 39 */ 23 40 public String id; 24 41 25 /* (non-Javadoc)26 * @see java.lang.Object#toString()27 */28 @Override29 public String toString() {30 return "Condition ["31 + (keyPattern != null ? "k=" + keyPattern + ", " : "")32 + (valPattern != null ? "v=" + valPattern + ", " : "")33 + (id != null ? "id=" + id : "") + "]";34 }42 /* (non-Javadoc) 43 * @see java.lang.Object#toString() 44 */ 45 @Override 46 public String toString() { 47 return "Condition [" 48 + (keyPattern != null ? "k=" + keyPattern + ", " : "") 49 + (valPattern != null ? "v=" + valPattern + ", " : "") 50 + (id != null ? "id=" + id : "") + "]"; 51 } 35 52 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Link.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 21 21 22 22 public Link(String name, String url) { 23 this.name = name;24 this.url = url;23 this.name = name; 24 this.url = url; 25 25 } 26 26 27 27 public Link(Link link) { 28 this(new String(link.name), new String(link.url));28 this(new String(link.name), new String(link.url)); 29 29 } 30 30 … … 45 45 } 46 46 47 /* (non-Javadoc)48 * @see java.lang.Object#toString()49 */50 @Override51 public String toString() {52 return "Link [name=" + name + ", url=" + url + "]";53 }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 54 55 /* (non-Javadoc)56 * @see java.lang.Object#clone()57 */58 @Override59 public Link clone() throws CloneNotSupportedException {60 return new Link(this);61 }55 /* (non-Javadoc) 56 * @see java.lang.Object#clone() 57 */ 58 @Override 59 public Link clone() throws CloneNotSupportedException { 60 return new Link(this); 61 } 62 62 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/LinkPost.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 21 21 public class LinkPost extends Link { 22 22 23 public final Map<String, String> headers;24 public final Map<String, String> params;25 26 public LinkPost(LinkPost link) {27 this(new String(link.name), new String(link.url),28 link.headers == null ? null : new HashMap<String, String>(link.headers),29 link.params == null ? null : new HashMap<String, String>(link.params));30 }23 public final Map<String, String> headers; 24 public final Map<String, String> params; 25 26 public LinkPost(LinkPost link) { 27 this(new String(link.name), new String(link.url), 28 link.headers == null ? null : new HashMap<String, String>(link.headers), 29 link.params == null ? null : new HashMap<String, String>(link.params)); 30 } 31 31 32 public LinkPost(String name, String url) {33 this(name, url, null, null);34 }32 public LinkPost(String name, String url) { 33 this(name, url, null, null); 34 } 35 35 36 public LinkPost(String name, String url, Map<String, String> headers, Map<String, String> params) {37 super(name, url);38 this.headers = headers;39 this.params = params;40 }41 42 protected final boolean containsParams(Map<String, String> map) {43 if (map != null) {44 for (String key : map.keySet()) {45 if (containsParams(map.get(key))) {46 return true;47 }48 }49 }50 return false;51 }52 53 public boolean headersContainsParams() {54 return containsParams(headers);55 }36 public LinkPost(String name, String url, Map<String, String> headers, Map<String, String> params) { 37 super(name, url); 38 this.headers = headers; 39 this.params = params; 40 } 41 42 protected final boolean containsParams(Map<String, String> map) { 43 if (map != null) { 44 for (String key : map.keySet()) { 45 if (containsParams(map.get(key))) { 46 return true; 47 } 48 } 49 } 50 return false; 51 } 52 53 public boolean headersContainsParams() { 54 return containsParams(headers); 55 } 56 56 57 public boolean paramsContainsParams() {58 return containsParams(params);59 }57 public boolean paramsContainsParams() { 58 return containsParams(params); 59 } 60 60 61 /* (non-Javadoc)62 * @see org.openstreetmap.josm.plugins.tag2link.data.Link#containsParams()63 */64 @Override65 public boolean containsParams() {66 return super.containsParams() || headersContainsParams() || paramsContainsParams();67 }61 /* (non-Javadoc) 62 * @see org.openstreetmap.josm.plugins.tag2link.data.Link#containsParams() 63 */ 64 @Override 65 public boolean containsParams() { 66 return super.containsParams() || headersContainsParams() || paramsContainsParams(); 67 } 68 68 69 /* (non-Javadoc)70 * @see org.openstreetmap.josm.plugins.tag2link.data.Link#clone()71 */72 @Override73 public LinkPost clone() throws CloneNotSupportedException {74 return new LinkPost(this);75 }69 /* (non-Javadoc) 70 * @see org.openstreetmap.josm.plugins.tag2link.data.Link#clone() 71 */ 72 @Override 73 public LinkPost clone() throws CloneNotSupportedException { 74 return new LinkPost(this); 75 } 76 76 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 35 35 private String prefix; 36 36 public MatchingTag(String key, String value, String prefix) { 37 this.key = key;38 this.value = value;39 this.params = new HashMap<String, String>();40 this.prefix = prefix;41 addKeyValueParams();37 this.key = key; 38 this.value = value; 39 this.params = new HashMap<String, String>(); 40 this.prefix = prefix; 41 addKeyValueParams(); 42 42 } 43 43 public void addParams(Matcher m, String paramName) { 44 for (int i = 1; i<=m.groupCount(); i++) {45 params.put(prefix+paramName+"."+i, m.group(i));46 }44 for (int i = 1; i<=m.groupCount(); i++) { 45 params.put(prefix+paramName+"."+i, m.group(i)); 46 } 47 47 } 48 48 private void addKeyValueParams() { 49 params.put("k", key);50 params.put("v", value);51 if (!prefix.isEmpty()) {52 params.put(prefix+"k", key);53 params.put(prefix+"v", value);54 }49 params.put("k", key); 50 params.put("v", value); 51 if (!prefix.isEmpty()) { 52 params.put(prefix+"k", key); 53 params.put(prefix+"v", value); 54 } 55 55 } 56 /* (non-Javadoc)57 * @see java.lang.Object#toString()58 */59 @Override60 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 }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 } 66 66 } 67 67 68 68 public static class EvalResult { 69 private final int conditionsNumber;70 public EvalResult(int conditionsNumber) {71 this.conditionsNumber = conditionsNumber;72 }69 private final int conditionsNumber; 70 public EvalResult(int conditionsNumber) { 71 this.conditionsNumber = conditionsNumber; 72 } 73 73 public final Collection<MatchingTag> matchingTags = new ArrayList<MatchingTag>(); 74 74 public boolean matches() { 75 75 return conditionsNumber > 0 && matchingTags.size() >= conditionsNumber; 76 76 } 77 /* (non-Javadoc)78 * @see java.lang.Object#toString()79 */80 @Override81 public String toString() {82 return "EvalResult [conditionsNumber=" + conditionsNumber83 + ", matchingTags=" + matchingTags + "]";84 }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 } 85 85 } 86 86 … … 91 91 Matcher keyMatcher = c.keyPattern.matcher(key); 92 92 if (keyMatcher.matches()) { 93 String idPrefix = c.id == null ? "" : c.id+".";94 MatchingTag tag = new MatchingTag(key, tags.get(key), idPrefix);95 tag.addParams(keyMatcher, "k");96 boolean matchingTag = true;97 if (c.valPattern != null) {98 Matcher valMatcher = c.valPattern.matcher(tag.value);99 if (valMatcher.matches()) {100 tag.addParams(valMatcher, "v");101 } else {102 matchingTag = false;103 }104 }105 if (matchingTag) {106 result.matchingTags.add(tag);107 }93 String idPrefix = c.id == null ? "" : c.id+"."; 94 MatchingTag tag = new MatchingTag(key, tags.get(key), idPrefix); 95 tag.addParams(keyMatcher, "k"); 96 boolean matchingTag = true; 97 if (c.valPattern != null) { 98 Matcher valMatcher = c.valPattern.matcher(tag.value); 99 if (valMatcher.matches()) { 100 tag.addParams(valMatcher, "v"); 101 } else { 102 matchingTag = false; 103 } 104 } 105 if (matchingTag) { 106 result.matchingTags.add(tag); 107 } 108 108 } 109 109 } … … 113 113 114 114 public EvalResult evaluates(IPrimitive p) { 115 return evaluates(p.getKeys());115 return evaluates(p.getKeys()); 116 116 } 117 117 118 public EvalResult evaluates(Tag tag) {119 Map<String, String> map = new HashMap<String, String>();120 map.put(tag.getKey(), tag.getValue());121 return evaluates(map);122 }118 public EvalResult evaluates(Tag tag) { 119 Map<String, String> map = new HashMap<String, String>(); 120 map.put(tag.getKey(), tag.getValue()); 121 return evaluates(map); 122 } 123 123 124 /* (non-Javadoc)125 * @see java.lang.Object#toString()126 */127 @Override128 public String toString() {129 return "Rule [conditions=" + conditions + ", links=" + links + "]";130 }124 /* (non-Javadoc) 125 * @see java.lang.Object#toString() 126 */ 127 @Override 128 public String toString() { 129 return "Rule [conditions=" + conditions + ", links=" + links + "]"; 130 } 131 131 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Source.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 19 19 import java.util.Collection; 20 20 21 /** 22 * A source of links relative to an OSM primitive or tag, depending of the successful match of its conditions against it. 23 * @author Don-vip 24 * 25 */ 21 26 public class Source { 27 /** 28 * The user-friendly source name. 29 */ 22 30 public final String name; 31 32 /** 33 * The rules applied against an OSM primitive or tag. 34 */ 23 35 public final Collection<Rule> rules = new ArrayList<Rule>(); 24 36 37 /** 38 * Constructs a new {@code Source}. 39 * @param name The user-friendly source name 40 */ 25 41 public Source(String name) { 26 this.name = name;27 }42 this.name = name; 43 } 28 44 29 /* (non-Javadoc)30 * @see java.lang.Object#toString()31 */32 @Override33 public String toString() {34 return "Source [name=" + name + ", rules=" + rules + "]";35 }45 /* (non-Javadoc) 46 * @see java.lang.Object#toString() 47 */ 48 @Override 49 public String toString() { 50 return "Source [name=" + name + ", rules=" + rules + "]"; 51 } 36 52 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java
r26980 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 42 42 import org.openstreetmap.josm.plugins.tag2link.data.Source; 43 43 44 /** 45 * Class allowing to read the sources file. 46 * @author Don-vip 47 * 48 */ 44 49 public class SourcesReader implements Tag2LinkConstants { 45 50 46 51 XMLStreamReader parser; 47 52 53 /** 54 * Constructs a new {@code SourcesReader}. 55 * @param parser The XML parser 56 */ 48 57 public SourcesReader(XMLStreamReader parser) { 49 58 this.parser = parser; 50 59 } 51 60 61 /** 62 * Reads the sources and replies them as a {@code Collection}. 63 * @return The colleciton of sources. 64 */ 52 65 public static Collection<Source> readSources() { 53 66 List<Source> result = new ArrayList<Source>(); … … 184 197 String v = parser.getAttributeValue(null, "v"); 185 198 if (v != null) { 186 c.valPattern = Pattern.compile(v);199 c.valPattern = Pattern.compile(v); 187 200 } 188 201 c.id = parser.getAttributeValue(null, "id"); … … 197 210 198 211 if ("POST".equals(parser.getAttributeValue(null, "method"))) { 199 Map<String, String> headers = null;200 Map<String, String> params = null;201 while (parser.hasNext()) {212 Map<String, String> headers = null; 213 Map<String, String> params = null; 214 while (parser.hasNext()) { 202 215 int event = parser.next(); 203 216 if (event == XMLStreamConstants.START_ELEMENT) { 204 217 if (parser.getLocalName().equals("header")) { 205 218 if (headers == null) { 206 headers = new HashMap<String, String>();219 headers = new HashMap<String, String>(); 207 220 } 208 221 headers.put(parser.getAttributeValue(null, "name"), parser.getAttributeValue(null, "value")); 209 222 } else if (parser.getLocalName().equals("param")) { 210 223 if (params == null) { 211 params = new HashMap<String, String>();224 params = new HashMap<String, String>(); 212 225 } 213 226 params.put(parser.getAttributeValue(null, "name"), parser.getAttributeValue(null, "value")); … … 217 230 } else if (event == XMLStreamConstants.END_ELEMENT) { 218 231 if (parser.getLocalName().equals("link")) { 219 break;232 break; 220 233 } 221 234 } 222 235 } 223 link = new LinkPost(name, href, headers, params);236 link = new LinkPost(name, href, headers, params); 224 237 } else { 225 link = new Link(name, href);226 jumpToEnd();238 link = new Link(name, href); 239 jumpToEnd(); 227 240 } 228 241 return link; -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractIPrimitivePopupListener.java
r26921 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/AbstractPopupListener.java
r26964 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify … … 54 54 55 55 protected void addLink(JPopupMenu popup, Link link) { 56 JosmAction action = null;57 if (link.url.matches("mailto:.*")) {58 action = new OpenMailAction(link);59 } else {60 action = new OpenLinkAction(link);61 }56 JosmAction action = null; 57 if (link.url.matches("mailto:.*")) { 58 action = new OpenMailAction(link); 59 } else { 60 action = new OpenLinkAction(link); 61 } 62 62 63 63 itemList.add(popup.add(action)); -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/MembershipPopupListener.java
r26922 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/PropertyPopupListener.java
r26922 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/RelationPopupListener.java
r26921 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/listeners/SelectionPopupListener.java
r26921 r28547 1 1 // JOSM tag2link plugin. 2 // Copyright (C) 2011 Don-vip & FrViPofm 2 // Copyright (C) 2011-2012 Don-vip & FrViPofm 3 3 // 4 4 // This program is free software: you can redistribute it and/or modify
Note:
See TracChangeset
for help on using the changeset viewer.
