File Source: multiblog.java
/*
P/P * Method: net.sourceforge.pebble.domain.MultiBlog__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.domain;
33
34 import net.sourceforge.pebble.comparator.BlogEntryComparator;
35 import net.sourceforge.pebble.PebbleContext;
36
/*
P/P * Method: void net.sourceforge.pebble.domain.MultiBlog(String)
*
* Preconditions:
* (soft) net/sourceforge/pebble/domain/AbstractBlog.log != null
*
* Postconditions:
* init'ed(this.blog)
* this.messages == &new LinkedList(AbstractBlog#1)
* this.properties == &new Properties(loadProperties#1)
* this.root == root
* init'ed(this.root)
* new LinkedList(AbstractBlog#1) num objects == 1
* new Properties(loadProperties#1) num objects == 1
*/
37 import javax.servlet.http.HttpServletRequest;
38 import java.util.*;
39
40 /**
41 * A composite blog is one that is made up of one or more simple blogs. This
42 * is effectively a container when Pebble is running in multi-user mode - there
43 * being a single MultiBlog and many Blog instances.
44 * <br /><br />
45 * In addition to managing one or more simple blogs, a composite blog provides
46 * some aggegration functionality over the blogs it manages in order to
47 * generate an aggregated XML (RSS/RDF/Atom) feed.
48 *
49 * @author Simon Brown
50 */
51 public class MultiBlog extends AbstractBlog {
52
53 /**
54 * Creates a new Blog instance, based at the specified location.
55 *
56 * @param root an absolute path pointing to the root directory of the blog
57 */
58 public MultiBlog(String root) {
59 super(root);
60
61 // probably MultiBlog should be made a final class if init is called from here -
62 // see javadoc comment on AbstractBlog.init() for reasons
63 init();
64 }
65
66 /**
67 * Gets the default properties for a MultiBlog.
68 *
69 * @return a Properties instance
70 */
/*
P/P * Method: Properties getDefaultProperties()
*
* Postconditions:
* return_value == &new Properties(getDefaultProperties#1)
* new Properties(getDefaultProperties#1) num objects == 1
*/
71 protected Properties getDefaultProperties() {
72 Properties defaultProperties = new Properties();
73 defaultProperties.setProperty(NAME_KEY, "My blogs");
74 defaultProperties.setProperty(DESCRIPTION_KEY, "");
75 defaultProperties.setProperty(IMAGE_KEY, "");
76 defaultProperties.setProperty(AUTHOR_KEY, "Various");
77 defaultProperties.setProperty(TIMEZONE_KEY, "Europe/London");
78 defaultProperties.setProperty(RECENT_BLOG_ENTRIES_ON_HOME_PAGE_KEY, "3");
79 defaultProperties.setProperty(LANGUAGE_KEY, "en");
80 defaultProperties.setProperty(COUNTRY_KEY, "GB");
81 defaultProperties.setProperty(CHARACTER_ENCODING_KEY, "UTF-8");
82 defaultProperties.setProperty(THEME_KEY, "default");
83
84 return defaultProperties;
85 }
86
87 /**
88 * Gets the ID of this blog.
89 *
90 * @return the ID as a String
91 */
/*
P/P * Method: String getId()
*
* Postconditions:
* return_value == &""
*/
92 public String getId() {
93 return "";
94 }
95
96 /**
97 * Gets the URL where this blog is deployed.
98 *
99 * @return a URL as a String
100 */
/*
P/P * Method: String getUrl()
*
* Presumptions:
* net.sourceforge.pebble.PebbleContext:getConfiguration(...)@102 != null
* net.sourceforge.pebble.PebbleContext:getInstance(...)@102 != null
*
* Postconditions:
* init'ed(return_value)
*/
101 public String getUrl() {
102 return PebbleContext.getInstance().getConfiguration().getUrl();
103 }
104
105 /**
106 * Gets the relative URL where this blog is deployed.
107 *
108 * @return a URL as a String
109 */
/*
P/P * Method: String getRelativeUrl()
*
* Postconditions:
* return_value == &"."
*/
110 public String getRelativeUrl() {
111 return "/";
112 }
113
114 /**
115 * Gets the date that this blog was last updated.
116 *
117 * @return a Date instance representing the time of the most recent entry
118 */
/*
P/P * Method: Date getLastModified()
*
* Preconditions:
* net/sourceforge/pebble/domain/BlogManager.instance != null
* net/sourceforge/pebble/domain/BlogManager.instance.blogs != null
*
* Presumptions:
* blog.blogEntryIndex@125 != null
* blog.blogEntryIndex@126 != null
* java.util.Iterator:next(...)@125 != null
*
* Postconditions:
* init'ed(return_value)
* new Date(getLastModified#1) num objects == 1
* init'ed(new Date(getLastModified#1*) num objects)
*
* Test Vectors:
* java.util.Date:after(...)@126: {0}, {1}
* java.util.Iterator:hasNext(...)@124: {1}, {0}
*/
119 public Date getLastModified() {
120 Date date = new Date(0);
121
122 Iterator it = BlogManager.getInstance().getPublicBlogs().iterator();
123 Blog blog;
124 while (it.hasNext()) {
125 blog = (Blog)it.next();
+ 126 if (blog.getLastModified().after(date)) {
127 date = blog.getLastModified();
128 }
129 }
130
131 return date;
132 }
133
134 /**
135 * Gets the most recent blog entries, the number
136 * of which is specified.
137 *
138 * @param numberOfEntries the number of entries to get
139 * @return a List containing the most recent blog entries
140 */
/*
P/P * Method: List getRecentBlogEntries(int)
*
* Preconditions:
* net/sourceforge/pebble/domain/BlogManager.instance != null
* net/sourceforge/pebble/domain/BlogManager.instance.blogs != null
*
* Presumptions:
* blog.blogEntryIndex@144 != null
* blog.properties@144 != null
* java.util.Iterator:next(...)@144 != null
*
* Postconditions:
* init'ed(return_value)
* new ArrayList(getRecentBlogEntries#4) num objects <= 1
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@144: {1}, {0}
*/
141 public List getRecentBlogEntries(int numberOfEntries) {
142 List blogEntries = new ArrayList();
143
144 for (Blog blog : BlogManager.getInstance().getPublicBlogs()) {
145 blogEntries.addAll(blog.getRecentPublishedBlogEntries());
146 }
147
148 Collections.sort(blogEntries, new BlogEntryComparator());
149
150 if (blogEntries.size() >= numberOfEntries) {
151 return new ArrayList(blogEntries).subList(0, numberOfEntries);
152 } else {
153 return new ArrayList(blogEntries);
154 }
155 }
156
157 /**
158 * Logs this request for blog.
159 *
160 * @param request the HttpServletRequest instance for this request
161 */
162 public void log(HttpServletRequest request, int status) {
163 // no op
/*
P/P * Method: void log(HttpServletRequest, int)
*/
164 }
165
166 }
SofCheck Inspector Build Version : 2.22510
| multiblog.java |
2010-Jun-25 19:40:32 |
| multiblog.class |
2010-Jul-19 20:23:40 |