hideunapprovedresponsesdecorator.java

### File Source: hideunapprovedresponsesdecorator.java

             /*
        P/P   *  Method: net.sourceforge.pebble.decorator.HideUnapprovedResponsesDecorator__static_init
              */
         1  package net.sourceforge.pebble.decorator;
         2
         3  import net.sourceforge.pebble.domain.BlogEntry;
         4  import net.sourceforge.pebble.domain.Comment;
         5  import net.sourceforge.pebble.domain.TrackBack;
         6  import net.sourceforge.pebble.util.SecurityUtils;
         7  import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
         8
         9  import java.util.List;
        10
        11  /**
        12   * Hides unapproved responses (comments and TrackBacks) if the current user is
        13   * not a blog contributor.
        14   *
        15   * @author Simon Brown
        16   */
             /*
        P/P   *  Method: void net.sourceforge.pebble.decorator.HideUnapprovedResponsesDecorator()
              */
        17  public class HideUnapprovedResponsesDecorator extends ContentDecoratorSupport {
        18
        19    /**
        20     * Decorates the specified blog entry.
        21     *
        22     * @param context   the context in which the decoration is running
        23     * @param blogEntry the blog entry to be decorated
        24     */
        25    public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
                 /*
        P/P       *  Method: void decorate(ContentDecoratorContext, BlogEntry)
                  *
                  *  Preconditions:
                  *    blogEntry != null
                  *
                  *  Presumptions:
                  *    java.util.List:get(...)@29 != null
                  *    java.util.List:get(...)@37 != null
                  *    java.util.List:size(...)@28 >= -231+1
                  *    java.util.List:size(...)@36 >= -231+1
                  *
                  *  Test Vectors:
                  *    net.sourceforge.pebble.util.SecurityUtils:isUserAuthorisedForBlogAsBlogContributor(...)@26: {1}, {0}
                  *
                  *  Preconditions:
                  *    init'ed(blogEntry.blog)
                  *    (soft) blogEntry.comments != null
                  *    (soft) blogEntry.events != null
                  *    (soft) init'ed(blogEntry.eventsEnabled)
                  *    (soft) blogEntry.trackBacks != null
                  *    (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
                  *    (soft) net/sourceforge/pebble/domain/BlogEntry.log != null
                  *
                  *  Presumptions:
                  *    comment.date@30 != null
                  *    comment.state@29 != null
                  *    trackBack.date@38 != null
                  *    trackBack.state@37 != null
                  */
        26      if (!SecurityUtils.isUserAuthorisedForBlogAsBlogContributor(blogEntry.getBlog())) {
        27        List comments = blogEntry.getComments();
        28        for (int i = comments.size()-1; i >= 0; i--) {
        29          Comment comment = (Comment)comments.get(i);
        30          if (!comment.isApproved()) {
        31            blogEntry.removeComment(comment.getId());
        32          }
        33        }
        34
        35        List trackBacks = blogEntry.getTrackBacks();
        36        for (int i = trackBacks.size()-1; i >= 0; i--) {
        37          TrackBack trackBack = (TrackBack)trackBacks.get(i);
        38          if (!trackBack.isApproved()) {
        39            blogEntry.removeTrackBack(trackBack.getId());
        40          }
        41        }
        42      }
        43    }
        44
        45  }

SofCheck Inspector Build Version : 2.22510

hideunapprovedresponsesdecorator.java | 2010-Jun-25 19:40:32
hideunapprovedresponsesdecorator.class | 2010-Jul-19 20:23:40