Coverage Report - net.sf.statcvs.pages.xml.DirectoriesXml
 
Classes in this File Line Coverage Branch Coverage Complexity
DirectoriesXml
0%
0/30
0%
0/4
1.667
 
 1  
 package net.sf.statcvs.pages.xml;
 2  
 
 3  
 /**
 4  
  * @author Nilendra Weerasinghe (nilendraw@gmail.com)
 5  
  * @version $Id: DirectoriesXml.java,v 1.2 2008/04/02 11:22:16 benoitx Exp $
 6  
  *
 7  
  * This is the class which generates the per directory information of the xml report
 8  
  */
 9  
 
 10  
 import java.util.Iterator;
 11  
 import java.util.SortedSet;
 12  
 import java.util.Stack;
 13  
 
 14  
 import net.sf.statcvs.model.Directory;
 15  
 import net.sf.statcvs.model.Repository;
 16  
 import net.sf.statcvs.output.ReportConfig;
 17  
 
 18  
 import org.jdom.Element;
 19  
 
 20  
 public class DirectoriesXml {
 21  
     private final SortedSet directory;
 22  
     private final Repository repository;
 23  
 
 24  
     /**
 25  
      * @param config Configuration and data for the report suite
 26  
      */
 27  0
     public DirectoriesXml(final ReportConfig config) {
 28  0
         this.repository = config.getRepository();
 29  0
         directory = this.repository.getDirectories();
 30  0
     }
 31  
 
 32  
     /**
 33  
      * returns jdom element which contains data extracted from the SortedSet of directories
 34  
      *
 35  
      * @returns Element
 36  
      */
 37  
     public Element toFile() {
 38  0
         final Element dir = new Element(XmlTags.TAG_DIRECTORIES);
 39  0
         final Iterator it = this.directory.iterator();
 40  
 
 41  
         //        int depth = -1;
 42  0
         final Element parent = dir;
 43  0
         final Stack stack = new Stack();
 44  0
         stack.add(dir);
 45  0
         while (it.hasNext()) {
 46  0
             final Directory direc = (Directory) it.next();
 47  0
             final Element item = format(direc, 0);
 48  
 
 49  
             //            if (direc.getDepth() < depth) {
 50  
             //                int toReach = depth - direc.getDepth();
 51  
             //                while (toReach-- > 0) {
 52  
             //                    parent = (Element) stack.pop();
 53  
             //                }
 54  
             //            } else if (direc.getDepth() == depth) {
 55  
             //                parent = (Element) stack.pop();
 56  
             //            }
 57  
             //            System.err.println("Directory depth " + direc.getDepth() + " " + depth + " " + getFormattedName(direc) + " " + parent.getName());
 58  
 
 59  0
             parent.addContent(item);
 60  
             //            if (direc.getDepth() >= depth) {
 61  
             //                stack.push(parent);
 62  
             //                parent = item;
 63  
             //            }
 64  
             //            depth = direc.getDepth();
 65  0
         }
 66  
 
 67  0
         return dir;
 68  
     }
 69  
 
 70  
     /**
 71  
      * returns jdom element properly formatted with the attributes and child elements
 72  
      *
 73  
      * @param Directory the current directory
 74  
      * @param int the depth of the directory
 75  
      */
 76  
     private Element format(final Directory dir, final int currentDepth) {
 77  0
         final Element element = new Element(XmlTags.TAG_DIRECTORY);
 78  0
         final Element path = new Element(XmlTags.TAG_PATH);
 79  
         //        path.setText(getFormattedName(dir));
 80  0
         path.setText(dir.getPath());
 81  0
         if (dir.isEmpty()) {
 82  0
             element.setAttribute("status", "deleted");
 83  
         }
 84  0
         final Element child1 = new Element(XmlTags.TAG_FILES);
 85  0
         final String str = Integer.toString(dir.getCurrentFileCount());
 86  0
         child1.setText(str);
 87  0
         final Element child2 = new Element(XmlTags.TAG_LINES_CHANGED);
 88  0
         final String str2 = Integer.toString(dir.getCurrentLOC());
 89  0
         child2.setText(str2);
 90  0
         element.addContent(path);
 91  0
         element.addContent(child1);
 92  0
         element.addContent(child2);
 93  0
         return element;
 94  
     }
 95  
 }