File Source: blogcategoriesdecorator.java

         /* 
    P/P   *  Method: net.sourceforge.pebble.decorator.BlogCategoriesDecorator__static_init
          */
     1  package net.sourceforge.pebble.decorator;
     2  
     3  import java.util.Iterator;
     4  
     5  import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
     6  import net.sourceforge.pebble.domain.BlogEntry;
     7  import net.sourceforge.pebble.domain.Category;
     8  import net.sourceforge.pebble.util.I18n;
     9  
    10  /**
    11   * Generates category links for inclusion in the body of blog entries,
    12   * when rendered as HTML.
    13   * 
    14   * @author Simon Brown
    15   */
         /* 
    P/P   *  Method: void net.sourceforge.pebble.decorator.BlogCategoriesDecorator()
          */
    16  public class BlogCategoriesDecorator extends ContentDecoratorSupport {
    17  
    18    /**
    19     * Decorates the specified blog entry.
    20     *
    21     * @param context   the context in which the decoration is running
    22     * @param blogEntry the blog entry to be decorated
    23     */
    24    public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
           /* 
    P/P     *  Method: void decorate(ContentDecoratorContext, BlogEntry)
            * 
            *  Preconditions:
            *    context != null
            *    (soft) blogEntry != null
            * 
            *  Presumptions:
            *    java.util.Iterator:next(...)@35 != null
            * 
            *  Test Vectors:
            *    java.lang.String:length(...)@50: {0}, {1..232-1}
            *    java.lang.String:length(...)@55: {0}, {1..232-1}
            *    java.util.Iterator:hasNext(...)@28: {0}, {1}
            *    java.util.Iterator:hasNext(...)@34: {1}, {0}
            *    java.util.Iterator:hasNext(...)@42: {0}, {1}
            * 
            *  Preconditions:
            *    init'ed(context.media)
            *    (soft) init'ed(blogEntry.blog)
            *    (soft) init'ed(blogEntry.categories)
            *    (soft) blogEntry.propertyChangeSupport != null
            *    (soft) init'ed(blogEntry.body)
            *    (soft) init'ed(blogEntry.excerpt)
            * 
            *  Presumptions:
            *    category.blog@35 != null
            *    category.id@35 != null
            * 
            *  Postconditions:
            *    init'ed(blogEntry.body)
            *    init'ed(blogEntry.excerpt)
            * 
            *  Preconditions:
            *    (soft) net/sourceforge/pebble/domain/BlogManager.instance != null
            *    (soft) init'ed(net/sourceforge/pebble/domain/BlogManager.instance.multiBlog)
            * 
            *  Test Vectors:
            *    context.media: {-231..-1, 1..232-1}, {0}
            *    blogEntry.body: Addr_Set{null}, Inverse{null}
            *    blogEntry.excerpt: Addr_Set{null}, Inverse{null}
            */
    25    if (context.getMedia() == ContentDecoratorContext.HTML_PAGE) {
    26        Iterator categories = blogEntry.getCategories().iterator();
    27  
    28        if (categories.hasNext()) {
    29          StringBuffer buf = new StringBuffer();
    30  
    31          buf.append("<div class=\"categories\"><span>");
    32          buf.append(I18n.getMessage(blogEntry.getBlog(), "category.categories"));
    33          buf.append(" : </span>");
    34          while (categories.hasNext()) {
    35            Category category = (Category)categories.next();
    36            buf.append("<a href=\"");
    37            buf.append(category.getPermalink());
    38            buf.append("\">");
    39            buf.append(category.getName());
    40            buf.append("</a>");
    41  
    42            if (categories.hasNext()) {
    43              buf.append(", ");
    44            }
    45          }
    46          buf.append("</div>");
    47  
    48          // now add the HTML to the body and excerpt, if they aren't empty
    49          String body = blogEntry.getBody();
    50          if (body != null && body.trim().length() > 0) {
    51            blogEntry.setBody(body + buf.toString());
    52          }
    53  
    54          String excerpt = blogEntry.getExcerpt();
    55          if (excerpt != null && excerpt.trim().length() > 0) {
    56            blogEntry.setExcerpt(excerpt + buf.toString());
    57          }
    58        }
    59      }
    60    }
    61  
    62  }








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