File Source: WeblogEntriesPreviewPager.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.sql.Timestamp;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.TreeMap;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.roller.weblogger.business.URLStrategy;
29 import org.apache.roller.weblogger.business.Weblogger;
30 import org.apache.roller.weblogger.business.WebloggerFactory;
31 import org.apache.roller.weblogger.business.WeblogManager;
32 import org.apache.roller.weblogger.pojos.WeblogEntry;
33 import org.apache.roller.weblogger.pojos.Weblog;
34 import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryWrapper;
35
36
37 /**
38 * A special pager for showing entries in preview mode.
39 *
40 * This pager is different from the other pagers because it allows access to
41 * data we don't normally provide to templates working on the "live" weblog,
42 * like entries in DRAFT mode.
43 */
44 public class WeblogEntriesPreviewPager extends WeblogEntriesPermalinkPager {
45
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesPreviewPager__static_init
*
* Postconditions:
* init'ed(log)
*/
46 private static Log log = LogFactory.getLog(WeblogEntriesPreviewPager.class);
47
48
49 public WeblogEntriesPreviewPager(
50 URLStrategy strat,
51 Weblog weblog,
52 String locale,
53 String pageLink,
54 String entryAnchor,
55 String dateString,
56 String catPath,
57 List tags,
58 int page) {
59
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesPreviewPager(URLStrategy, Weblog, String, String, String, String, String, List, int)
*
* Preconditions:
* locale == null
* org/apache/roller/weblogger/util/I18nMessages.messagesMap != null
* weblog != null
*
* Postconditions:
* this.catPath == catPath
* init'ed(this.catPath)
* init'ed(this.currEntry)
* this.dateString == dateString
* init'ed(this.dateString)
* init'ed(this.entries)
* this.entryAnchor == entryAnchor
* init'ed(this.entryAnchor)
* init'ed(this.length)
* this.locale == null
* ...
*/
60 super(strat, weblog, locale, pageLink, entryAnchor, dateString, catPath, tags, page);
61 }
62
63
64 public Map getEntries() {
/*
P/P * Method: Map getEntries()
*
* Preconditions:
* init'ed(this.entries)
* (soft) log != null
* (soft) init'ed(this.entryAnchor)
* (soft) init'ed(this.weblog)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@67 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@66 != null
*
* Postconditions:
* return_value == One-of{old this.entries, &new TreeMap(getEntries#3)}
* init'ed(return_value)
* this.entries == return_value
* possibly_updated(this.currEntry)
* new TreeMap(getEntries#3) num objects <= 1
*
* Test Vectors:
* this.entries: Inverse{null}, Addr_Set{null}
* org.apache.roller.weblogger.business.WeblogManager:getWeblogEntryByAnchor(...)@68: Addr_Set{null}, Inverse{null}
* org.apache.roller.weblogger.pojos.WeblogEntry:getPubTime(...)@76: Inverse{null}, Addr_Set{null}
*/
65 if (entries == null) try {
66 Weblogger roller = WebloggerFactory.getWeblogger();
67 WeblogManager wmgr = roller.getWeblogManager();
68 currEntry = wmgr.getWeblogEntryByAnchor(weblog, entryAnchor);
69 if (currEntry != null) {
70
71 // clone the entry since we don't want to work with the real pojo
72 WeblogEntry tmpEntry = new WeblogEntry();
73 tmpEntry.setData(currEntry);
74
75 // set the pubtime to the current time if it is unset
76 if(tmpEntry.getPubTime() == null) {
77 tmpEntry.setPubTime(new Timestamp(System.currentTimeMillis()));
78 }
79
80 // store the entry in the collection
81 entries = new TreeMap();
82 entries.put(tmpEntry.getPubTime(),Collections.singletonList(WeblogEntryWrapper.wrap(tmpEntry, urlStrategy)));
83 }
84 } catch (Exception e) {
85 log.error("ERROR: fetching entry", e);
86 }
87
88
89
90 return entries;
91 }
92
93 }
SofCheck Inspector Build Version : 2.18479
| WeblogEntriesPreviewPager.java |
2009-Jan-02 14:25:18 |
| WeblogEntriesPreviewPager.class |
2009-Sep-04 03:12:44 |