File Source: CommentsPager.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.struts2.pagers;
20
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
27 import org.apache.roller.weblogger.util.URLUtilities;
28
29
30 /**
31 * Paging through a collection of comments.
32 */
33 public class CommentsPager {
34
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.pagers.CommentsPager__static_init
*
* Postconditions:
* init'ed(log)
*/
35 private static final Log log = LogFactory.getLog(CommentsPager.class);
36
37 // the collection for the pager
38 private final List<WeblogEntryComment> items;
39
40 // base url for the pager
41 private final String baseUrl;
42
43 // what page we are on
44 private final int pageNum;
45
46 // are there more items?
47 private final boolean moreItems;
48
49
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.pagers.CommentsPager(String, int, List, bool)
*
* Postconditions:
* this.baseUrl == url
* init'ed(this.baseUrl)
* this.items == comments
* init'ed(this.items)
* this.moreItems == hasMore
* init'ed(this.moreItems)
* this.pageNum == page
* init'ed(this.pageNum)
*/
50 public CommentsPager(String url, int page, List<WeblogEntryComment> comments, boolean hasMore) {
51 this.baseUrl = url;
52 this.pageNum = page;
53 this.items = comments;
54 this.moreItems = hasMore;
55 }
56
57
58 public String getNextLink() {
/*
P/P * Method: String getNextLink()
*
* Preconditions:
* (soft) this.baseUrl != null
* (soft) this.pageNum <= 232-2
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* this.moreItems: {0}, {1}
*/
59 if(isMoreItems()) {
60 int nextPage = pageNum + 1;
61 Map<String, String> params = new HashMap();
62 params.put("bean.page", ""+nextPage);
63 return createURL(baseUrl, params);
64 }
65 return null;
66 }
67
68
69 public String getPrevLink() {
/*
P/P * Method: String getPrevLink()
*
* Preconditions:
* (soft) this.baseUrl != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{null,&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* this.pageNum: {-231..0}, {1..232-1}
*/
70 if (pageNum > 0) {
71 int prevPage = pageNum - 1;
72 Map<String, String> params = new HashMap();
73 params.put("bean.page", ""+prevPage);
74 return createURL(baseUrl, params);
75 }
76 return null;
77 }
78
79
80 private String createURL(String base, Map<String, String> params) {
/*
P/P * Method: String createURL(String, Map)
*
* Preconditions:
* base != null
*
* Presumptions:
* org.apache.roller.weblogger.util.URLUtilities:getQueryString(...)@81 != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...)}
*
* Test Vectors:
* java.lang.String:indexOf(...)@83: {-1}, {-231..-2, 0..232-1}
*/
81 String qString = URLUtilities.getQueryString(params);
82
83 if(base.indexOf("?") != -1) {
84 // if base url already has params them just append our query string
85 return base + "&" + qString.substring(1);
86 } else {
87 return base + qString;
88 }
89 }
90
91
92 public List<WeblogEntryComment> getItems() {
/*
P/P * Method: List getItems()
*
* Postconditions:
* return_value == this.items
* init'ed(return_value)
*/
93 return items;
94 }
95
96 public boolean isMoreItems() {
/*
P/P * Method: bool isMoreItems()
*
* Postconditions:
* return_value == this.moreItems
* init'ed(return_value)
*/
97 return moreItems;
98 }
99
100 }
SofCheck Inspector Build Version : 2.18479
| CommentsPager.java |
2009-Jan-02 14:25:02 |
| CommentsPager.class |
2009-Sep-04 03:12:45 |