| 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 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
@author |
| 15 |
|
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 9 |
Complexity Density: 0,39 |
|
| 16 |
|
public class BlogCategoriesDecorator extends ContentDecoratorSupport { |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
@param |
| 22 |
|
@param |
| 23 |
|
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 9 |
Complexity Density: 0,39 |
|
| 24 |
0
|
public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {... |
| 25 |
0
|
if (context.getMedia() == ContentDecoratorContext.HTML_PAGE) { |
| 26 |
0
|
Iterator categories = blogEntry.getCategories().iterator(); |
| 27 |
|
|
| 28 |
0
|
if (categories.hasNext()) { |
| 29 |
0
|
StringBuffer buf = new StringBuffer(); |
| 30 |
|
|
| 31 |
0
|
buf.append("<div class=\"categories\"><span>"); |
| 32 |
0
|
buf.append(I18n.getMessage(blogEntry.getBlog(), "category.categories")); |
| 33 |
0
|
buf.append(" : </span>"); |
| 34 |
0
|
while (categories.hasNext()) { |
| 35 |
0
|
Category category = (Category)categories.next(); |
| 36 |
0
|
buf.append("<a href=\""); |
| 37 |
0
|
buf.append(category.getPermalink()); |
| 38 |
0
|
buf.append("\">"); |
| 39 |
0
|
buf.append(category.getName()); |
| 40 |
0
|
buf.append("</a>"); |
| 41 |
|
|
| 42 |
0
|
if (categories.hasNext()) { |
| 43 |
0
|
buf.append(", "); |
| 44 |
|
} |
| 45 |
|
} |
| 46 |
0
|
buf.append("</div>"); |
| 47 |
|
|
| 48 |
|
|
| 49 |
0
|
String body = blogEntry.getBody(); |
| 50 |
0
|
if (body != null && body.trim().length() > 0) { |
| 51 |
0
|
blogEntry.setBody(body + buf.toString()); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
0
|
String excerpt = blogEntry.getExcerpt(); |
| 55 |
0
|
if (excerpt != null && excerpt.trim().length() > 0) { |
| 56 |
0
|
blogEntry.setExcerpt(excerpt + buf.toString()); |
| 57 |
|
} |
| 58 |
|
} |
| 59 |
|
} |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
} |