Coverage Report - net.spy.digg.parsers.ErrorsParser
 
Classes in this File Line Coverage Branch Coverage Complexity
ErrorsParser
100%
9/9
100%
2/2
0
 
 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  
  * Parse a digg errors response.
 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  
          * Get the map of error IDs to names.
 38  
          */
 39  
         public Map<Integer, String> getErrors() {
 40  6
                 return errors;
 41  
         }
 42  
 }