File Source: contentdecoratorchain.java
/*
P/P * Method: net.sourceforge.pebble.decorator.ContentDecoratorChain__static_init
*/
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 */
/*
P/P * Method: void net.sourceforge.pebble.decorator.ContentDecoratorChain(Blog)
*
* Postconditions:
* this.blog == blog
* init'ed(this.blog)
* this.decorators == &new ArrayList(ContentDecoratorChain#1)
* new ArrayList(ContentDecoratorChain#1) num objects == 1
*/
58 public ContentDecoratorChain(Blog blog) {
59 setBlog(blog);
60 }
61
62 /**
63 * Adds a new decorator.
64 *
65 * @param decorator a ContentDecorator instance
66 */
67 public void add(ContentDecorator decorator) {
/*
P/P * Method: void add(ContentDecorator)
*
* Preconditions:
* this.decorators != null
*/
68 decorators.add(decorator);
69 }
70
71 /**
72 * Gets the list of decorators in use.
73 */
74 public List getContentDecorators() {
/*
P/P * Method: List getContentDecorators()
*
* Preconditions:
* init'ed(this.decorators)
*
* Postconditions:
* return_value == &new ArrayList(getContentDecorators#1)
* new ArrayList(getContentDecorators#1) num objects == 1
*/
75 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 public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
/*
P/P * Method: void decorate(ContentDecoratorContext, BlogEntry)
*
* Preconditions:
* context != null
* this.decorators != null
* (soft) blogEntry != null
*
* Presumptions:
* java.util.Iterator:next(...)@85 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@85: {1}, {0}
* java.util.Iterator:hasNext(...)@91: {1}, {0}
* java.util.Iterator:hasNext(...)@95: {1}, {0}
*
* Preconditions:
* (soft) blogEntry.comments != null
* (soft) init'ed(blogEntry.trackBacks)
* (soft) init'ed(context.view)
*
* Presumptions:
* blogEntry.comments@86 != null
*/
85 for (ContentDecorator decorator : decorators) {
86 decorator.decorate(context, blogEntry);
87 }
88
89 // if the view is detail, decorate the comments and TrackBacks too
90 if (context.getView() == ContentDecoratorContext.DETAIL_VIEW) {
91 for (Comment comment : blogEntry.getComments()) {
92 decorate(context, comment);
93 }
94
95 for (TrackBack trackBack : blogEntry.getTrackBacks()) {
96 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 public void decorate(ContentDecoratorContext context, Comment comment) {
/*
P/P * Method: void decorate(ContentDecoratorContext, Comment)
*
* Preconditions:
* this.decorators != null
*
* Presumptions:
* java.util.Iterator:next(...)@108 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@108: {1}, {0}
*
* Postconditions:
* possibly_updated(comment.author)
* possibly_updated(comment.body)
* possibly_updated(comment.email)
* possibly_updated(comment.title)
* possibly_updated(comment.website)
*/
108 for (ContentDecorator decorator : decorators) {
109 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 public void decorate(ContentDecoratorContext context, TrackBack trackBack) {
/*
P/P * Method: void decorate(ContentDecoratorContext, TrackBack)
*
* Preconditions:
* this.decorators != null
*
* Presumptions:
* java.util.Iterator:next(...)@120 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@120: {1}, {0}
*
* Postconditions:
* possibly_updated(trackBack.blogName)
* possibly_updated(trackBack.excerpt)
* possibly_updated(trackBack.title)
* possibly_updated(trackBack.url)
*/
120 for (ContentDecorator decorator : decorators) {
121 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 public void decorate(ContentDecoratorContext context, StaticPage staticPage) {
/*
P/P * Method: void decorate(ContentDecoratorContext, StaticPage)
*
* Preconditions:
* this.decorators != null
*
* Presumptions:
* java.util.Iterator:next(...)@132 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@132: {1}, {0}
*/
132 for (ContentDecorator decorator : decorators) {
133 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 public Blog getBlog() {
/*
P/P * Method: Blog getBlog()
*
* Preconditions:
* init'ed(this.blog)
*
* Postconditions:
* return_value == this.blog
* init'ed(return_value)
*/
143 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 public void setBlog(Blog blog) {
/*
P/P * Method: void setBlog(Blog)
*
* Postconditions:
* this.blog == blog
* init'ed(this.blog)
*/
152 this.blog = blog;
153 }
154
155 /**
156 * Gets the list of content decorators.
157 *
158 * @return a List of ContentDecorator instances
159 */
160 public List<ContentDecorator> getDecorators() {
/*
P/P * Method: List getDecorators()
*
* Preconditions:
* init'ed(this.decorators)
*
* Postconditions:
* return_value == &new ArrayList(getDecorators#1)
* new ArrayList(getDecorators#1) num objects == 1
*/
161 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 public static void decorate(ContentDecoratorContext context, List blogEntries) {
/*
P/P * Method: void decorate(ContentDecoratorContext, List)
*
* Preconditions:
* (soft) context != null
*
* Presumptions:
* java.util.Iterator:next(...)@173 != null
*
* Test Vectors:
* blogEntries: Addr_Set{null}, Inverse{null}
* java.util.Iterator:hasNext(...)@172: {1}, {0}
*
* Preconditions:
* (soft) init'ed(context.view)
*
* Presumptions:
* blogEntry.blog@173 != null
* blogEntry.comments@173 != null
* getBlog(...).decoratorChain@173 != null
* getContentDecoratorChain(...).decorators@173 != null
*/
170 if (blogEntries != null) {
171 Iterator it = blogEntries.iterator();
172 while (it.hasNext()) {
173 BlogEntry blogEntry = (BlogEntry)it.next();
174 blogEntry.getBlog().getContentDecoratorChain().decorate(context, blogEntry);
175 }
176 }
177 }
178
179 }
SofCheck Inspector Build Version : 2.22510
| contentdecoratorchain.java |
2010-Jun-25 19:40:32 |
| contentdecoratorchain.class |
2010-Jul-19 20:23:40 |