| 1 | |
package net.spy.digg.parsers; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
|
| 5 | |
import org.w3c.dom.Document; |
| 6 | |
import org.w3c.dom.Node; |
| 7 | |
import org.w3c.dom.NodeList; |
| 8 | |
import org.xml.sax.SAXException; |
| 9 | |
|
| 10 | |
import net.spy.digg.Event; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | 15 | public class EventsParser extends TimePagedItemParser<Event> { |
| 16 | |
|
| 17 | |
@Override |
| 18 | |
protected String getRootElementName() { |
| 19 | 12 | return "events"; |
| 20 | |
} |
| 21 | |
|
| 22 | |
@Override |
| 23 | |
protected void handleDocument(Document doc) |
| 24 | |
throws SAXException, IOException { |
| 25 | 12 | parseCommonFields(doc); |
| 26 | |
|
| 27 | 12 | final NodeList nl=doc.getFirstChild().getChildNodes(); |
| 28 | 324 | for(int i=0; i<nl.getLength(); i++) { |
| 29 | 312 | final Node n=nl.item(i); |
| 30 | 312 | final String nm=n.getNodeName(); |
| 31 | 312 | if(nm.equals("digg")) { |
| 32 | 30 | addItem(new EventImpl(n)); |
| 33 | 282 | } else if(nm.equals("comment")) { |
| 34 | 120 | addItem(new CommentImpl(n)); |
| 35 | 162 | } else if(n.getNodeType() == Node.TEXT_NODE) { |
| 36 | |
|
| 37 | |
} else { |
| 38 | 0 | assert false : "Unhandled node: " + n; |
| 39 | |
} |
| 40 | |
} |
| 41 | 12 | } |
| 42 | |
|
| 43 | |
} |