src/main/java/de/blau/android/osm/Wiki.java
/**
     * Check if a specific language - page combination exists on the OSM wiki
     * 
     * @param context an Android Context
     * @param baseUrl the base url for the wiki
     * @param parser an XmlPullParser instance
     * @param page the page name
     * @param language the language
     * @return true if the page could be found
     * @throws IOException if anything goes wrong
     */
Check if a specific language - page combination exists on the OSM wiki


Check if a specific language - page combination exists on the OSM wiki
private static boolean checkLanguage(@NonNull final Context context, @NonNull String baseUrl, @NonNull final XmlPullParser parser, @NonNull String page,
            @NonNull String language) throws IOException {
        String wikiApiUrl = baseUrl + "w/api.php?action=query&prop=info&format=xml&titles=" + language.toUpperCase(Locale.US) + DOUBLE_COLON + page;
        try (InputStream is = Server.openConnection(context, new URL(wikiApiUrl))) {
            parser.setInput(is, null);
            int eventType;
            while ((eventType = parser.next()) != XmlPullParser.END_DOCUMENT) {
                String tagName = parser.getName();
                if (eventType == XmlPullParser.START_TAG && API_ELEMENT_PAGE.equals(tagName) && parser.getAttributeValue(null, API_ATTR_MISSING) != null) {
                    Log.d(DEBUG_TAG, "displayMapFeatures " + language + DOUBLE_COLON + page + " doesn't exist");
                    return false;
                }
            }
        } catch (final IOException | XmlPullParserException iox) {
            Log.e(DEBUG_TAG, "Parse wiki api " + iox.getMessage());
            throw new IOException(iox.getMessage());
        }
        return true;
    }
private static boolean checkLanguage ( @ NonNull final Context context , @ NonNull String baseUrl , @ NonNull final XmlPullParser parser , @ NonNull String page , @ NonNull String language ) throws IOException { String wikiApiUrl = baseUrl + "w/api.php?action=query&prop=info&format=xml&titles=" + language . toUpperCase ( Locale . US ) + DOUBLE_COLON + page ; try ( InputStream is = Server . openConnection ( context , new URL ( wikiApiUrl ) ) ) { parser . setInput ( is , null ) ; int eventType ; while ( ( eventType = parser . next ( ) ) != XmlPullParser . END_DOCUMENT ) { String tagName = parser . getName ( ) ; if ( eventType == XmlPullParser . START_TAG && API_ELEMENT_PAGE . equals ( tagName ) && parser . getAttributeValue ( null , API_ATTR_MISSING ) != null ) { Log . d ( DEBUG_TAG , "displayMapFeatures " + language + DOUBLE_COLON + page + " doesn't exist" ) ; return false ; } } } catch ( final IOException | XmlPullParserException iox ) { Log . e ( DEBUG_TAG , "Parse wiki api " + iox . getMessage ( ) ) ; throw new IOException ( iox . getMessage ( ) ) ; } return true ; }
Check if a specific language - page combination exists on the OSM wiki
Check if a specific language - page combination exists on the OSM wiki
// https://wiki.openstreetmap.org/w/api.php?action=query&titles=DE:Use_OpenStreetMap&prop=info&format=xml // see https://wiki.openstreetmap.org/w/api.php