From: Hendrik <nh...@us...> - 2006-12-27 12:56:13
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/util In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv8155/src/games/stendhal/server/util Modified Files: WikipediaAccess.java Log Message: imlemented Runnable pattern and added javadoc Index: WikipediaAccess.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/util/WikipediaAccess.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** WikipediaAccess.java 27 Dec 2006 12:37:51 -0000 1.2 --- WikipediaAccess.java 27 Dec 2006 12:56:09 -0000 1.3 *************** *** 13,20 **** * Gets the first text paragraph from the specified Wikipedia article using * the MediaWiki bot api. * * @author hendrik */ ! public class WikipediaAccess extends DefaultHandler { private StringBuilder text = new StringBuilder(); /** used by the parser to detect the right tag */ --- 13,24 ---- * 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. * * @author hendrik */ ! public class WikipediaAccess extends DefaultHandler implements Runnable { ! private String title = null; private StringBuilder text = new StringBuilder(); /** used by the parser to detect the right tag */ *************** *** 24,27 **** --- 28,40 ---- private String error = null; + /** + * creates a new WikipeidaAccess + * + * @param title title of the page to access + */ + public WikipediaAccess(String title) { + this.title = title; + } + @Override public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) { *************** *** 94,98 **** * @throws Exception in case of an unexpected error */ ! public void parse(String title) throws Exception { try { // look it up using the Wikipedia API --- 107,111 ---- * @throws Exception in case of an unexpected error */ ! public void parse() throws Exception { try { // look it up using the Wikipedia API *************** *** 113,116 **** --- 126,137 ---- } + public void run() { + try { + parse(); + } catch (Exception e) { + // ignore as they are alread logged in the parse()-method itself + } + } + /** * Returns true when the xml response was completly parsed |