File Source: tagindexlistener.java

     1  package net.sourceforge.pebble.index;
     2  
     3  import net.sourceforge.pebble.api.event.blogentry.BlogEntryListener;
     4  import net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent;
     5  import net.sourceforge.pebble.domain.BlogEntry;
     6  
     7  import java.util.Iterator;
     8  import java.util.List;
     9  import java.beans.PropertyChangeEvent;
    10  
    11  public class TagIndexListener implements BlogEntryListener {
    12  
    13    /**
    14     * Called when a blog entry has been added.
    15     *
    16     * @param event a BlogEntryEvent instance
    17     */
    18    public void blogEntryAdded(BlogEntryEvent event) {
             /* 
    P/P       *  Method: void blogEntryAdded(BlogEntryEvent)
              * 
              *  Preconditions:
              *    event != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name != null
              * 
              *  Presumptions:
              *    blogEntry.blog@20 != null
              *    blogEntry.blog.rootCategory@20 != null
              *    blogEntry.state@19 != null
              *    blogEntry.state@20 != null
              *    blogEntry.tagsAsList@20 != null
              *    ...
              */
    19      BlogEntry blogEntry = event.getBlogEntry();
    20      if (blogEntry.isPublished()) {
    21        blogEntry.getBlog().getTagIndex().index(blogEntry);
    22      }
    23    }
    24  
    25    /**
    26     * Called when a blog entry has been removed.
    27     *
    28     * @param event a BlogEntryEvent instance
    29     */
    30    public void blogEntryRemoved(BlogEntryEvent event) {
             /* 
    P/P       *  Method: void blogEntryRemoved(BlogEntryEvent)
              * 
              *  Preconditions:
              *    event != null
              * 
              *  Presumptions:
              *    blogEntry.blog@31 != null
              *    net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent:getSource(...)@91 != null
              *    getBlog(...).tagIndex@31 != null
              *    getTagIndex(...).blog@31 != null
              *    getTagIndex(...).tags@31 != null
              */
    31      BlogEntry blogEntry = event.getBlogEntry();
    32      blogEntry.getBlog().getTagIndex().unindex(blogEntry);
    33    }
    34  
    35    /**
    36     * Called when a blog entry has been changed.
    37     *
    38     * @param event a BlogEntryEvent instance
    39     */
    40    public void blogEntryChanged(BlogEntryEvent event) {
             /* 
    P/P       *  Method: void blogEntryChanged(BlogEntryEvent)
              * 
              *  Preconditions:
              *    event != null
              *    (soft) event.propertyChangeEvents != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name != null
              * 
              *  Presumptions:
              *    blogEntry.blog@43 != null
              *    blogEntry.blog@52 != null
              *    blogEntry.state@41 != null
              *    blogEntry.state@52 != null
              *    blogEntry.tagsAsList@52 != null
              *    ...
              * 
              *  Test Vectors:
              *    java.lang.String:equals(...)@51: {1}, {0}
              *    java.lang.String:equals(...)@51: {0}, {1}
              *    java.util.Iterator:hasNext(...)@46: {1}, {0}
              */
    41      BlogEntry blogEntry = event.getBlogEntry();
    42  
    43      if (blogEntry.isPublished()) {
    44        List propertyChangeEvents = event.getPropertyChangeEvents();
    45        Iterator it = propertyChangeEvents.iterator();
    46        while (it.hasNext()) {
    47          PropertyChangeEvent pce = (PropertyChangeEvent)it.next();
    48          String property = pce.getPropertyName();
    49  
    50          // only if the tags or categories change do we need to reindex the tags
    51          if (property.equals(BlogEntry.TAGS_PROPERTY) || property.equals(BlogEntry.CATEGORIES_PROPERTY)) {
    52            blogEntry.getBlog().getTagIndex().unindex(blogEntry);
    53            blogEntry.getBlog().getTagIndex().index(blogEntry);
    54          }
    55        }
    56      }
    57    }
    58  
    59    /**
    60     * Called when a blog entry has been published.
    61     *
    62     * @param event a BlogEntryEvent instance
    63     */
    64    public void blogEntryPublished(BlogEntryEvent event) {
             /* 
    P/P       *  Method: void blogEntryPublished(BlogEntryEvent)
              * 
              *  Preconditions:
              *    event != null
              *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#5).name != null
              * 
              *  Presumptions:
              *    blogEntry.blog@65 != null
              *    blogEntry.state@65 != null
              *    blogEntry.tagsAsList@65 != null
              *    net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent:getSource(...)@91 != null
              *    blogEntry.blog.rootCategory@65 != null
              *    ...
              */
    65      BlogEntry blogEntry = event.getBlogEntry();
    66      blogEntry.getBlog().getTagIndex().index(blogEntry);
    67    }
    68  
    69    /**
    70     * Called when a blog entry has been unpublished.
    71     *
    72     * @param event a BlogEntryEvent instance
    73     */
    74    public void blogEntryUnpublished(BlogEntryEvent event) {
             /* 
    P/P       *  Method: void blogEntryUnpublished(BlogEntryEvent)
              * 
              *  Preconditions:
              *    event != null
              * 
              *  Presumptions:
              *    blogEntry.blog@75 != null
              *    net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent:getSource(...)@91 != null
              *    getBlog(...).tagIndex@75 != null
              *    getTagIndex(...).blog@75 != null
              *    getTagIndex(...).tags@75 != null
              */
    75      BlogEntry blogEntry = event.getBlogEntry();
    76      blogEntry.getBlog().getTagIndex().unindex(blogEntry);
    77    }
    78  
    79  }








SofCheck Inspector Build Version : 2.22510
tagindexlistener.java 2010-Jun-25 19:40:32
tagindexlistener.class 2010-Jul-19 20:23:38