Changeset 29521 in osm for applications/editors/josm/plugins
- Timestamp:
- 2013-04-21T11:25:17+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/wikipedia/src/org/wikipedia
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaAddNamesAction.java
r29511 r29521 10 10 import java.util.List; 11 11 import java.util.Locale; 12 import java.util.TreeMap;13 12 import org.openstreetmap.josm.Main; 14 13 import org.openstreetmap.josm.actions.JosmAction; 15 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.preferences.StringProperty; 16 16 import org.openstreetmap.josm.io.remotecontrol.AddTagsDialog; 17 import org.openstreetmap.josm.tools.LanguageInfo; 17 18 18 19 public class WikipediaAddNamesAction extends JosmAction { 20 21 final StringProperty wikipediaLang = new StringProperty("wikipedia.lang", LanguageInfo.getJOSMLocaleCode().substring(0, 2)); 19 22 20 23 public WikipediaAddNamesAction() { … … 26 29 @Override 27 30 public void actionPerformed(ActionEvent e) { 28 String[] parts = getWikipediaValue().split(":", 2);31 final WikipediaApp.WikipediaLangArticle wp = WikipediaApp.WikipediaLangArticle.parseTag("wikipedia", getWikipediaValue()); 29 32 List<String[]> tags = new ArrayList<String[]>(); 30 for (WikipediaApp.WikipediaLangArticle i : WikipediaApp.getInterwikiArticles( parts[0], parts[1])) {33 for (WikipediaApp.WikipediaLangArticle i : WikipediaApp.getInterwikiArticles(wp.lang, wp.article)) { 31 34 if (useWikipediaLangArticle(i)) { 32 35 tags.add(new String[]{"name:" + i.lang, i.article}); -
applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java
r29330 r29521 25 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 26 import org.openstreetmap.josm.data.osm.Tag; 27 import org.openstreetmap.josm.tools.Predicate; 27 28 import org.openstreetmap.josm.tools.Utils; 28 29 import org.openstreetmap.josm.tools.Utils.Function; … … 137 138 } 138 139 139 static Collection<String> getWikipediaArticles(String wikipediaLang, OsmPrimitive p) { 140 Collection<String> r = new ArrayList<String>(); 140 static Collection<String> getWikipediaArticles(final String wikipediaLang, OsmPrimitive p) { 141 141 final Map<String, String> tags = p.getKeys(); 142 // consider wikipedia=[lang]:* 143 final String wp = tags.get("wikipedia"); 144 if (wp != null && wp.startsWith("http")) { 145 //wikipedia=http... 146 final WikipediaLangArticle item = WikipediaLangArticle.parseFromUrl(wp); 147 if (item != null && wikipediaLang.equals(item.lang)) { 148 r.add(item.article.replace("_", " ")); 149 } 150 } else if (wp != null) { 151 //wikipedia=[lang]:[article] 152 String[] item = decodeURL(wp).split(":", 2); 153 if (item.length == 2 && wikipediaLang.equals(item[0])) { 154 r.add(item[1].replace("_", " ")); 155 } 156 } 157 // consider wikipedia:[lang]=* 158 final String wpLang = tags.get("wikipedia:" + wikipediaLang); 159 if (wpLang != null && wpLang.startsWith("http")) { 160 //wikipedia:[lang]=http... 161 final WikipediaLangArticle item = WikipediaLangArticle.parseFromUrl(wpLang); 162 if (wikipediaLang.equals(item.lang)) { 163 r.add(item.article.replace("_", " ")); 164 } 165 } else if (wpLang != null) { 166 //wikipedia:[lang]=[lang]:[article] 167 //wikipedia:[lang]=[article] 168 String[] item = decodeURL(wpLang).split(":", 2); 169 r.add(item[item.length == 2 ? 1 : 0].replace("_", " ")); 170 } 171 return r; 142 return Utils.transform(Utils.filter( 143 Arrays.asList( 144 WikipediaLangArticle.parseTag("wikipedia", tags.get("wikipedia")), 145 WikipediaLangArticle.parseTag("wikipedia:" + wikipediaLang, tags.get("wikipedia:" + wikipediaLang)) 146 ), new Predicate<WikipediaLangArticle>() { 147 @Override 148 public boolean evaluate(WikipediaLangArticle wp) { 149 return wp != null && wikipediaLang.equals(wp.lang); 150 } 151 }), new Function<WikipediaLangArticle, String>() { 152 @Override 153 public String apply(WikipediaLangArticle wp) { 154 return wp.article; 155 } 156 }); 172 157 } 173 158 … … 217 202 return new WikipediaLangArticle(m.group(1), m.group(2)); 218 203 } 204 205 public static WikipediaLangArticle parseTag(String key, String value) { 206 if (value == null) { 207 return null; 208 } else if (value.startsWith("http")) { 209 //wikipedia=http... 210 return parseFromUrl(value); 211 } else if (value.contains(":")) { 212 //wikipedia=[lang]:[article] 213 //wikipedia:[lang]=[lang]:[article] 214 final String[] item = decodeURL(value).split(":", 2); 215 final String article = item[1].replace("_", " "); 216 return new WikipediaLangArticle(item[0], article); 217 } else if (key.startsWith("wikipedia:")) { 218 //wikipedia:[lang]=[lang]:[article] 219 //wikipedia:[lang]=[article] 220 final String lang = key.split(":", 2)[1]; 221 final String[] item = decodeURL(value).split(":", 2); 222 final String article = item[item.length == 2 ? 1 : 0].replace("_", " "); 223 return new WikipediaLangArticle(lang, article); 224 } else { 225 return null; 226 } 227 } 219 228 } 220 229
Note:
See TracChangeset
for help on using the changeset viewer.