001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.rendering.pagers;
020:
021: import java.util.HashMap;
022: import java.util.Map;
023: import org.apache.roller.util.URLUtilities;
024:
025: /**
026: * Abstract base for simple pagers.
027: */
028: public abstract class AbstractPager implements Pager {
029:
030: private String url = null;
031: private int page = 0;
032:
033: public AbstractPager(String baseUrl, int pageNum) {
034:
035: this .url = baseUrl;
036: if (pageNum > 0) {
037: this .page = pageNum;
038: }
039: }
040:
041: public String getHomeLink() {
042: return url;
043: }
044:
045: public String getHomeName() {
046: return "Home";
047: }
048:
049: public String getNextLink() {
050: if (hasMoreItems()) {
051: int nextPage = page + 1;
052: Map params = new HashMap();
053: params.put("page", "" + nextPage);
054: return createURL(url, params);
055: }
056: return null;
057: }
058:
059: public String getNextName() {
060: if (hasMoreItems()) {
061: return "Next";
062: }
063: return null;
064: }
065:
066: public String getPrevLink() {
067: if (page > 0) {
068: int prevPage = page - 1;
069: Map params = new HashMap();
070: params.put("page", "" + prevPage);
071: return createURL(url, params);
072: }
073: return null;
074: }
075:
076: public String getPrevName() {
077: if (page > 0) {
078: return "Previous";
079: }
080: return null;
081: }
082:
083: public boolean hasMoreItems() {
084: return false;
085: }
086:
087: protected String createURL(String url, Map params) {
088:
089: return url + URLUtilities.getQueryString(params);
090: }
091:
092: public String getUrl() {
093: return url;
094: }
095:
096: public void setUrl(String url) {
097: this .url = url;
098: }
099:
100: public int getPage() {
101: return page;
102: }
103:
104: public void setPage(int page) {
105: this.page = page;
106: }
107:
108: }
|