KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > action > SearchAction


1 /*
2  * Copyright 2004 JavaFree.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not 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.
15  */

16 package org.javabb.action;
17
18 import java.util.List JavaDoc;
19
20 import org.javabb.action.infra.BaseAction;
21 import org.javabb.component.PostFormatter;
22 import org.javabb.transaction.PostTransaction;
23 import org.javabb.vo.Post;
24
25 import com.opensymphony.xwork.Action;
26
27
28 /**
29  *
30  * @author <a HREF="mailto:jackganzha@dev.java.net">Marcos Silva Pereira</a>
31  *
32  * @since 22/04/2005
33  *
34  * @version $Id$
35  */

36 public class SearchAction extends BaseAction {
37
38     public static final String JavaDoc EMPTY = "empty";
39
40     private String JavaDoc query;
41
42     private int page;
43     private int totalRowsFound;
44     private boolean empty = false;
45
46     private List JavaDoc posts;
47     private PostTransaction postTransaction;
48
49     private PostFormatter postFormatter;
50
51     public String JavaDoc searchInPosts(){
52         posts = postTransaction.findInPosts(query, page);
53         return SUCCESS;
54     }
55
56     /**
57      * @param postFormatter the new postFormatter value
58      */

59     public void setPostFormatter(PostFormatter postFormatter) {
60         this.postFormatter = postFormatter;
61     }
62
63     /**
64      * Only to navigation
65      *
66      * @see com.opensymphony.xwork.Action#execute()
67      */

68     public String JavaDoc execute() {
69
70         return Action.SUCCESS;
71
72     }
73
74     /**
75      * actually do search
76      *
77      * @return action status
78      */

79     public String JavaDoc search() {
80         log.debug("Search: [query]:" + query);
81         
82         if(query != null){
83             if(query.indexOf(" ") > 0 && query.indexOf(" AND ") == -1){
84                 query = query.replaceAll(" ", " AND ");
85             }
86         }
87         posts = postTransaction.findByQuery(query, page);
88         if(posts.isEmpty()) {
89             empty = true;
90             log.debug("Search: [No rows found]");
91             return EMPTY;
92         }
93         totalRowsFound = postTransaction.getTotalRowsOfLucene(query);
94         log.debug("Search: [total rows]:" + totalRowsFound);
95
96         return SUCCESS;
97     }
98
99
100     /**
101      * @param post
102      * @return formated post
103      */

104     public String JavaDoc formatPostWithoutBBCode(Post post) {
105         return postFormatter.formatWithoutBBCode(post);
106     }
107     
108     
109     public boolean isEmpty() {
110         return empty;
111     }
112
113
114     public void setEmpty( boolean empty ) {
115         this.empty = empty;
116     }
117
118
119     public List JavaDoc getPosts() {
120         return posts;
121     }
122
123
124     public void setPosts( List JavaDoc posts ) {
125
126         this.posts = posts;
127     }
128
129
130     public PostTransaction getPostTransaction() {
131
132         return postTransaction;
133     }
134
135
136     public void setPostTransaction( PostTransaction postTransaction ) {
137
138         this.postTransaction = postTransaction;
139     }
140
141
142     public String JavaDoc getQuery() {
143
144         return query;
145     }
146
147
148     public void setQuery( String JavaDoc query ) {
149
150         this.query = query;
151     }
152
153
154     public int getPage() {
155
156         return page;
157     }
158
159
160     public void setPage( int page ) {
161
162         this.page = page;
163     }
164
165     public int getTotalRowsFound() {
166         return totalRowsFound;
167     }
168
169     public void setTotalRowsFound(int totalRowsFound) {
170         this.totalRowsFound = totalRowsFound;
171     }
172
173
174 }
175
Popular Tags