Coverage Report - net.sf.tacos.components.SiteMapComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
SiteMapComponent
0% 
0% 
1,2
 
 1  
 /*
 2  
  * SiteMap.java
 3  
  */
 4  
 
 5  
 package net.sf.tacos.components;
 6  
 
 7  
 import java.util.List;
 8  
 import net.sf.tacos.services.CategoryInfo;
 9  
 import net.sf.tacos.services.SiteMap;
 10  
 import org.apache.tapestry.BaseComponent;
 11  
 
 12  
 /**
 13  
  * Useful methods for generating a site map.
 14  
  * @author andyhot
 15  
  */
 16  0
 public abstract class SiteMapComponent extends BaseComponent
 17  
 {
 18  
     public abstract SiteMap getSiteMap();
 19  
     public abstract String getName();
 20  
     public abstract String getCategory();    
 21  
     
 22  
     public abstract boolean getShowAll();
 23  
     public abstract boolean getIgnoreCurrentPage();
 24  
     
 25  
     /**
 26  
      * If the sitemap should be shown.
 27  
      */ 
 28  
     public boolean getShowSiteMap()
 29  
     {
 30  0
         return getIgnoreCurrentPage() 
 31  
             || (getCurrentPageCategory() != null);
 32  
     }
 33  
     
 34  
     /**
 35  
      * The category where the given page belongs.
 36  
      */ 
 37  
     public CategoryInfo getCategoryOf(String page)
 38  
     {
 39  0
         return getSiteMap().getCategoryFromPage(page);
 40  
     }
 41  
     
 42  
     /**
 43  
      * The category of the currently displaying page.
 44  
      */ 
 45  
     public CategoryInfo getCurrentPageCategory()
 46  
     {
 47  0
         return getCategoryOf(getPage().getPageName());
 48  
     }
 49  
     
 50  
     /**
 51  
      * If the given page is part of the currently rendering category.
 52  
      */ 
 53  
     public boolean isPageInCategory(String page)
 54  
     {
 55  0
         return getSiteMap().inCategory(page, getCategory());
 56  
     }
 57  
     
 58  
     /**
 59  
      * If the currently displaying page is part of the currently rendering category.
 60  
      */     
 61  
     public boolean isCurrentPageInCategory()
 62  
     {
 63  0
         return isPageInCategory(getPage().getPageName());
 64  
     }    
 65  
     
 66  
     /**
 67  
      * The default page for the currently rendering category.
 68  
      */      
 69  
     public String getDefaultPage()
 70  
     {
 71  0
         return getSiteMap().getDefaultPage(getCategory()).getName();
 72  
     }
 73  
     
 74  
     /**
 75  
      * The css class to be applied for the currently rendering category.
 76  
      * It is 'current' if the category in question contains the displaying page.
 77  
      */      
 78  
     public String getCategoryClass()
 79  
     {
 80  0
         return isCurrentPageInCategory() ? "current" : null;
 81  
     }
 82  
     
 83  
     /**
 84  
      * The display name for the currently rendering category.
 85  
      */ 
 86  
     public String getCategoryDisplayName()
 87  
     {
 88  0
         if (getShowAll())
 89  0
             return getSiteMap().getCategoryInfo(getCategory()).getName();
 90  
         else
 91  0
             return getSiteMap().getDefaultPageDesc(getCategory());
 92  
     }
 93  
     
 94  
     /**
 95  
      * The display name for the currently rendering page.
 96  
      */     
 97  
     public String getPageDisplayName()
 98  
     {
 99  0
         return getSiteMap().getPageInfo(getName()).getDesc();
 100  
     }    
 101  
     
 102  
     /**
 103  
      * Gets the pages that belong to the same category as the given one.
 104  
      */      
 105  
     public List getPagesOfCategoryOfPage(String page)
 106  
     {
 107  0
         return getSiteMap().getCategoryPages(page);
 108  
     }
 109  
     
 110  
     /**
 111  
      * Gets the pages that belong to the same category as the currently displaying one.
 112  
      */     
 113  
     public List getPagesOfCategoryOfCurrentPage()
 114  
     {
 115  0
         return getPagesOfCategoryOfPage(getPage().getPageName());
 116  
     } 
 117  
     
 118  
     /**
 119  
      * Gets the pages of the given category.
 120  
      */     
 121  
     public List getPagesOfCategory(String category)
 122  
     {
 123  0
         return getSiteMap().getCategoryInfo(category).getPageNames();
 124  
     }     
 125  
     
 126  
     /**
 127  
      * Gets the pages of the currently rendering category.
 128  
      */     
 129  
     public List getPagesOfCurrentCategory()
 130  
     {
 131  0
         return getPagesOfCategory(getCategory());
 132  
     }     
 133  
     
 134  
     public boolean getShowPage()
 135  
     {
 136  0
         if (getShowAll())
 137  0
             return true;
 138  
         else
 139  0
             return !getName().equals( getCategoryOf(getPage().getPageName()).getDefaultPage() );
 140  
     }
 141  
     
 142  
     /**
 143  
      * The css class to be applied for the currently rendering page.
 144  
      * It is 'here' if the page in question is in fact the one currently displayed.
 145  
      */    
 146  
     public String getPageClass()
 147  
     {
 148  0
         String name = getName();
 149  0
         String pageName = getPage().getPageName();
 150  
         
 151  0
         boolean selected = name.equals(pageName) 
 152  
             || getSiteMap().contains(name, pageName);
 153  0
         return selected ? "here" : null;
 154  
     }
 155  
 }