Coverage Report - net.spy.digg.parsers.TopicsParser
 
Classes in this File Line Coverage Branch Coverage Complexity
TopicsParser
100%
24/24
75%
12/16
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  
 import net.spy.digg.TopicContainer;
 13  
 
 14  
 
 15  
 /**
 16  
  * Parse the topics.
 17  
  */
 18  6
 public class TopicsParser extends BaseParser {
 19  
 
 20  3
         private final Map<String, TopicContainer> containers
 21  
                 =new HashMap<String, TopicContainer>();
 22  
 
 23  
         @Override
 24  
         protected String getRootElementName() {
 25  3
                 return "topics";
 26  
         }
 27  
 
 28  
         @Override
 29  
         protected void handleDocument(Document doc)
 30  
                 throws SAXException, IOException {
 31  
 
 32  
                 // Build out the topics.
 33  3
                 final NodeList nl=doc.getDocumentElement().getElementsByTagName("topic");
 34  138
                 for(int i=0; i<nl.getLength(); i++) {
 35  135
                         final Node n=nl.item(i);
 36  135
                         final String name=getAttr(n, "name");
 37  135
                         final String shortName=getAttr(n, "short_name");
 38  
 
 39  135
                         final NodeList nlTmp=n.getChildNodes();
 40  135
                         Node cn=null;
 41  540
                         for(int j=0; j<nlTmp.getLength(); j++) {
 42  405
                                 if(nlTmp.item(j).getNodeName().equals("container")) {
 43  135
                                         cn=nlTmp.item(j);
 44  
                                 }
 45  
                         }
 46  135
                         assert cn != null : "Couldn't find a container";
 47  
                         assert cn.getNodeName().equals("container")
 48  135
                                 : "Expected container, got " + cn.getNodeName();
 49  135
                         final String cname=getAttr(cn, "name");
 50  135
                         final String cshortName=getAttr(cn, "short_name");
 51  
 
 52  135
                         TopicContainer tc=containers.get(cshortName);
 53  135
                         if(tc == null) {
 54  21
                                 tc=new TopicContainerImpl(cname, cshortName);
 55  21
                                 containers.put(cshortName, tc);
 56  
                         }
 57  135
                         tc.add(new TopicImpl(name, shortName));
 58  
                 }
 59  3
         }
 60  
 
 61  
         /**
 62  
          * Get a map of all topic containers by short name.
 63  
          */
 64  
         public Map<String, TopicContainer> getContainers() {
 65  9
                 return containers;
 66  
         }
 67  
 }