KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > rendering > pagers > AbstractPager


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.ui.rendering.pagers;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23 import org.apache.roller.util.URLUtilities;
24
25
26 /**
27  * Abstract base for simple pagers.
28  */

29 public abstract class AbstractPager implements Pager {
30     
31     private String JavaDoc url = null;
32     private int page = 0;
33     
34     
35     public AbstractPager(String JavaDoc baseUrl, int pageNum) {
36         
37         this.url = baseUrl;
38         if(pageNum > 0) {
39             this.page = pageNum;
40         }
41     }
42     
43     
44     public String JavaDoc getHomeLink() {
45         return url;
46     }
47     
48     
49     public String JavaDoc getHomeName() {
50         return "Home";
51     }
52     
53     
54     public String JavaDoc getNextLink() {
55         if(hasMoreItems()) {
56             int nextPage = page + 1;
57             Map JavaDoc params = new HashMap JavaDoc();
58             params.put("page", ""+nextPage);
59             return createURL(url, params);
60         }
61         return null;
62     }
63     
64     
65     public String JavaDoc getNextName() {
66         if(hasMoreItems()) {
67             return "Next";
68         }
69         return null;
70     }
71     
72     
73     public String JavaDoc getPrevLink() {
74         if (page > 0) {
75             int prevPage = page - 1;
76             Map JavaDoc params = new HashMap JavaDoc();
77             params.put("page", ""+prevPage);
78             return createURL(url, params);
79         }
80         return null;
81     }
82     
83     
84     public String JavaDoc getPrevName() {
85         if (page > 0) {
86             return "Previous";
87         }
88         return null;
89     }
90     
91     
92     public boolean hasMoreItems() {
93         return false;
94     }
95     
96     
97     protected String JavaDoc createURL(String JavaDoc url, Map JavaDoc params) {
98         
99         return url + URLUtilities.getQueryString(params);
100     }
101
102     
103     public String JavaDoc getUrl() {
104         return url;
105     }
106
107     public void setUrl(String JavaDoc url) {
108         this.url = url;
109     }
110
111     public int getPage() {
112         return page;
113     }
114
115     public void setPage(int page) {
116         this.page = page;
117     }
118     
119 }
120
Popular Tags