Coverage Report - net.sourceforge.pebble.index.ResponseIndexListener
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponseIndexListener
100%
29/29
N/A
1
 
 1  
 /*
 2  
  * Copyright (c) 2003-2011, Simon Brown
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions are met:
 7  
  *
 8  
  *   - Redistributions of source code must retain the above copyright
 9  
  *     notice, this list of conditions and the following disclaimer.
 10  
  *
 11  
  *   - Redistributions in binary form must reproduce the above copyright
 12  
  *     notice, this list of conditions and the following disclaimer in
 13  
  *     the documentation and/or other materials provided with the
 14  
  *     distribution.
 15  
  *
 16  
  *   - Neither the name of Pebble nor the names of its contributors may
 17  
  *     be used to endorse or promote products derived from this software
 18  
  *     without specific prior written permission.
 19  
  *
 20  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 21  
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22  
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23  
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 24  
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 25  
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 26  
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 28  
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 29  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 30  
  * POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package net.sourceforge.pebble.index;
 34  
 
 35  
 import net.sourceforge.pebble.domain.Comment;
 36  
 import net.sourceforge.pebble.domain.TrackBack;
 37  
 import net.sourceforge.pebble.api.event.comment.CommentEvent;
 38  
 import net.sourceforge.pebble.api.event.comment.CommentListener;
 39  
 import net.sourceforge.pebble.api.event.trackback.TrackBackEvent;
 40  
 import net.sourceforge.pebble.api.event.trackback.TrackBackListener;
 41  
 
 42  
 /**
 43  
  * Listens to comment/TrackBack events and keeps the response index up to date.
 44  
  *
 45  
  * @author    Simon Brown
 46  
  */
 47  5440
 public class ResponseIndexListener implements CommentListener, TrackBackListener {
 48  
 
 49  
   /**
 50  
    * Called when a comment has been added.
 51  
    *
 52  
    * @param event a CommentEvent instance
 53  
    */
 54  
   public void commentAdded(CommentEvent event) {
 55  156
     Comment comment = event.getComment();
 56  156
     comment.getBlogEntry().getBlog().getResponseIndex().index(comment);
 57  156
   }
 58  
 
 59  
   /**
 60  
    * Called when a comment has been removed.
 61  
    *
 62  
    * @param event a CommentEvent instance
 63  
    */
 64  
   public void commentRemoved(CommentEvent event) {
 65  32
     Comment comment = event.getComment();
 66  32
     comment.getBlogEntry().getBlog().getResponseIndex().unindex(comment);
 67  32
   }
 68  
 
 69  
   /**
 70  
    * Called when a comment has been approved.
 71  
    *
 72  
    * @param event a CommentEvent instance
 73  
    */
 74  
   public void commentApproved(CommentEvent event) {
 75  92
     Comment comment = event.getComment();
 76  92
     comment.getBlogEntry().getBlog().getResponseIndex().unindex(comment);
 77  92
     comment.getBlogEntry().getBlog().getResponseIndex().index(comment);
 78  92
   }
 79  
 
 80  
   /**
 81  
    * Called when a comment has been rejected.
 82  
    *
 83  
    * @param event a CommentEvent instance
 84  
    */
 85  
   public void commentRejected(CommentEvent event) {
 86  4
     Comment comment = event.getComment();
 87  4
     comment.getBlogEntry().getBlog().getResponseIndex().unindex(comment);
 88  4
     comment.getBlogEntry().getBlog().getResponseIndex().index(comment);
 89  4
   }
 90  
 
 91  
   /**
 92  
    * Called when a TrackBack has been added.
 93  
    *
 94  
    * @param event a TrackBackEvent instance
 95  
    */
 96  
   public void trackBackAdded(TrackBackEvent event) {
 97  28
     TrackBack trackBack = event.getTrackBack();
 98  28
     trackBack.getBlogEntry().getBlog().getResponseIndex().index(trackBack);
 99  28
   }
 100  
 
 101  
   /**
 102  
    * Called when a TrackBack has been removed.
 103  
    *
 104  
    * @param event a TrackBackEvent instance
 105  
    */
 106  
   public void trackBackRemoved(TrackBackEvent event) {
 107  16
     TrackBack trackBack = event.getTrackBack();
 108  16
     trackBack.getBlogEntry().getBlog().getResponseIndex().unindex(trackBack);
 109  16
   }
 110  
 
 111  
   /**
 112  
    * Called when a TrackBack has been approved.
 113  
    *
 114  
    * @param event a TrackBackEvent instance
 115  
    */
 116  
   public void trackBackApproved(TrackBackEvent event) {
 117  4
     TrackBack trackBack = event.getTrackBack();
 118  4
     trackBack.getBlogEntry().getBlog().getResponseIndex().unindex(trackBack);
 119  4
     trackBack.getBlogEntry().getBlog().getResponseIndex().index(trackBack);
 120  4
   }
 121  
 
 122  
   /**
 123  
    * Called when a TrackBack has been rejected.
 124  
    *
 125  
    * @param event a TrackBackEvent instance
 126  
    */
 127  
   public void trackBackRejected(TrackBackEvent event) {
 128  4
     TrackBack trackBack = event.getTrackBack();
 129  4
     trackBack.getBlogEntry().getBlog().getResponseIndex().unindex(trackBack);
 130  4
     trackBack.getBlogEntry().getBlog().getResponseIndex().index(trackBack);
 131  4
   }
 132  
 
 133  
 }