File Source: SearchResultsPager.java
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.pagers.SearchResultsPager__static_init
*/
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.Locale;
22 import java.util.Map;
23 import org.apache.roller.weblogger.business.URLStrategy;
24 import org.apache.roller.weblogger.pojos.Weblog;
25 import org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest;
26 import org.apache.roller.weblogger.util.I18nMessages;
27
28 /**
29 * Pager for navigating through search results.
30 */
31 public class SearchResultsPager implements WeblogEntriesPager {
32
33 // message utils for doing i18n messages
34 I18nMessages messageUtils = null;
35
36 // url strategy
37 URLStrategy urlStrategy = null;
38
39 private Map entries = null;
40
41 private Weblog weblog = null;
42 private String locale = null;
43 private String query = null;
44 private String category = null;
45 private int page = 0;
46 private boolean moreResults = false;
47
48
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.pagers.SearchResultsPager()
*
* Postconditions:
* this.category == null
* this.entries == null
* this.locale == null
* this.messageUtils == null
* this.query == null
* this.urlStrategy == null
* this.weblog == null
* this.moreResults == 0
* this.page == 0
*/
49 public SearchResultsPager() {}
50
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.pagers.SearchResultsPager(URLStrategy, WeblogSearchRequest, Map, bool)
*
* Preconditions:
* org/apache/roller/weblogger/util/I18nMessages.messagesMap != null
* searchRequest != null
*
* Presumptions:
* org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest:getLocale(...)@63 == null
* org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest:getWeblog(...)@60 != null
*
* Postconditions:
* init'ed(this.category)
* this.entries == entries
* init'ed(this.entries)
* this.locale == null
* this.messageUtils != null
* this.moreResults == more
* init'ed(this.moreResults)
* init'ed(this.page)
* init'ed(this.query)
* this.urlStrategy == strat
* ...
*/
51 public SearchResultsPager(URLStrategy strat, WeblogSearchRequest searchRequest, Map entries, boolean more) {
52
53 // url strategy for building urls
54 this.urlStrategy = strat;
55
56 // store search results
57 this.entries = entries;
58
59 // data from search request
60 this.weblog = searchRequest.getWeblog();
61 this.query = searchRequest.getQuery();
62 this.category = searchRequest.getWeblogCategoryName();
63 this.locale = searchRequest.getLocale();
64 this.page = searchRequest.getPageNum();
65
66 // does this pager have more results?
67 this.moreResults = more;
68
69 // get a message utils instance to handle i18n of messages
70 Locale viewLocale = null;
+ 71 if(locale != null) {
+ 72 String[] langCountry = locale.split("_");
73 if(langCountry.length == 1) {
74 viewLocale = new Locale(langCountry[0]);
75 } else if(langCountry.length == 2) {
76 viewLocale = new Locale(langCountry[0], langCountry[1]);
77 }
78 } else {
79 viewLocale = weblog.getLocaleInstance();
80 }
+ 81 this.messageUtils = I18nMessages.getMessages(viewLocale);
82 }
83
84
85 public Map getEntries() {
/*
P/P * Method: Map getEntries()
*
* Preconditions:
* init'ed(this.entries)
*
* Postconditions:
* return_value == this.entries
* init'ed(return_value)
*/
86 return entries;
87 }
88
89
90 public String getHomeLink() {
/*
P/P * Method: String getHomeLink()
*
* Preconditions:
* init'ed(this.locale)
* this.urlStrategy != null
* init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*/
91 return urlStrategy.getWeblogURL(weblog, locale, false);
92 }
93
94 public String getHomeName() {
/*
P/P * Method: String getHomeName()
*
* Preconditions:
* this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Postconditions:
* init'ed(return_value)
*/
95 return messageUtils.getString("searchPager.home");
96 }
97
98
99 public String getNextLink() {
/*
P/P * Method: String getNextLink()
*
* Preconditions:
* init'ed(this.moreResults)
* (soft) init'ed(this.category)
* (soft) init'ed(this.locale)
* (soft) this.page <= 232-2
* (soft) init'ed(this.query)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.moreResults: {0}, {1}
*/
100 if(moreResults) {
101 return urlStrategy.getWeblogSearchURL(weblog, locale, query, category, page + 1, false);
102 }
103 return null;
104 }
105
106 public String getNextName() {
/*
P/P * Method: String getNextName()
*
* Preconditions:
* init'ed(this.moreResults)
* (soft) init'ed(this.category)
* (soft) init'ed(this.locale)
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
* (soft) this.page <= 232-2
* (soft) init'ed(this.query)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*/
107 if (getNextLink() != null) {
108 return messageUtils.getString("searchPager.next");
109 }
110 return null;
111 }
112
113 public String getPrevLink() {
/*
P/P * Method: String getPrevLink()
*
* Preconditions:
* init'ed(this.page)
* (soft) init'ed(this.category)
* (soft) init'ed(this.locale)
* (soft) init'ed(this.query)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.page: {-231..0}, {1..232-1}
*/
114 if(page > 0) {
115 return urlStrategy.getWeblogSearchURL(weblog, locale, query, category, page - 1, false);
116 }
117 return null;
118 }
119
120 public String getPrevName() {
/*
P/P * Method: String getPrevName()
*
* Preconditions:
* init'ed(this.page)
* (soft) init'ed(this.category)
* (soft) init'ed(this.locale)
* (soft) this.messageUtils != null
* (soft) this.messageUtils.bundle != null
* (soft) init'ed(this.query)
* (soft) this.urlStrategy != null
* (soft) init'ed(this.weblog)
*
* Postconditions:
* init'ed(return_value)
*/
121 if (getPrevLink() != null) {
122 return messageUtils.getString("searchPager.prev");
123 }
124 return null;
125 }
126
127
128 public String getNextCollectionLink() {
/*
P/P * Method: String getNextCollectionLink()
*
* Postconditions:
* return_value == null
*/
129 return null;
130 }
131
132 public String getNextCollectionName() {
/*
P/P * Method: String getNextCollectionName()
*
* Postconditions:
* return_value == null
*/
133 return null;
134 }
135
136 public String getPrevCollectionLink() {
/*
P/P * Method: String getPrevCollectionLink()
*
* Postconditions:
* return_value == null
*/
137 return null;
138 }
139
140 public String getPrevCollectionName() {
/*
P/P * Method: String getPrevCollectionName()
*
* Postconditions:
* return_value == null
*/
141 return null;
142 }
143
144 }
SofCheck Inspector Build Version : 2.18479
| SearchResultsPager.java |
2009-Jan-02 14:24:54 |
| SearchResultsPager.class |
2009-Sep-04 03:12:44 |