Package games.stendhal.server.util
Class WikipediaAccess
java.lang.Object
org.xml.sax.helpers.DefaultHandler
games.stendhal.server.util.WikipediaAccess
- All Implemented Interfaces:
Runnable
,ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
characters(char[] ch, int start, int length)
getError()
Gets the last error message.Returns the first paragraph of the specified article without wiki code.getText()
Returns the unparsed text.boolean
Returns true when the XML response was completely parsed.void
run()
void
startElement(String namespaceURI, String lName, String qName, Attributes attrs)
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
WikipediaAccess
Creates a new WikipeidaAccess.- Parameters:
title
- title of the page to access
-
-
Method Details
-
startElement
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
-
characters
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
getText
Returns the unparsed text.- Returns:
- content
-
getError
Gets the last error message.- Returns:
- error message or
null
in case no error occurred
-
getProcessedText
Returns the first paragraph of the specified article without wiki code.- Returns:
- content
-
run
public void run() -
isFinished
public boolean isFinished()Returns true when the XML response was completely parsed.- Returns:
- true if the parsing was completed, false otherwise
-