Class WikipediaAccess

java.lang.Object
org.xml.sax.helpers.DefaultHandler
games.stendhal.server.util.WikipediaAccess
All Implemented Interfaces:
Runnable, ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class WikipediaAccess extends DefaultHandler implements Runnable
Gets the first text paragraph from the specified Wikipedia article using the MediaWiki bot API. You can invoke the parser either inline using the method parse() or start it in a new thread. TODO: handle redirects (but take care, there might be two redirects that point to each other).
Author:
hendrik
  • Constructor Details

    • WikipediaAccess

      public WikipediaAccess(String title)
      Creates a new WikipeidaAccess.
      Parameters:
      title - title of the page to access
  • Method Details

    • startElement

      public void startElement(String namespaceURI, String lName, String qName, Attributes attrs)
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
    • characters

      public void characters(char[] ch, int start, int length) throws SAXException
      Specified by:
      characters in interface ContentHandler
      Overrides:
      characters in class DefaultHandler
      Throws:
      SAXException
    • getText

      public String getText()
      Returns the unparsed text.
      Returns:
      content
    • getError

      public String getError()
      Gets the last error message.
      Returns:
      error message or null in case no error occurred
    • getProcessedText

      public String getProcessedText()
      Returns the first paragraph of the specified article without wiki code.
      Returns:
      content
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • isFinished

      public boolean isFinished()
      Returns true when the XML response was completely parsed.
      Returns:
      true if the parsing was completed, false otherwise