Class Mediawiki


  • public class Mediawiki
    extends java.lang.Object
    Interaction with Mediawiki instances, such as the OSM wiki.
    Since:
    14641
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String baseUrl  
    • Constructor Summary

      Constructors 
      Constructor Description
      Mediawiki​(java.lang.String baseUrl)
      Constructs a new Mediawiki for the given base URL.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<java.lang.String> findExistingPage​(java.util.List<java.lang.String> pages)
      Determines which page exists on the Mediawiki instance.
      private static org.w3c.dom.Document getDocument​(java.net.URL url)  
      static java.lang.String getGeoImagesUrl​(java.lang.String baseUrl, Bounds bounds)
      Returns the URL for searching geolocated images in given bounds.
      static java.lang.String getImageUrl​(java.lang.String fileBaseUrl, java.lang.String filename)
      Computes the URL for the given filename on the MediaWiki server
      void searchGeoImages​(Bounds bounds, java.util.function.BiConsumer<java.lang.String,​LatLon> imageConsumer)
      Searches geocoded images from Wikimedia Commons for the given bounding box.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • baseUrl

        private final java.lang.String baseUrl
    • Constructor Detail

      • Mediawiki

        public Mediawiki​(java.lang.String baseUrl)
        Constructs a new Mediawiki for the given base URL.
        Parameters:
        baseUrl - The wiki base URL
    • Method Detail

      • findExistingPage

        public java.util.Optional<java.lang.String> findExistingPage​(java.util.List<java.lang.String> pages)
                                                              throws java.io.IOException,
                                                                     javax.xml.parsers.ParserConfigurationException,
                                                                     org.xml.sax.SAXException,
                                                                     javax.xml.xpath.XPathExpressionException
        Determines which page exists on the Mediawiki instance.
        Parameters:
        pages - the pages to check
        Returns:
        the first existing page
        Throws:
        java.io.IOException - if any I/O error occurs
        javax.xml.parsers.ParserConfigurationException - if a parser cannot be created
        org.xml.sax.SAXException - if any XML error occurs
        javax.xml.xpath.XPathExpressionException - if any error in an XPath expression occurs
      • getDocument

        private static org.w3c.dom.Document getDocument​(java.net.URL url)
                                                 throws java.io.IOException,
                                                        javax.xml.parsers.ParserConfigurationException,
                                                        org.xml.sax.SAXException
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • searchGeoImages

        public void searchGeoImages​(Bounds bounds,
                                    java.util.function.BiConsumer<java.lang.String,​LatLon> imageConsumer)
                             throws java.io.IOException,
                                    javax.xml.parsers.ParserConfigurationException,
                                    org.xml.sax.SAXException,
                                    javax.xml.xpath.XPathExpressionException
        Searches geocoded images from Wikimedia Commons for the given bounding box.
        Parameters:
        bounds - the bounds to load
        imageConsumer - a consumer to receive the file title and the coordinates for every geocoded image
        Throws:
        java.io.IOException - if any I/O error occurs
        javax.xml.parsers.ParserConfigurationException - if a parser cannot be created
        org.xml.sax.SAXException - if any XML error occurs
        javax.xml.xpath.XPathExpressionException - if any error in an XPath expression occurs
      • getGeoImagesUrl

        public static java.lang.String getGeoImagesUrl​(java.lang.String baseUrl,
                                                       Bounds bounds)
        Returns the URL for searching geolocated images in given bounds.
        Parameters:
        baseUrl - The wiki base URL
        bounds - the bounds of the search area
        Returns:
        the URL for searching geolocated images in given bounds
        Since:
        18046
      • getImageUrl

        public static java.lang.String getImageUrl​(java.lang.String fileBaseUrl,
                                                   java.lang.String filename)
        Computes the URL for the given filename on the MediaWiki server
        Parameters:
        fileBaseUrl - the base URL of the file MediaWiki storage, such as "https://upload.wikimedia.org/wikipedia/commons/"
        filename - the filename
        Returns:
        the URL for the given filename on the MediaWiki server
        See Also:
        MediaWiki $wgHashedUploadDirectory