File Source: WeblogSearchRequest.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.rendering.util;
20
21 import javax.servlet.http.HttpServletRequest;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.roller.weblogger.WebloggerException;
25 import org.apache.roller.weblogger.business.WebloggerFactory;
26 import org.apache.roller.weblogger.business.WeblogManager;
27 import org.apache.roller.weblogger.pojos.WeblogCategory;
28 import org.apache.roller.weblogger.util.URLUtilities;
29
30
31 /**
32 * Represents a request for a weblog preview.
33 */
34 public class WeblogSearchRequest extends WeblogRequest {
35
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest__static_init
*
* Postconditions:
* init'ed(log)
*/
36 private static Log log = LogFactory.getLog(WeblogSearchRequest.class);
37
38 private static final String SEARCH_SERVLET = "/roller-ui/rendering/search";
39
40 // lightweight attributes
41 private String query = null;
42 private int pageNum = 0;
43 private String weblogCategoryName = null;
44
45 // heavyweight attributes
46 private WeblogCategory weblogCategory = null;
47
48
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest()
*
* Postconditions:
* this.authenticUser == null
* this.locale == null
* this.localeInstance == null
* this.pathInfo == null
* this.query == null
* this.request == null
* this.user == null
* this.weblog == null
* this.weblogCategory == null
* this.weblogCategoryName == null
* ...
*/
49 public WeblogSearchRequest() {}
50
51
52 public WeblogSearchRequest(HttpServletRequest request)
53 throws InvalidRequestException {
54
55 // let our parent take care of their business first
56 // parent determines weblog handle and locale if specified
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.util.WeblogSearchRequest(HttpServletRequest)
*
* Preconditions:
* org/apache/roller/weblogger/ui/rendering/util/WeblogRequest.log != null
* request != null
*
* Presumptions:
* java.lang.String:equals(...)@65 == 1
* javax.servlet.http.HttpServletRequest:getParameter(...)@84 != null
* javax.servlet.http.HttpServletRequest:getParameter(...)@98 != null
* javax.servlet.http.HttpServletRequest:getServletPath(...)@59 != null
* org.apache.roller.weblogger.util.URLUtilities:decode(...)@100 != null
*
* Postconditions:
* java.lang.String:substring(...)._tainted == 0
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* init'ed(this.authenticUser)
* init'ed(this.locale)
* this.localeInstance == null
* this.user == null
* this.weblog == null
* this.weblogCategory == null
* init'ed(this.pageNum)
* this.pathInfo == null
* ...
*
* Test Vectors:
* java.lang.String:length(...)@84: {0}, {1..232-1}
* java.lang.String:length(...)@98: {0}, {1..232-1}
* java.lang.String:startsWith(...)@104: {1}, {0}
* javax.servlet.http.HttpServletRequest:getParameter(...)@84: Addr_Set{null}, Inverse{null}
* javax.servlet.http.HttpServletRequest:getParameter(...)@89: Addr_Set{null}, Inverse{null}
* javax.servlet.http.HttpServletRequest:getParameter(...)@98: Addr_Set{null}, Inverse{null}
*/
57 super(request);
58
59 String servlet = request.getServletPath();
60
61 // we only want the path info left over from after our parents parsing
62 String pathInfo = this.getPathInfo();
63
64 // was this request bound for the search servlet?
65 if(servlet == null || !SEARCH_SERVLET.equals(servlet)) {
66 throw new InvalidRequestException("not a weblog search request, "+
67 request.getRequestURL());
68 }
69
70 if(pathInfo != null) {
+ 71 throw new InvalidRequestException("invalid path info, "+
72 request.getRequestURL());
73 }
74
75
76 /*
77 * parse request parameters
78 *
79 * the only params we currently care about are:
80 * q - specifies the search query
81 * pageNum - specifies what pageNum # to display
82 * cat - limit results to a certain weblogCategoryName
83 */
84 if(request.getParameter("q") != null &&
85 request.getParameter("q").trim().length() > 0) {
86 this.query = request.getParameter("q");
87 }
88
89 if(request.getParameter("page") != null) {
90 String pageInt = request.getParameter("page");
91 try {
92 this.pageNum = Integer.parseInt(pageInt);
93 } catch(NumberFormatException e) {
94 // ignored, bad input
95 }
96 }
97
98 if(request.getParameter("cat") != null &&
99 request.getParameter("cat").trim().length() > 0) {
100 this.weblogCategoryName =
101 URLUtilities.decode(request.getParameter("cat"));
102
103 // all categories must start with a /
104 if(!this.weblogCategoryName.startsWith("/")) {
105 this.weblogCategoryName = "/"+this.weblogCategoryName;
106 }
107 }
108 }
109
110 public String getQuery() {
/*
P/P * Method: String getQuery()
*
* Preconditions:
* init'ed(this.query)
*
* Postconditions:
* return_value == this.query
* init'ed(return_value)
*/
111 return query;
112 }
113
114 public void setQuery(String query) {
/*
P/P * Method: void setQuery(String)
*
* Postconditions:
* this.query == query
* init'ed(this.query)
*/
115 this.query = query;
116 }
117
118 public int getPageNum() {
/*
P/P * Method: int getPageNum()
*
* Preconditions:
* init'ed(this.pageNum)
*
* Postconditions:
* return_value == this.pageNum
* init'ed(return_value)
*/
119 return pageNum;
120 }
121
122 public void setPageNum(int pageNum) {
/*
P/P * Method: void setPageNum(int)
*
* Postconditions:
* this.pageNum == pageNum
* init'ed(this.pageNum)
*/
123 this.pageNum = pageNum;
124 }
125
126 public String getWeblogCategoryName() {
/*
P/P * Method: String getWeblogCategoryName()
*
* Preconditions:
* init'ed(this.weblogCategoryName)
*
* Postconditions:
* return_value == this.weblogCategoryName
* init'ed(return_value)
*/
127 return weblogCategoryName;
128 }
129
130 public void setWeblogCategoryName(String weblogCategory) {
/*
P/P * Method: void setWeblogCategoryName(String)
*
* Postconditions:
* this.weblogCategoryName == weblogCategory
* init'ed(this.weblogCategoryName)
*/
131 this.weblogCategoryName = weblogCategory;
132 }
133
134 public WeblogCategory getWeblogCategory() {
135
/*
P/P * Method: WeblogCategory getWeblogCategory()
*
* Preconditions:
* init'ed(this.weblogCategory)
* (soft) log != null
* (soft) init'ed(this.weblog)
* (soft) org/apache/roller/weblogger/ui/rendering/util/WeblogRequest.log != null
* (soft) init'ed(this.weblogCategoryName)
* (soft) init'ed(this.weblogHandle)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@138 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@138 != null
*
* Postconditions:
* init'ed(return_value)
* this.weblogCategory == return_value
* init'ed(this.weblog)
*
* Test Vectors:
* this.weblogCategory: Inverse{null}, Addr_Set{null}
* this.weblogCategoryName: Addr_Set{null}, Inverse{null}
*/
136 if(weblogCategory == null && weblogCategoryName != null) {
137 try {
138 WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
139 weblogCategory = wmgr.getWeblogCategoryByPath(getWeblog(), weblogCategoryName);
140 } catch (WebloggerException ex) {
141 log.error("Error getting weblog category "+weblogCategoryName, ex);
142 }
143 }
144
145 return weblogCategory;
146 }
147
148 public void setWeblogCategory(WeblogCategory weblogCategory) {
/*
P/P * Method: void setWeblogCategory(WeblogCategory)
*
* Postconditions:
* this.weblogCategory == weblogCategory
* init'ed(this.weblogCategory)
*/
149 this.weblogCategory = weblogCategory;
150 }
151
152 }
SofCheck Inspector Build Version : 2.18479
| WeblogSearchRequest.java |
2009-Jan-02 14:25:36 |
| WeblogSearchRequest.class |
2009-Sep-04 03:12:46 |