File Source: SearchResultsFeedPager.java
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.pagers.SearchResultsFeedPager__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.HashMap;
22 import java.util.List;
23 import java.util.Locale;
24 import java.util.Map;
25 import org.apache.roller.weblogger.business.URLStrategy;
26 import org.apache.roller.weblogger.business.WebloggerFactory;
27 import org.apache.roller.weblogger.pojos.Weblog;
28 import org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest;
29 import org.apache.roller.weblogger.util.I18nMessages;
30 import org.apache.roller.weblogger.util.URLUtilities;
31
32
33 /**
34 * Pager for navigating through search results feeds.
35 */
36 public class SearchResultsFeedPager extends AbstractPager {
37
38 // message utils for doing i18n messages
39 I18nMessages messageUtils = null;
40
41 private List entries = null;
42
43 private Weblog weblog = null;
44 private boolean moreResults = false;
45
46 private WeblogFeedRequest feedRequest = null;
47
48 private String url = null;
49
50
51 public SearchResultsFeedPager(URLStrategy strat, String baseUrl, int pageNum,
52 WeblogFeedRequest feedRequest, List entries, boolean more) {
53
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.pagers.SearchResultsFeedPager(URLStrategy, String, int, WeblogFeedRequest, List, bool)
*
* Preconditions:
* feedRequest != null
* org/apache/roller/weblogger/util/I18nMessages.messagesMap != null
*
* Presumptions:
* org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest:getLocale(...)@72 != null
* org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest:getWeblog(...)@64 != null
*
* Postconditions:
* this.entries == entries
* init'ed(this.entries)
* this.feedRequest == feedRequest
* this.feedRequest != null
* this.messageUtils != null
* this.moreResults == more
* init'ed(this.moreResults)
* this.page == One-of{0, pageNum}
* this.page >= 0
* this.url == baseUrl
* ...
*
* Test Vectors:
* org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest:getLocale(...)@71: Addr_Set{null}, Inverse{null}
*/
54 super(strat, baseUrl, pageNum);
55
56 this.url = baseUrl;
57
58 this.feedRequest = feedRequest;
59
60 // store search results
61 this.entries = entries;
62
63 // data from search request
64 this.weblog = feedRequest.getWeblog();
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(feedRequest.getLocale() != null) {
72 String[] langCountry = feedRequest.getLocale().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 public List getItems() {
/*
P/P * Method: List getItems()
*
* Preconditions:
* init'ed(this.entries)
*
* Postconditions:
* return_value == this.entries
* init'ed(return_value)
*/
85 return this.entries;
86 }
87
88 public boolean hasMoreItems() {
/*
P/P * Method: bool hasMoreItems()
*
* Preconditions:
* init'ed(this.moreResults)
*
* Postconditions:
* return_value == this.moreResults
* init'ed(return_value)
*/
89 return this.moreResults;
90 }
91
92 public String getHomeLink() {
/*
P/P * Method: String getHomeLink()
*
* Preconditions:
* this.urlStrategy != null
* this.weblog != null
*
* Postconditions:
* init'ed(return_value)
*/
93 return urlStrategy.getWeblogURL(weblog, weblog.getLocale(), false);
94 }
95
96 public String getHomeName() {
/*
P/P * Method: String getHomeName()
*
* Preconditions:
* this.messageUtils != null
* (soft) this.messageUtils.bundle != null
*
* Postconditions:
* init'ed(return_value)
*/
97 return messageUtils.getString("searchPager.home");
98 }
99
100 protected String createURL(String url, Map params) {
/*
P/P * Method: String createURL(String, Map)
*
* Preconditions:
* this.feedRequest != null
* (soft) params != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value == &java.lang.StringBuilder:toString(...)
*
* Test Vectors:
* java.lang.String:length(...)@102: {0}, {1..232-1}
* java.lang.String:length(...)@106: {0}, {1..232-1}
* java.util.List:size(...)@110: {-231..0}, {1..232-1}
* org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest:getTags(...)@109: Addr_Set{null}, Inverse{null}
* org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest:getTerm(...)@105: Addr_Set{null}, Inverse{null}
* org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest:getWeblogCategoryName(...)@101: Addr_Set{null}, Inverse{null}
* org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest:isExcerpts(...)@113: {0}, {1}
*/
101 String category = feedRequest.getWeblogCategoryName();
102 if(category != null && category.trim().length() > 0) {
103 params.put("cat", URLUtilities.encode(category));
104 }
105 String term = feedRequest.getTerm();
106 if(term != null && term.trim().length() > 0) {
107 params.put("q", URLUtilities.encode(term.trim()));
108 }
109 List tags = feedRequest.getTags();
110 if(tags != null && tags.size() > 0) {
111 params.put("tags", URLUtilities.getEncodedTagsString(tags));
112 }
113 if(feedRequest.isExcerpts()) {
114 params.put("excerpts", "true");
115 }
116 return super.createURL(url, params);
117 }
118
119 public String getUrl() {
/*
P/P * Method: String getUrl()
*
* Preconditions:
* this.feedRequest != null
* init'ed(this.url)
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value == &java.lang.StringBuilder:toString(...)
*/
120 return createURL(url, new HashMap());
121 }
122 }
SofCheck Inspector Build Version : 2.18479
| SearchResultsFeedPager.java |
2009-Jan-02 14:25:42 |
| SearchResultsFeedPager.class |
2009-Sep-04 03:12:44 |