Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MultiBlog |
|
| 1.625;1.625 |
1 | /* | |
2 | * Copyright (c) 2003-2011, 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 | ||
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 | 20 | 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 | 20 | init(); |
64 | 20 | } |
65 | ||
66 | /** | |
67 | * Gets the default properties for a MultiBlog. | |
68 | * | |
69 | * @return a Properties instance | |
70 | */ | |
71 | protected Properties getDefaultProperties() { | |
72 | 20 | Properties defaultProperties = new Properties(); |
73 | 20 | defaultProperties.setProperty(NAME_KEY, "My blogs"); |
74 | 20 | defaultProperties.setProperty(DESCRIPTION_KEY, ""); |
75 | 20 | defaultProperties.setProperty(IMAGE_KEY, ""); |
76 | 20 | defaultProperties.setProperty(AUTHOR_KEY, "Various"); |
77 | 20 | defaultProperties.setProperty(TIMEZONE_KEY, "Europe/London"); |
78 | 20 | defaultProperties.setProperty(RECENT_BLOG_ENTRIES_ON_HOME_PAGE_KEY, "3"); |
79 | 20 | defaultProperties.setProperty(LANGUAGE_KEY, "en"); |
80 | 20 | defaultProperties.setProperty(COUNTRY_KEY, "GB"); |
81 | 20 | defaultProperties.setProperty(CHARACTER_ENCODING_KEY, "UTF-8"); |
82 | 20 | defaultProperties.setProperty(THEME_KEY, "default"); |
83 | ||
84 | 20 | return defaultProperties; |
85 | } | |
86 | ||
87 | /** | |
88 | * Gets the ID of this blog. | |
89 | * | |
90 | * @return the ID as a String | |
91 | */ | |
92 | public String getId() { | |
93 | 0 | return ""; |
94 | } | |
95 | ||
96 | /** | |
97 | * Gets the URL where this blog is deployed. | |
98 | * | |
99 | * @return a URL as a String | |
100 | */ | |
101 | public String getUrl() { | |
102 | 0 | 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 | */ | |
110 | public String getRelativeUrl() { | |
111 | 0 | 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 | */ | |
119 | public Date getLastModified() { | |
120 | 8 | Date date = new Date(0); |
121 | ||
122 | 8 | Iterator it = BlogManager.getInstance().getPublicBlogs().iterator(); |
123 | Blog blog; | |
124 | 24 | while (it.hasNext()) { |
125 | 16 | blog = (Blog)it.next(); |
126 | 16 | if (blog.getLastModified().after(date)) { |
127 | 4 | date = blog.getLastModified(); |
128 | } | |
129 | } | |
130 | ||
131 | 8 | 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 | */ | |
141 | public List<BlogEntry> getRecentBlogEntries(int numberOfEntries) { | |
142 | 12 | List<BlogEntry> blogEntries = new ArrayList<BlogEntry>(); |
143 | ||
144 | 12 | for (Blog blog : BlogManager.getInstance().getPublicBlogs()) { |
145 | 24 | blogEntries.addAll(blog.getRecentPublishedBlogEntries()); |
146 | } | |
147 | ||
148 | 12 | Collections.sort(blogEntries, new BlogEntryComparator()); |
149 | ||
150 | 12 | if (blogEntries.size() >= numberOfEntries) { |
151 | 12 | return new ArrayList<BlogEntry>(blogEntries).subList(0, numberOfEntries); |
152 | } else { | |
153 | 0 | return new ArrayList<BlogEntry>(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 | |
164 | 0 | } |
165 | ||
166 | } |