01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.ui.rendering.pagers;
20:
21: import java.sql.Timestamp;
22: import java.util.Collections;
23: import java.util.Date;
24: import java.util.List;
25: import java.util.Map;
26: import java.util.TreeMap;
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29: import org.apache.roller.business.Roller;
30: import org.apache.roller.business.RollerFactory;
31: import org.apache.roller.business.WeblogManager;
32: import org.apache.roller.pojos.WeblogEntryData;
33: import org.apache.roller.pojos.WebsiteData;
34: import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
35:
36: /**
37: * A special pager for showing entries in preview mode.
38: *
39: * This pager is different from the other pagers because it allows access to
40: * data we don't normally provide to templates working on the "live" weblog,
41: * like entries in DRAFT mode.
42: */
43: public class WeblogEntriesPreviewPager extends
44: WeblogEntriesPermalinkPager {
45:
46: private static Log log = LogFactory
47: .getLog(WeblogEntriesPreviewPager.class);
48:
49: public WeblogEntriesPreviewPager(WebsiteData weblog, String locale,
50: String pageLink, String entryAnchor, String dateString,
51: String catPath, List tags, int page) {
52:
53: super (weblog, locale, pageLink, entryAnchor, dateString,
54: catPath, tags, page);
55: }
56:
57: public Map getEntries() {
58: if (entries == null)
59: try {
60: Roller roller = RollerFactory.getRoller();
61: WeblogManager wmgr = roller.getWeblogManager();
62: currEntry = wmgr.getWeblogEntryByAnchor(weblog,
63: entryAnchor);
64: if (currEntry != null) {
65:
66: // clone the entry since we don't want to work with the real pojo
67: WeblogEntryData tmpEntry = new WeblogEntryData();
68: tmpEntry.setData(currEntry);
69:
70: // set the pubtime to the current time if it is unset
71: if (tmpEntry.getPubTime() == null) {
72: tmpEntry.setPubTime(new Timestamp(System
73: .currentTimeMillis()));
74: }
75:
76: // store the entry in the collection
77: entries = new TreeMap();
78: entries.put(tmpEntry.getPubTime(), Collections
79: .singletonList(WeblogEntryDataWrapper
80: .wrap(tmpEntry)));
81: }
82: } catch (Exception e) {
83: log.error("ERROR: fetching entry", e);
84: }
85:
86: return entries;
87: }
88:
89: }
|