Changeset 26918 in osm for applications/editors
- Timestamp:
- 2011-10-21T21:29:51+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/tag2link
- Files:
-
- 1 added
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tag2link/resources/tag2link_sources.xml
r26917 r26918 24 24 <rule> 25 25 <condition k="website" /> 26 <link name="View website" href=" {v}" />26 <link name="View website" href="%v%" /> 27 27 </rule> 28 28 <rule> 29 29 <condition k="url" /> 30 <link name="View URL" href=" {v}" />30 <link name="View URL" href="%v%" /> 31 31 </rule> 32 32 </source> … … 35 35 <rule> 36 36 <condition k="wikipedia(?::([\p{Lower}]{2,}))?" /> 37 <link name="View {name}article" href="http://{k.1:en}.wikipedia.org/wiki/{v}" />37 <link name="View %name% article" href="http://%k.1:en%.wikipedia.org/wiki/%v%" /> 38 38 </rule> 39 39 </source> … … 44 44 <rule> 45 45 <condition k="ref:sandre" v="[A-Z0-9-]{8}" /> 46 <link name="View {name}sheet of river" href="http://services.sandre.eaufrance.fr/Courdo/Fiche/client/fiche_courdo.php?CdSandre={v}" />46 <link name="View %name% sheet of river" href="http://services.sandre.eaufrance.fr/Courdo/Fiche/client/fiche_courdo.php?CdSandre=%v%" /> 47 47 </rule> 48 48 </source> … … 52 52 <condition k="admin_level" v="8"/> 53 53 <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{3})" id="ref"/> 54 <link name="View {name}municipality sheet" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/fichecommunale.asp?codedep={ref.v.1}&codecom={ref.v.2}" />54 <link name="View %name% municipality sheet" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/fichecommunale.asp?codedep=%ref.v.1%&codecom=%ref.v.2%" /> 55 55 </rule> 56 56 <rule> 57 57 <condition k="political_division" v="FR:canton"/> 58 58 <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{2})" id="ref"/> 59 <link name="View {name}map of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_comcan.asp?codecan={ref.v}" />60 <link name="View {name}list of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/comcan.asp?codedep={ref.v.1}&codecan={ref.v.2}" />59 <link name="View %name% map of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_comcan.asp?codecan=%ref.v%" /> 60 <link name="View %name% list of municipalities" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/comcan.asp?codedep={ref.v.1}&codecan=%ref.v.2%" /> 61 61 </rule> 62 62 <rule> 63 63 <condition k="admin_level" v="7"/> 64 64 <condition k="ref:INSEE" v="(\p{Digit}{2})(\p{Digit}{1})" id="ref"/> 65 <link name="View {name}map of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_canarr.asp?codearr={ref.v}" />66 <link name="View {name}list of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/canarr.asp?codedep={ref.v.1}&codearr={ref.v.2}" />65 <link name="View %name% map of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_canarr.asp?codearr=%ref.v%" /> 66 <link name="View %name% list of cantons" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/canarr.asp?codedep=%ref.v.1%&codearr=%ref.v.2%" /> 67 67 </rule> 68 68 <rule> 69 69 <condition k="admin_level" v="6"/> 70 70 <condition k="ref:INSEE" v="\p{Digit}{2}" id="ref"/> 71 <link name="View {name}map of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_arrdep.asp?codedep={ref.v}" />72 <link name="View {name}list of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/arrdep.asp?codedep={ref.v}" />71 <link name="View %name% map of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_arrdep.asp?codedep=%ref.v%" /> 72 <link name="View %name% list of arrondissements" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/arrdep.asp?codedep=%ref.v%" /> 73 73 </rule> 74 74 <rule> 75 75 <condition k="admin_level" v="4"/> 76 76 <condition k="ref:INSEE" v="\p{Digit}{2}" id="ref"/> 77 <link name="View {name}map of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_depreg.asp?codereg={ref.v}" />78 <link name="View {name}list of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/depreg.asp?codereg={ref.v}" />77 <link name="View %name% map of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_depreg.asp?codereg=%ref.v%" /> 78 <link name="View %name% list of departments" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/depreg.asp?codereg=%ref.v%" /> 79 79 </rule> 80 80 <rule> 81 81 <condition k="admin_level" v="2"/> 82 82 <condition k="name" v="France*"/> 83 <link name="View {name}map of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_regions.asp" />84 <link name="View {name}list of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/region.asp" />83 <link name="View %name% map of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/carte_regions.asp" /> 84 <link name="View %name% list of regions" href="http://www.insee.fr/fr/methodes/nomenclatures/cog/region.asp" /> 85 85 </rule> 86 86 </source> -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkRuleChecker.java
r26917 r26918 18 18 import java.util.ArrayList; 19 19 import java.util.Collection; 20 import java.util.HashSet;21 import java.util.Set;22 20 23 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 48 46 EvalResult eval = rule.evaluates(p); 49 47 if (eval.matches()) { 50 Set<String> links = new HashSet<String>(); 51 for (MatchingTag tag : eval.matchingTags) { 52 48 for (Link link : rule.links) { 49 Link copy = new Link(link); 50 copy.name = copy.name.replaceAll("%name%", source.name); 51 MatchingTag firstTag = eval.matchingTags.iterator().next(); 52 copy.url = copy.url.replaceAll("%k%", firstTag.key) 53 .replaceAll("%v%", firstTag.value); 54 result.add(copy); 53 55 } 54 56 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/action/OpenLinkAction.java
r26917 r26918 10 10 import org.openstreetmap.josm.tools.OpenBrowser; 11 11 12 @SuppressWarnings("serial") 12 13 public class OpenLinkAction extends JosmAction implements Tag2LinkConstants { 13 14 … … 15 16 16 17 public OpenLinkAction(Link link) { 17 super(tr(link.name), ICON_ 16, tr("Launch browser with information about the selected object"), null, true);18 super(tr(link.name), ICON_24, tr("Launch browser with information about the selected object"), null, true); 18 19 this.url = link.url; 19 20 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Link.java
r26917 r26918 4 4 public String name; 5 5 public String url; 6 7 public Link(String name, String url) { 8 this.name = name; 9 this.url = url; 10 } 11 12 public Link(Link link) { 13 this(link.name, link.url); 14 } 15 6 16 private boolean containsParams(String s) { 7 17 return s.matches("[^{}]*{[^{}]*}[^{}]*"); 8 18 } 19 9 20 public boolean nameContainsParams() { 10 21 return containsParams(name); 11 22 } 23 12 24 public boolean urlContainsParams() { 13 25 return containsParams(url); 14 26 } 27 15 28 public boolean containsParams() { 16 29 return nameContainsParams() || urlContainsParams(); -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Rule.java
r26917 r26918 17 17 public String value; 18 18 public final Map<String, String> params = new HashMap<String, String>(); 19 public MatchingTag(String key, String value) { 20 this.key = key; 21 this.value = value; 22 } 23 public void addParams(Matcher m, String prefix) { 24 for (int i = 1; i<=m.groupCount(); i++) { 25 this.params.put(prefix+i, m.group(i)); 26 } 27 } 19 28 } 20 29 … … 31 40 for (Condition c : conditions) { 32 41 for (String key : tags.keySet()) { 33 Matcher m = c.keyPattern.matcher(key); 34 if (m.matches()) { 35 42 Matcher keyMatcher = c.keyPattern.matcher(key); 43 if (keyMatcher.matches()) { 44 String idPrefix = c.id == null ? "" : c.id+"."; 45 MatchingTag tag = new MatchingTag(key, tags.get(key)); 46 tag.addParams(keyMatcher, idPrefix+"k."); 47 boolean matchingTag = true; 48 if (c.valPattern != null) { 49 Matcher valMatcher = c.valPattern.matcher(tag.value); 50 if (valMatcher.matches()) { 51 tag.addParams(valMatcher, idPrefix+"v."); 52 } else { 53 matchingTag = false; 54 } 55 } 56 if (matchingTag) { 57 result.matchingTags.add(tag); 58 } 36 59 } 37 60 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/data/Source.java
r26917 r26918 5 5 6 6 public class Source { 7 public String name; 7 public final String name; 8 8 public final Collection<Rule> rules = new ArrayList<Rule>(); 9 10 public Source(String name) { 11 this.name = name; 12 } 9 13 } -
applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/io/SourcesReader.java
r26917 r26918 126 126 127 127 private Source parseSource() throws XMLStreamException { 128 Source source = new Source(); 128 Source source = new Source(parser.getAttributeValue(null, "name")); 129 129 while (parser.hasNext()) { 130 130 int event = parser.next(); … … 174 174 175 175 private Link parseLink() throws XMLStreamException { 176 Link link = new Link(); 177 link.name = parser.getAttributeValue(null, "name"); 178 link.url = parser.getAttributeValue(null, "href"); 176 Link link = new Link( 177 parser.getAttributeValue(null, "name"), 178 parser.getAttributeValue(null, "href") 179 ); 179 180 jumpToEnd(); 180 181 return link;
Note:
See TracChangeset
for help on using the changeset viewer.