| 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 | |
|
| 13 | |
|
| 14 | |
|
| 15 | 3 | public class ErrorsParser extends BaseParser { |
| 16 | |
|
| 17 | 3 | private final Map<Integer, String> errors=new HashMap<Integer, String>(); |
| 18 | |
|
| 19 | |
@Override |
| 20 | |
protected String getRootElementName() { |
| 21 | 3 | return "errors"; |
| 22 | |
} |
| 23 | |
|
| 24 | |
@Override |
| 25 | |
protected void handleDocument(Document doc) |
| 26 | |
throws SAXException, IOException { |
| 27 | |
|
| 28 | 3 | final NodeList nl=doc.getDocumentElement().getElementsByTagName("error"); |
| 29 | 93 | for(int i=0; i<nl.getLength(); i++) { |
| 30 | 90 | final Node n=nl.item(i); |
| 31 | 90 | errors.put(Integer.parseInt(getAttr(n, "code")), |
| 32 | |
getAttr(n, "message")); |
| 33 | |
} |
| 34 | 3 | } |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public Map<Integer, String> getErrors() { |
| 40 | 6 | return errors; |
| 41 | |
} |
| 42 | |
} |