File Source: WeblogEntriesDayPager.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.ui.rendering.pagers;
20
21 import java.text.SimpleDateFormat;
22 import java.util.ArrayList;
23 import java.util.Calendar;
24 import java.util.Date;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.TreeMap;
29 import org.apache.commons.collections.comparators.ReverseComparator;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.roller.weblogger.business.Weblogger;
33 import org.apache.roller.weblogger.business.WebloggerFactory;
34 import org.apache.roller.weblogger.business.WeblogManager;
35 import org.apache.roller.weblogger.pojos.WeblogEntry;
36 import org.apache.roller.weblogger.pojos.Weblog;
37 import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryWrapper;
38 import org.apache.roller.util.DateUtil;
39 import org.apache.roller.weblogger.business.URLStrategy;
40
41
42 /**
43 *
44 */
45 public class WeblogEntriesDayPager extends AbstractWeblogEntriesPager {
46
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesDayPager__static_init
*
* Postconditions:
* init'ed(log)
*/
47 private static Log log = LogFactory.getLog(WeblogEntriesDayPager.class);
48
49 private SimpleDateFormat dayFormat = new SimpleDateFormat();
50
51 private Date day;
52 private Date nextDay;
53 private Date prevDay;
54
55 // collection for the pager
56 private Map entries = null;
57
58 // are there more pages?
59 private boolean more = false;
60
61
62 public WeblogEntriesDayPager(
63 URLStrategy strat,
64 Weblog weblog,
65 String locale,
66 String pageLink,
67 String entryAnchor,
68 String dateString,
69 String catPath,
70 List tags,
71 int page) {
72
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesDayPager(URLStrategy, Weblog, String, String, String, String, String, List, int)
*
* Preconditions:
* locale == null
* org/apache/roller/weblogger/util/I18nMessages.messagesMap != null
* weblog != null
* (soft) log != null
*
* Presumptions:
* java.util.Calendar:getInstance(...)@82 != null
* java.util.Calendar:getTime(...)@89 != null
* org.apache.roller.util.DateUtil:getEndOfDay(...)@101 != null
* this.length in range
* this.messageUtils init'ed
* ...
*
* Postconditions:
* this.catPath == catPath
* init'ed(this.catPath)
* this.dateString == dateString
* init'ed(this.dateString)
* init'ed(this.day)
* this.dayFormat == &new SimpleDateFormat(WeblogEntriesDayPager#2)
* this.entries == &new TreeMap(getEntries#1)
* this.entryAnchor == entryAnchor
* init'ed(this.entryAnchor)
* (soft) this.length <= 232-2
* ...
*
* Test Vectors:
* java.util.Date:after(...)@90: {0}, {1}
* java.util.Date:before(...)@101: {0}, {1}
* org.apache.roller.weblogger.pojos.Weblog:getDateCreated(...)@100: Addr_Set{null}, Inverse{null}
*/
73 super(strat, weblog, locale, pageLink, entryAnchor, dateString, catPath, tags, page);
74
75 dayFormat = new SimpleDateFormat(
76 messageUtils.getString("weblogEntriesPager.day.dateFormat"));
77
78 getEntries();
79
80 day = parseDate(dateString);
81
82 Calendar cal = Calendar.getInstance();
83
84 cal.setTime(day);
85 cal.add(Calendar.DAY_OF_MONTH, 1);
86 cal.set(Calendar.HOUR, 0);
87 cal.set(Calendar.MINUTE, 0);
88 cal.set(Calendar.SECOND, 0);
89 nextDay = cal.getTime();
90 if (nextDay.after(getToday())) {
91 nextDay = null;
92 }
93
94 cal.setTime(day);
95 cal.add(Calendar.DAY_OF_MONTH, -1);
96 cal.set(Calendar.HOUR, 23);
97 cal.set(Calendar.MINUTE, 59);
98 cal.set(Calendar.SECOND, 59);
99 prevDay = cal.getTime();
100 Date weblogInitialDate = weblog.getDateCreated() != null ? weblog.getDateCreated() : new Date(0);
101 if (DateUtil.getEndOfDay(prevDay,cal).before(weblogInitialDate)) {
102 prevDay = null;
103 }
104 }
105
106
107 public Map getEntries() {
/*
P/P * Method: Map getEntries()
*
* Preconditions:
* init'ed(this.entries)
* init'ed(this.dateString)
* this.weblog != null
* (soft) log != null
* (soft) init'ed(this.catPath)
* (soft) this.length <= 232-2
* (soft) init'ed(this.locale)
* (soft) init'ed(this.offset)
* (soft) init'ed(this.tags)
*
* Presumptions:
* java.util.Map:get(...)@140 != null
* java.util.Map:keySet(...)@134 != null
* org.apache.roller.weblogger.business.WeblogManager:getWeblogEntryObjectMap(...)@120 != null
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@120 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@118 != null
* ...
*
* Postconditions:
* return_value == One-of{old this.entries, &new TreeMap(getEntries#1)}
* return_value != null
* this.entries == return_value
* possibly_updated(this.more)
* new TreeMap(getEntries#1) num objects <= 1
*
* Test Vectors:
* this.entries: Inverse{null}, Addr_Set{null}
* java.util.List:size(...)@150: {-231..0}, {1..232-1}
*/
108 Date date = parseDate(dateString);
109 Calendar cal = Calendar.getInstance(weblog.getTimeZoneInstance());
110 Date startDate = null;
111 Date endDate = date;
112 startDate = DateUtil.getStartOfDay(endDate, cal);
113 endDate = DateUtil.getEndOfDay(endDate, cal);
114
115 if (entries == null) {
116 entries = new TreeMap(new ReverseComparator());
117 try {
118 Weblogger roller = WebloggerFactory.getWeblogger();
+ 119 WeblogManager wmgr = roller.getWeblogManager();
120 Map mmap = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogEntryObjectMap(
121
122 weblog,
123 startDate,
124 endDate,
125 catPath,
126 tags,WeblogEntry.PUBLISHED,
127 locale,
128 offset,
129 length + 1);
130
131 // need to wrap pojos
132 int count = 0;
133 Date key = null;
134 Iterator days = mmap.keySet().iterator();
135 while(days.hasNext()) {
136 key = (Date) days.next();
137
138 // now we need to go through each entry in a day and wrap
139 List wrapped = new ArrayList();
140 List unwrapped = (List) mmap.get(key);
141 for(int i=0; i < unwrapped.size(); i++) {
+ 142 if (count++ < length) {
143 wrapped.add(i,WeblogEntryWrapper.wrap((WeblogEntry)unwrapped.get(i), urlStrategy));
144 } else {
145 more = true;
146 }
147 }
148
149 // done with that day, put it in the map
150 if(wrapped.size() > 0) {
151 entries.put(key, wrapped);
152 }
153 }
154
155
156 } catch (Exception e) {
157 log.error("ERROR: getting entry month map", e);
158 }
159 }
160 return entries;
161 }
162
163
164 public String getHomeLink() {
/*
P/P * Method: String getHomeLink()
*
* Preconditions:
* init'ed(this.catPath)
* init'ed(this.locale)
* init'ed(this.pageLink)
* init'ed(this.tags)
* this.urlStrategy != null
* init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*/
165 return createURL(0, 0, weblog, locale, pageLink, null, null, catPath, tags);
166 }
167
168
169 public String getHomeName() {
/*
P/P * Method: String getHomeName()
*
* Preconditions:
* this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Postconditions:
* init'ed(return_value)
*/
170 return messageUtils.getString("weblogEntriesPager.day.home");
171 }
172
173
174 public String getNextLink() {
/*
P/P * Method: String getNextLink()
*
* Preconditions:
* init'ed(this.more)
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.dateString)
* (soft) init'ed(this.locale)
* (soft) this.page <= 232-2
* (soft) init'ed(this.pageLink)
* (soft) init'ed(this.tags)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.more: {0}, {1}
*/
175 if (more) {
176 return createURL(page, 1, weblog, locale, pageLink, null, dateString, catPath, tags);
177 }
178 return null;
179 }
180
181
182 public String getNextName() {
/*
P/P * Method: String getNextName()
*
* Preconditions:
* init'ed(this.more)
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.dateString)
* (soft) init'ed(this.day)
* (soft) this.dayFormat != null
* (soft) init'ed(this.locale)
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
* (soft) this.page <= 232-2
* (soft) init'ed(this.pageLink)
* ...
*
* Postconditions:
* init'ed(return_value)
*/
183 if (getNextLink() != null) {
184 return messageUtils.getString("weblogEntriesPager.day.next", new Object[] {dayFormat.format(day)});
185 }
186 return null;
187 }
188
189
190 public String getPrevLink() {
/*
P/P * Method: String getPrevLink()
*
* Preconditions:
* init'ed(this.page)
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.dateString)
* (soft) init'ed(this.locale)
* (soft) init'ed(this.pageLink)
* (soft) init'ed(this.tags)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.page: {-231..0}, {1..232-1}
*/
191 if (page > 0) {
192 return createURL(page, -1, weblog, locale, pageLink, null, dateString, catPath, tags);
193 }
194 return null;
195 }
196
197
198 public String getPrevName() {
/*
P/P * Method: String getPrevName()
*
* Preconditions:
* init'ed(this.page)
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.dateString)
* (soft) init'ed(this.day)
* (soft) this.dayFormat != null
* (soft) init'ed(this.locale)
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
* (soft) init'ed(this.pageLink)
* (soft) init'ed(this.tags)
* ...
*
* Postconditions:
* init'ed(return_value)
*/
199 if (getPrevLink() != null) {
200 return messageUtils.getString("weblogEntriesPager.day.prev", new Object[] {dayFormat.format(day)});
201 }
202 return null;
203 }
204
205
206 public String getNextCollectionLink() {
/*
P/P * Method: String getNextCollectionLink()
*
* Preconditions:
* init'ed(this.nextDay)
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.locale)
* (soft) init'ed(this.pageLink)
* (soft) init'ed(this.tags)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.nextDay: Addr_Set{null}, Inverse{null}
*/
207 if (nextDay != null) {
208 String next = DateUtil.format8chars(nextDay);
209 return createURL(0, 0, weblog, locale, pageLink, null, next, catPath, tags);
210 }
211 return null;
212 }
213
214
215 public String getNextCollectionName() {
/*
P/P * Method: String getNextCollectionName()
*
* Preconditions:
* init'ed(this.nextDay)
* (soft) this.dayFormat != null
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.nextDay: Addr_Set{null}, Inverse{null}
*/
216 if (nextDay != null) {
217 return messageUtils.getString("weblogEntriesPager.day.nextCollection", new Object[] {dayFormat.format(nextDay)});
218 }
219 return null;
220 }
221
222
223 public String getPrevCollectionLink() {
/*
P/P * Method: String getPrevCollectionLink()
*
* Preconditions:
* init'ed(this.prevDay)
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.locale)
* (soft) init'ed(this.pageLink)
* (soft) init'ed(this.tags)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.prevDay: Addr_Set{null}, Inverse{null}
*/
224 if (prevDay != null) {
225 String prev = DateUtil.format8chars(prevDay);
226 return createURL(0, 0, weblog, locale, pageLink, null, prev, catPath, tags);
227 }
228 return null;
229 }
230
231
232 public String getPrevCollectionName() {
/*
P/P * Method: String getPrevCollectionName()
*
* Preconditions:
* init'ed(this.prevDay)
* (soft) this.dayFormat != null
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.prevDay: Addr_Set{null}, Inverse{null}
*/
233 if (prevDay != null) {
234 return messageUtils.getString("weblogEntriesPager.day.prevCollection", new Object[] {dayFormat.format(prevDay)});
235 }
236 return null;
237 }
238
239 }
SofCheck Inspector Build Version : 2.18479
| WeblogEntriesDayPager.java |
2009-Jan-02 14:24:54 |
| WeblogEntriesDayPager.class |
2009-Sep-04 03:12:44 |