File Source: WeblogEntriesPermalinkPager.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.util.Collections;
22 import java.util.Date;
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.WebloggerException;
29 import org.apache.roller.weblogger.business.URLStrategy;
30 import org.apache.roller.weblogger.business.Weblogger;
31 import org.apache.roller.weblogger.business.WebloggerFactory;
32 import org.apache.roller.weblogger.business.WeblogManager;
33 import org.apache.roller.weblogger.pojos.WeblogEntry;
34 import org.apache.roller.weblogger.pojos.Weblog;
35 import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryWrapper;
36 import org.apache.roller.weblogger.util.Utilities;
37
38
39 /**
40 *
41 */
42 public class WeblogEntriesPermalinkPager extends AbstractWeblogEntriesPager {
43
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesPermalinkPager__static_init
*
* Postconditions:
* init'ed(log)
*/
44 private static Log log = LogFactory.getLog(WeblogEntriesPermalinkPager.class);
45
46 WeblogEntry currEntry = null;
47 WeblogEntry nextEntry = null;
48 WeblogEntry prevEntry = null;
49
50 // collection for the pager
51 Map entries = null;
52
53
54 public WeblogEntriesPermalinkPager(
55 URLStrategy strat,
56 Weblog weblog,
57 String locale,
58 String pageLink,
59 String entryAnchor,
60 String dateString,
61 String catPath,
62 List tags,
63 int page) {
64
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesPermalinkPager(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
* ...
*/
65 super(strat, weblog, locale, pageLink, entryAnchor, dateString, catPath, tags, page);
66
67 getEntries();
68 }
69
70
71 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(...)@74 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@73 != null
* org.apache.roller.weblogger.pojos.WeblogEntry:getPubTime(...)@78 != null
* org.apache.roller.weblogger.pojos.WeblogEntry:getStatus(...)@76 != null
*
* Postconditions:
* return_value == One-of{old this.entries, &new TreeMap(getEntries#1)}
* init'ed(return_value)
* this.entries == return_value
* possibly_updated(this.currEntry)
* new TreeMap(getEntries#1) num objects <= 1
*
* Test Vectors:
* this.entries: Inverse{null}, Addr_Set{null}
* java.lang.String:equals(...)@76: {0}, {1}
* org.apache.roller.weblogger.business.WeblogManager:getWeblogEntryByAnchor(...)@75: Addr_Set{null}, Inverse{null}
*/
72 if (entries == null) try {
73 Weblogger roller = WebloggerFactory.getWeblogger();
74 WeblogManager wmgr = roller.getWeblogManager();
75 currEntry = wmgr.getWeblogEntryByAnchor(weblog, entryAnchor);
76 if (currEntry != null && currEntry.getStatus().equals(WeblogEntry.PUBLISHED)) {
77 entries = new TreeMap();
78 entries.put(new Date(currEntry.getPubTime().getTime()),Collections.singletonList(WeblogEntryWrapper.wrap(currEntry, urlStrategy)));
79 }
80 } catch (Exception e) {
81 log.error("ERROR: fetching entry");
82 }
83
84
85
86 return entries;
87 }
88
89
90 public String getHomeLink() {
/*
P/P * Method: String getHomeLink()
*
* Preconditions:
* init'ed(this.catPath)
* init'ed(this.dateString)
* init'ed(this.locale)
* init'ed(this.pageLink)
* init'ed(this.tags)
* this.urlStrategy != null
* init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*/
91 return createURL(0, 0, weblog, locale, pageLink, null, dateString, catPath, tags);
92 }
93
94
95 public String getHomeName() {
/*
P/P * Method: String getHomeName()
*
* Preconditions:
* this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Postconditions:
* init'ed(return_value)
*/
96 return messageUtils.getString("weblogEntriesPager.single.home");
97 }
98
99
100 public String getNextLink() {
/*
P/P * Method: String getNextLink()
*
* Preconditions:
* init'ed(this.nextEntry)
* (soft) log != null
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.currEntry)
* (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)
* init'ed(this.nextEntry)
*/
101 if (getNextEntry() != null) {
102 return createURL(0, 0, weblog, locale, pageLink, nextEntry.getAnchor(), dateString, catPath, tags);
103 }
104 return null;
105 }
106
107
108 public String getNextName() {
/*
P/P * Method: String getNextName()
*
* Preconditions:
* init'ed(this.nextEntry)
* (soft) log != null
* (soft) init'ed(this.currEntry)
* (soft) init'ed(this.locale)
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Presumptions:
* org.apache.roller.weblogger.pojos.WeblogEntry:getTitle(...)@110 != null
*
* Postconditions:
* init'ed(return_value)
* init'ed(this.nextEntry)
*/
109 if (getNextEntry() != null) {
+ 110 String title = Utilities.truncateNicely(getNextEntry().getTitle(), 15, 20, "...");
111 return messageUtils.getString("weblogEntriesPager.single.next", new Object[] {title});
112 }
113 return null;
114 }
115
116
117 public String getPrevLink() {
/*
P/P * Method: String getPrevLink()
*
* Preconditions:
* init'ed(this.prevEntry)
* (soft) log != null
* (soft) init'ed(this.catPath)
* (soft) init'ed(this.currEntry)
* (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)
* init'ed(this.prevEntry)
*/
118 if (getPrevEntry() != null) {
119 return createURL(0, 0, weblog, locale, pageLink, prevEntry.getAnchor(), dateString, catPath, tags);
120 }
121 return null;
122 }
123
124
125 public String getPrevName() {
/*
P/P * Method: String getPrevName()
*
* Preconditions:
* init'ed(this.prevEntry)
* (soft) log != null
* (soft) init'ed(this.currEntry)
* (soft) init'ed(this.locale)
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Presumptions:
* org.apache.roller.weblogger.pojos.WeblogEntry:getTitle(...)@127 != null
*
* Postconditions:
* init'ed(return_value)
* init'ed(this.prevEntry)
*/
126 if (getPrevEntry() != null) {
+ 127 String title = Utilities.truncateNicely(getPrevEntry().getTitle(), 15, 20, "...");
128 return messageUtils.getString("weblogEntriesPager.single.prev", new Object[] {title});
129 }
130 return null;
131 }
132
133
134 private WeblogEntry getNextEntry() {
/*
P/P * Method: WeblogEntry getNextEntry()
*
* Preconditions:
* init'ed(this.nextEntry)
* (soft) log != null
* (soft) init'ed(this.currEntry)
* (soft) init'ed(this.locale)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@137 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@136 != null
* org.apache.roller.weblogger.pojos.WeblogEntry:getPubTime(...)@140 != null
* org.apache.roller.weblogger.pojos.WeblogEntry:getStatus(...)@140 != null
*
* Postconditions:
* init'ed(return_value)
* this.nextEntry == return_value
*
* Test Vectors:
* this.nextEntry: Inverse{null}, Addr_Set{null}
* java.lang.String:equals(...)@140: {0}, {1}
* java.sql.Timestamp:after(...)@140: {0}, {1}
* org.apache.roller.weblogger.business.WeblogManager:getNextEntry(...)@138: Addr_Set{null}, Inverse{null}
*/
135 if (nextEntry == null) try {
136 Weblogger roller = WebloggerFactory.getWeblogger();
137 WeblogManager wmgr = roller.getWeblogManager();
138 nextEntry = wmgr.getNextEntry(currEntry, null, locale);
139 // make sure that entry is published and not to future
140 if (nextEntry != null && nextEntry.getPubTime().after(new Date())
141 && nextEntry.getStatus().equals(WeblogEntry.PUBLISHED)) {
142 nextEntry = null;
143 }
144 } catch (WebloggerException e) {
145 log.error("ERROR: getting next entry", e);
146 }
147
148 return nextEntry;
149 }
150
151
152 private WeblogEntry getPrevEntry() {
/*
P/P * Method: WeblogEntry getPrevEntry()
*
* Preconditions:
* init'ed(this.prevEntry)
* (soft) log != null
* (soft) init'ed(this.currEntry)
* (soft) init'ed(this.locale)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@155 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@154 != null
* org.apache.roller.weblogger.pojos.WeblogEntry:getPubTime(...)@158 != null
* org.apache.roller.weblogger.pojos.WeblogEntry:getStatus(...)@158 != null
*
* Postconditions:
* init'ed(return_value)
* this.prevEntry == return_value
*
* Test Vectors:
* this.prevEntry: Inverse{null}, Addr_Set{null}
* java.lang.String:equals(...)@158: {0}, {1}
* java.sql.Timestamp:after(...)@158: {0}, {1}
* org.apache.roller.weblogger.business.WeblogManager:getPreviousEntry(...)@156: Addr_Set{null}, Inverse{null}
*/
153 if (prevEntry == null) try {
154 Weblogger roller = WebloggerFactory.getWeblogger();
155 WeblogManager wmgr = roller.getWeblogManager();
156 prevEntry = wmgr.getPreviousEntry(currEntry, null, locale);
157 // make sure that entry is published and not to future
158 if (prevEntry != null && prevEntry.getPubTime().after(new Date())
159 && prevEntry.getStatus().equals(WeblogEntry.PUBLISHED)) {
160 prevEntry = null;
161 }
162 } catch (WebloggerException e) {
163 log.error("ERROR: getting prev entry", e);
164 }
165
166 return prevEntry;
167 }
168
169 }
SofCheck Inspector Build Version : 2.18479
| WeblogEntriesPermalinkPager.java |
2009-Jan-02 14:25:44 |
| WeblogEntriesPermalinkPager.class |
2009-Sep-04 03:12:44 |