Clover coverage report - Flock Flock - 0.7-dev
Coverage timestamp: Thu Jan 30 2003 01:35:37 EST
file stats: LOC: 151   Methods: 13
NCLOC: 120   Classes: 2
This license of Clover is provided to support the development of Flock only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
SubscriptionsTable.java 0% 0% 0% 0%
 1   
 package net.sf.flock.webapp.components;
 2   
 
 3   
 import java.net.URL;
 4   
 import java.util.ArrayList;
 5   
 import java.util.List;
 6   
 
 7   
 import net.sf.tapestry.ApplicationRuntimeException;
 8   
 import net.sf.tapestry.BaseComponent;
 9   
 import net.sf.tapestry.ComponentAddress;
 10   
 import net.sf.tapestry.IRender;
 11   
 import net.sf.tapestry.IRequestCycle;
 12   
 import net.sf.tapestry.RequestCycleException;
 13   
 import net.sf.tapestry.components.Block;
 14   
 import net.sf.tapestry.components.BlockRenderer;
 15   
 import net.sf.tapestry.contrib.table.model.ITableColumn;
 16   
 import net.sf.tapestry.contrib.table.model.ITableColumnModel;
 17   
 import net.sf.tapestry.contrib.table.model.ITableDataModel;
 18   
 import net.sf.tapestry.contrib.table.model.ITableModel;
 19   
 import net.sf.tapestry.contrib.table.model.ITableModelSource;
 20   
 import net.sf.tapestry.contrib.table.model.ITableSessionStateManager;
 21   
 import net.sf.tapestry.contrib.table.model.ognl.ExpressionTableColumn;
 22   
 import net.sf.tapestry.contrib.table.model.simple.SimpleListTableDataModel;
 23   
 import net.sf.tapestry.contrib.table.model.simple.SimpleTableColumn;
 24   
 import net.sf.tapestry.contrib.table.model.simple.SimpleTableColumnModel;
 25   
 import net.sf.tapestry.contrib.table.model.simple.SimpleTableSessionStateManager;
 26   
 import net.sf.tapestry.contrib.table.model.simple.SimpleTableState;
 27   
 import net.sf.tapestry.event.PageDetachListener;
 28   
 import net.sf.tapestry.event.PageEvent;
 29   
 import net.sf.flock.SubscriptionInfoI;
 30   
 import net.sf.flock.FlockResourceException;
 31   
 import net.sf.flock.webapp.FlockContext;
 32   
 import org.apache.log4j.LogManager;
 33   
 import org.apache.log4j.Logger;
 34   
 
 35   
 public class SubscriptionsTable extends BaseComponent implements PageDetachListener {
 36   
 
 37   
     private final static Logger LOGGER = LogManager.getLogger(SubscriptionsTable.class);
 38   
 
 39   
     private SubscriptionInfoI currentSubscription;
 40   
 
 41   
     private ITableSessionStateManager tableStateSessionManager;
 42   
 
 43  0
     public SubscriptionInfoI getCurrentSubscription() {
 44  0
         return currentSubscription;
 45   
     }
 46   
 
 47  0
     public void setCurrentSubscription(SubscriptionInfoI currentSubscription) {
 48  0
         this.currentSubscription = currentSubscription;
 49   
     }
 50   
 
 51   
     /**
 52   
      * @see net.sf.tapestry.AbstractComponent#finishLoad()
 53   
      */
 54  0
     protected void finishLoad() {
 55  0
         super.finishLoad();
 56  0
         this.getPage().addPageDetachListener(this);
 57   
     }
 58   
 
 59   
 
 60   
     /**
 61   
      * @see net.sf.tapestry.event.PageDetachListener#pageDetached(net.sf.tapestry.event.PageEvent)
 62   
      */
 63  0
     public void pageDetached(PageEvent evt) {
 64  0
         this.tableStateSessionManager = null;
 65   
     }
 66   
 
 67  0
     private void initTableSessionStateManager() {    
 68  0
         LOGGER.debug("initTableSessionStateManager");
 69  0
         ITableDataModel tableDataModel = this.createTableDataModel();
 70  0
         ITableColumnModel tableColumnModel = this.createTableColumnModel();
 71  0
         this.tableStateSessionManager =  new SimpleTableSessionStateManager(tableDataModel, tableColumnModel);
 72   
     }
 73   
 
 74  0
     private ITableColumnModel createTableColumnModel() {
 75  0
         final ComponentAddress componentAddress = new ComponentAddress(this);
 76  0
         return new SimpleTableColumnModel(
 77   
             new ITableColumn[] {
 78   
                 new BlockColumn(componentAddress, "Location", "blockLocation"),
 79   
                 new BlockColumn(componentAddress, "Title", "blockTitle"),
 80   
                 new ExpressionTableColumn("Category", "metaData.get(\"path\")", true),
 81   
                 new BlockColumn(componentAddress, "Action", "blockAction")
 82   
             }
 83   
         );
 84   
     }
 85   
 
 86  0
     private ITableDataModel createTableDataModel() {
 87  0
         try {
 88  0
             List feedList = new ArrayList(FlockContext.getSubscriptionManager().getSubscriptionInfos());
 89  0
             return new SimpleListTableDataModel(feedList);
 90   
         } catch (FlockResourceException e) {
 91  0
             throw new ApplicationRuntimeException(e);
 92   
         }
 93   
     }
 94   
 
 95  0
     public ITableModel getTableModel() {
 96  0
         if (this.tableStateSessionManager==null) {
 97  0
             this.initTableSessionStateManager();
 98   
         }
 99  0
         return this.tableStateSessionManager.recreateTableModel( new SimpleTableState() );
 100   
     }
 101   
     
 102  0
     public ITableSessionStateManager getTableSessionStateManager() {
 103  0
         LOGGER.debug("getTableSessionStateManager");
 104  0
         if (this.tableStateSessionManager==null) {
 105  0
             this.initTableSessionStateManager();
 106   
         }
 107  0
         return this.tableStateSessionManager;
 108   
     }
 109   
 
 110   
 
 111  0
     public void deleteFeed(IRequestCycle cycle) throws RequestCycleException {
 112  0
         URL location = (URL)cycle.getServiceParameters()[0];
 113  0
         LOGGER.info("Unsubscribe feed "+location);
 114  0
         try {
 115  0
             FlockContext.getSubscriptionManager().unsubscribe(location);
 116   
         } catch (FlockResourceException e) {
 117  0
             throw new ApplicationRuntimeException(e);
 118   
         }
 119   
     }
 120   
 
 121  0
     public void refreshFeed(IRequestCycle cycle) throws RequestCycleException {
 122  0
         URL location = (URL)cycle.getServiceParameters()[0];
 123  0
         LOGGER.info("Refresh feed "+location);
 124  0
         try {
 125  0
             FlockContext.getSubscriptionManager().refresh(location);
 126   
         } catch (FlockResourceException e) {
 127  0
             throw new ApplicationRuntimeException(e);
 128   
         }
 129   
     }
 130   
 
 131   
     private static class BlockColumn extends SimpleTableColumn {
 132   
         private String blockName;
 133   
         private ComponentAddress componentAddress;
 134   
 
 135  0
         public BlockColumn(ComponentAddress componentAddress, String title, String blockName) {
 136  0
             super(title, true);
 137  0
             this.blockName = blockName;
 138  0
             this.componentAddress = componentAddress;
 139   
         }
 140   
 
 141  0
         public IRender getValueRenderer(IRequestCycle cycle, ITableModelSource source, Object row) {
 142  0
             SubscriptionsTable comp = (SubscriptionsTable) componentAddress.findComponent(cycle);
 143  0
             comp.setCurrentSubscription((SubscriptionInfoI)row);
 144  0
             Block block = (Block) comp.getComponent(this.blockName);
 145  0
             return new BlockRenderer(block);
 146   
         }
 147   
         
 148   
     } 
 149   
 
 150   
 }
 151