| 1 | |
package net.spy.digg.parsers; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.util.HashMap; |
| 5 | |
import java.util.Map; |
| 6 | |
|
| 7 | |
import org.w3c.dom.Document; |
| 8 | |
import org.w3c.dom.Node; |
| 9 | |
import org.w3c.dom.NodeList; |
| 10 | |
import org.xml.sax.SAXException; |
| 11 | |
|
| 12 | |
import net.spy.digg.User; |
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | 3 | public class UsersParser extends PagedItemParser<User> { |
| 19 | |
|
| 20 | 3 | private final Map<String, User> users=new HashMap<String, User>(); |
| 21 | |
|
| 22 | |
@Override |
| 23 | |
protected void handleDocument(Document doc) |
| 24 | |
throws SAXException, IOException { |
| 25 | 3 | parseCommonFields(doc); |
| 26 | |
|
| 27 | 3 | final NodeList nl=doc.getElementsByTagName("user"); |
| 28 | 6 | for(int i=0; i<nl.getLength(); i++) { |
| 29 | 3 | final Node n=nl.item(i); |
| 30 | 3 | final UserImpl u=new UserImpl(n); |
| 31 | 3 | users.put(u.getName(), u); |
| 32 | 3 | addItem(u); |
| 33 | |
} |
| 34 | 3 | } |
| 35 | |
|
| 36 | |
@Override |
| 37 | |
protected String getRootElementName() { |
| 38 | 3 | return "users"; |
| 39 | |
} |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public Map<String, User> getUsers() { |
| 45 | 6 | return users; |
| 46 | |
} |
| 47 | |
|
| 48 | |
} |