Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart5.png 38% of files have more coverage
24   179   14   2,18
6   66   0,58   11
11     1,27  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ContentDecoratorChain       Line # 47 24 0% 14 24 41,5% 0.41463414
 
  (42)
 
1    /*
2    * Copyright (c) 2003-2006, 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    package net.sourceforge.pebble.decorator;
33   
34    import net.sourceforge.pebble.domain.*;
35    import net.sourceforge.pebble.api.decorator.ContentDecorator;
36    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
37   
38    import java.util.ArrayList;
39    import java.util.List;
40    import java.util.Iterator;
41   
42    /**
43    * Manages a list of content decorators at runtime.
44    *
45    * @author Simon Brown
46    */
 
47    public class ContentDecoratorChain implements ContentDecorator {
48   
49    /** the blog associated with this chain */
50    private Blog blog;
51   
52    /** the list of decorators */
53    private List<ContentDecorator> decorators = new ArrayList<ContentDecorator>();
54   
55    /**
56    * Creates a new chain.
57    */
 
58  1334 toggle public ContentDecoratorChain(Blog blog) {
59  1334 setBlog(blog);
60    }
61   
62    /**
63    * Adds a new decorator.
64    *
65    * @param decorator a ContentDecorator instance
66    */
 
67  9338 toggle public void add(ContentDecorator decorator) {
68  9338 decorators.add(decorator);
69    }
70   
71    /**
72    * Gets the list of decorators in use.
73    */
 
74  0 toggle public List getContentDecorators() {
75  0 return new ArrayList(decorators);
76    }
77   
78    /**
79    * Decorates the specified blog entry.
80    *
81    * @param context the context in which the decoration is running
82    * @param blogEntry the blog entry to be decorated
83    */
 
84  14 toggle public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
85  14 for (ContentDecorator decorator : decorators) {
86  98 decorator.decorate(context, blogEntry);
87    }
88   
89    // if the view is detail, decorate the comments and TrackBacks too
90  14 if (context.getView() == ContentDecoratorContext.DETAIL_VIEW) {
91  14 for (Comment comment : blogEntry.getComments()) {
92  4 decorate(context, comment);
93    }
94   
95  14 for (TrackBack trackBack : blogEntry.getTrackBacks()) {
96  0 decorate(context, trackBack);
97    }
98    }
99    }
100   
101    /**
102    * Decorates the specified comment.
103    *
104    * @param context the context in which the decoration is running
105    * @param comment the comment to be decorated
106    */
 
107  16 toggle public void decorate(ContentDecoratorContext context, Comment comment) {
108  16 for (ContentDecorator decorator : decorators) {
109  112 decorator.decorate(context, comment);
110    }
111    }
112   
113    /**
114    * Decorates the specified TrackBack.
115    *
116    * @param context the context in which the decoration is running
117    * @param trackBack the TrackBack to be decorated
118    */
 
119  0 toggle public void decorate(ContentDecoratorContext context, TrackBack trackBack) {
120  0 for (ContentDecorator decorator : decorators) {
121  0 decorator.decorate(context, trackBack);
122    }
123    }
124   
125    /**
126    * Decorates the specified static page.
127    *
128    * @param context the context in which the decoration is running
129    * @param staticPage the static page to be decorated
130    */
 
131  0 toggle public void decorate(ContentDecoratorContext context, StaticPage staticPage) {
132  0 for (ContentDecorator decorator : decorators) {
133  0 decorator.decorate(context, staticPage);
134    }
135    }
136   
137    /**
138    * Gets the blog to which this decorator is associated.
139    *
140    * @return a Blog instance
141    */
 
142  0 toggle public Blog getBlog() {
143  0 return this.blog;
144    }
145   
146    /**
147    * Sets the blog to which this decorator is associated.
148    *
149    * @param blog a Blog instance
150    */
 
151  1334 toggle public void setBlog(Blog blog) {
152  1334 this.blog = blog;
153    }
154   
155    /**
156    * Gets the list of content decorators.
157    *
158    * @return a List of ContentDecorator instances
159    */
 
160  0 toggle public List<ContentDecorator> getDecorators() {
161  0 return new ArrayList<ContentDecorator>(decorators);
162    }
163   
164    /**
165    * Decorates the specified blog entries.
166    *
167    * @param blogEntries a List of BlogEntry instances
168    */
 
169  0 toggle public static void decorate(ContentDecoratorContext context, List blogEntries) {
170  0 if (blogEntries != null) {
171  0 Iterator it = blogEntries.iterator();
172  0 while (it.hasNext()) {
173  0 BlogEntry blogEntry = (BlogEntry)it.next();
174  0 blogEntry.getBlog().getContentDecoratorChain().decorate(context, blogEntry);
175    }
176    }
177    }
178   
179    }