Changeset 30125 in osm for applications/editors


Ignore:
Timestamp:
2013-12-15T11:44:32+01:00 (11 years ago)
Author:
simon04
Message:

JOSM/wikipedia: add support for //X.wikipedia.org/wiki/Y URLs - fixes #josm9419

Location:
applications/editors/josm/plugins/wikipedia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaApp.java

    r30100 r30125  
    199199            url = decodeURL(url);
    200200            // extract Wikipedia language and
    201             final Matcher m = Pattern.compile("https?://(\\w*)\\.wikipedia\\.org/wiki/(.*)").matcher(url);
     201            final Matcher m = Pattern.compile("(https?:)?//(\\w*)\\.wikipedia\\.org/wiki/(.*)").matcher(url);
    202202            if (!m.matches()) {
    203203                return null;
    204204            }
    205             return new WikipediaLangArticle(m.group(1), m.group(2));
     205            return new WikipediaLangArticle(m.group(2), m.group(3));
    206206        }
    207207
  • applications/editors/josm/plugins/wikipedia/test/org/wikipedia/WikipediaAppTest.java

    r29621 r30125  
    22
    33import org.junit.Test;
     4import org.openstreetmap.josm.data.coor.LatLon;
     5import org.openstreetmap.josm.tools.Predicate;
     6import org.openstreetmap.josm.tools.Utils;
    47import org.wikipedia.WikipediaApp.WikipediaEntry;
    58import org.wikipedia.WikipediaApp.WikipediaLangArticle;
     
    710import java.util.Arrays;
    811import java.util.Collection;
     12import java.util.List;
    913
    1014import static org.hamcrest.CoreMatchers.is;
    1115import static org.hamcrest.CoreMatchers.nullValue;
    1216import static org.junit.Assert.assertThat;
     17import static org.junit.Assert.assertTrue;
    1318import static org.junit.matchers.JUnitMatchers.hasItem;
    1419
     
    4651        final WikipediaLangArticle actual = WikipediaLangArticle.parseFromUrl("http://de.wikipedia.org/wiki/Sternheim_%26_Emanuel");
    4752        assertThat(actual.article, is("Sternheim_&_Emanuel"));
     53        assertThat(actual.lang, is("de"));
     54    }
     55
     56    @Test
     57    public void testParseFromUrl4() {
     58        final WikipediaLangArticle actual = WikipediaLangArticle.parseFromUrl("//de.wikipedia.org/wiki/Reichstagsgeb%C3%A4ude");
     59        assertThat(actual.article, is("Reichstagsgebäude"));
    4860        assertThat(actual.lang, is("de"));
    4961    }
     
    103115    }
    104116
     117    @Test
     118    public void testFromCoordinates() throws Exception {
     119        final List<WikipediaEntry> entries = WikipediaApp.getEntriesFromCoordinates("de",
     120                new LatLon(52.5179786, 13.3753321), new LatLon(52.5192215, 13.3768705));
     121        assertTrue(Utils.exists(entries, new Predicate<WikipediaEntry>() {
     122            @Override
     123            public boolean evaluate(WikipediaEntry entry) {
     124                return "Deutscher Bundestag".equals(entry.wikipediaArticle) && "de".equals(entry.wikipediaLang);
     125            }
     126        }));
     127    }
    105128}
Note: See TracChangeset for help on using the changeset viewer.